function setOpacity(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	obj.style.filter = "alpha(opacity:" + opacity + ")";
	obj.style.KHTMLOpacity = opacity / 100;
	obj.style.MozOpacity = opacity / 100;
	obj.style.opacity = opacity / 100;
}

function fadeOutLoading(opacity) {
	if (opacity == null) {
		opacity = 80;
	}
	if (opacity > 0) {
		setOpacity(xajax.$("loading"), opacity);
		opacity -= 10;
		window.setTimeout("fadeOutLoading(" + opacity + ")", 50);
	} else if (opacity == 0) {
		xajax.$("loading").style.display = "none";
		setOpacity(xajax.$("loading"), 80);
	}
}

function getUpdate(type, pr1, pr2, swf) {
	if (swf == "flashPlayer" && type == "time" && pr2 == "1") {
		switchView("Poll");
	}
	if (swf == "promoVideoPlayer" && type == "time" && pr2 == "1") {
		hidePromo();
	}
}

function showPromo() {
	// Generate flashObj
	flashObj = new SWFObject("/static/flash/mediaplayer.swf", "promoVideoPlayer", "648", "480", "8", "#000000");
	flashObj.addVariable("file", "http://videos.wolfcenterstudios.com/WCS_Promo_08_B.flv");
	flashObj.addVariable("usefullscreen", "false");
	flashObj.addVariable("overstretch", "false");
	flashObj.addVariable("autostart", "true");
	flashObj.addVariable("height", "480");
	flashObj.addVariable("width", "648");
	flashObj.addVariable("displayheight", "480");
	flashObj.addVariable('javascriptid','promoVideoPlayer');
	flashObj.addVariable('enablejs','true');
	flashObj.write("promoVideo");
	
	// Make player visible
	xajax.$("promoVideoContainer").style.display = "block";
	center(xajax.$("promoVideo"));
}

function hidePromo() {
	xajax.$('promoVideo').innerHTML = "";
	xajax.$("promoVideoContainer").style.display = "none";
	xajax.$("promoVideo").style.display = "none";
}

function center(element){
    var my_width  = 0;
    var my_height = 0;

    if (typeof(window.innerWidth) == 'number') {
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }else if ( document.body &&
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    //element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
	
    var setX = ( my_width  - 716  ) / 2;
    var setY = ( my_height - 548 ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}

function pngfix() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5 && version < 7.0) && (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;
			}
			img.style.visibility = "visible";
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}