addLoadListener(correctPNG);
addLoadListener(activateOverlayControl);

var overlayActive = 0;

// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)) {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}    
}

function activateOverlayControl() {
	var overlayControl1 = document.getElementById('overlay_control1');
	
	overlayControl1.onclick = function() {
		initOverlay();
		return false;
	};

}

function initOverlay() {
	overlayActive = 1;
	var overlay = document.getElementById('overlay');
	overlay.style.display = 'block';
	overlay.style.width = '100%';
	overlay.style.height = '100%';
	setTimeout("showOverlay()", 250);
}

function showOverlay() {
	var animOverlay = new YAHOO.util.Anim('berkobox', { height: {to: 347}}, .350, YAHOO.util.Easing.easeIn);
	animOverlay.onComplete.subscribe(activateCloseControl);
	animOverlay.animate();
}

function activateCloseControl() {
	var overlayClose = document.getElementById('overlay_close');
	overlayClose.onclick = function() {
		hideOverlay();
		return false;
	};
	
	var overlay = document.getElementById('overlay');
	overlay.onclick = function() {
		hideOverlay();
		return false;
	};
	
	if (!!window.ActiveXObject && overlayActive == 1) {
		window.onresize = function() {
			var overlay = document.getElementById('overlay');
			overlay.style.width = '100%';
			overlay.style.height = '100%';
		};
		
		window.onscroll = function() {
			var overlay = document.getElementById('overlay');
			overlay.style.top = getScrollY();
			overlay.style.height = getHeight();
		};
	}

	
}

function hideOverlay() {
	var animOverlay = new YAHOO.util.Anim('berkobox', { height: {to: 0}}, .250, YAHOO.util.Easing.easeIn);
	animOverlay.onComplete.subscribe(removeOverlay);
	animOverlay.animate();
}

function removeOverlay() {
	var overlay = document.getElementById('overlay');
	overlay.style.display = 'none';
	overlayActive = 0;
}

function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

function getHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}