// global

function initSitemap() {
	var totalNum = 27;
	var rndNum = Math.floor(Math.random() * totalNum) + 1;
	var bgImage = "url('/img/sitemap/bg" + rndNum  + ".jpg')";
	$("#sitemapMod").css("background-image",bgImage);
}

function initSitemapDark() {
	var totalNum = 27;
	var rndNum = Math.floor(Math.random() * totalNum) + 1;
	var bgImage = "url('/img/sitemap/dark/bg" + rndNum  + ".jpg')";
	$("#sitemapMod").css("background-image",bgImage);
}

function gamePop(URL, w, h) {
	var left = (screen.width - w) / 2;
	var top = (screen.height - h) / 2;
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left = "+left+",top = "+top+"');");
}

function fixPNG(myImage) { // correctly handle PNG transparency in Win IE 5.5 or higher.
	if (window.ie55up)
	 {
	 var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	 var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	 var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
	 var imgStyle = "display:inline-block;" + myImage.style.cssText 
	 var strNewHTML = "<span " + imgID + imgClass + imgTitle
	 strNewHTML += " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";"
	 strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	 strNewHTML += "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" 
	 myImage.outerHTML = strNewHTML
	 }
}

// QuickReg window

function BeaconSignup(){
    document.beaconsignup.submit();
}

function initRelatedNews(relNewsHdrCount) {
	$("#relatedNewsHeader").css(
		{backgroundImage:"url(/img/related_news/" + ((Math.floor(Math.random()*relNewsHdrCount))+1) + ".jpg)"}
	);
	$("#relatedNewsContent a").each(function (i) {
		var theRow = $(this).children(".relNewsLinkTextContainer")[0];
		var rowHeight = $(theRow).height();
		var newPad = (Math.floor(12-rowHeight)/2);
		if (newPad < 12) {
			newPad = 12;
		}
		newPad = newPad + "px";
		var newPad = newPad + " 15px " + newPad + " 17px";
		$(theRow).css({"padding" : newPad});
	});
}

function layerSliverOnTop() {
	$("#sliver").css({"z-index":"999996"});
}

function layerSliverOnBottom() {
	$("#sliver").css({"z-index":"999990"});
}

function loadTopNav() {
	if (topNavSelected == undefined) {
		var topNavSelected = "default";
		var userMemberStatus = "hidden";
	}
	$("#topNavContainer").load("/topnav.html");
}

// general pop-up  window

function popGenWin(URL, winWidth, winHeight) {
    var day = new Date();
    var id = day.getTime();
    var winLeft = screen.width/2 - winWidth/2;
    var winTop = screen.height/2 - winHeight/2;

    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=" + winWidth + ",height=" + winHeight + ",left=" + winLeft + ",top=" + winTop + "');");    
    eval("page" + id + ".focus()");
}

// START CLONE WARS RANDOM AD

function cwAd(url, alt, banner, width, height, target) {
	this.url	= url;
	this.alt	= alt;
	this.banner	= banner;
	this.width	= width;
	this.height	= height;
	this.target	= target;
}
var cwAds = new Array();

cwAds.push(new cwAd("/video/view/0000/0025", "Watch Online Now!", "/img/ad/tcw/tcw1.jpg", "300", "250", "_self"));
cwAds.push(new cwAd("/video/view/0000/0025", "Watch Online Now!", "/img/ad/tcw/tcw2.jpg", "300", "250", "_self"));
cwAds.push(new cwAd("/video/view/0000/0025", "Watch Online Now!", "/img/ad/tcw/tcw3.jpg", "300", "250", "_self"));
cwAds.push(new cwAd("http://shop.starwars.com/catalog/category.xml?category_name=247;toptab=1&rid=ADTCW", "Buy Yours Today!", "/img/ad/tcw/tcw4.jpg", "300", "250", "_blank"));
cwAds.push(new cwAd("http://shop.starwars.com/catalog/category.xml?category_name=247;toptab=1&rid=ADTCW", "Buy Yours Today!", "/img/ad/tcw/tcw4.jpg", "300", "250", "_blank"));
cwAds.push(new cwAd("http://shop.starwars.com/catalog/category.xml?category_name=247;toptab=1&rid=ADTCW", "Buy Yours Today!", "/img/ad/tcw/tcw4.jpg", "300", "250", "_blank"));

function showCwAd() {
	var ad = Math.floor(Math.random()*(cwAds.length))
	document.write('<a href="'+cwAds[ad].url+'" target="'+cwAds[ad].target+'"><img src="'+cwAds[ad].banner+'" alt="'+cwAds[ad].alt+'" width="'+cwAds[ad].width+'" height="'+cwAds[ad].height+'" border="0" /></a>');
}

// END CLONE WARS RANDOM AD
