var popOpen = false;

function closePop() {
	Effect.Fade("popCont", {
		duration: 1.0,
		from: 1.0,
		to: 0.0
	});
	setTimeout("$('pcStage').remove()", 950);
	setTimeout("$('popCont').remove()", 1000);
	popOpen = false;
}
function closePopQuick() {
	Effect.Fade("popCont", {
		duration: 0.5,
		from: 1.0,
		to: 0.0
	});
	setTimeout("$('pcStage').remove()", 450);
	setTimeout("$('popCont').remove()", 500);
	popOpen = false;
}

function advertisingPops() {
	$$("a.adPop").each(function(a) {
		a.observe("click", function(a) {
			$("wrapper").insert("<div id='popCont' style='display: none;'><div id='pcStage'></div><a href='javascript:closePop();' title='Close window'><img src='images/button_closepop_off.gif' alt='Close window' width='10' height='10' class='close' /></a></div>");
			if (popOpen != true) {
				var ad = null;
				if (this.readAttribute("href").split("/")[0] == "http:") 
					ad = this.readAttribute("href").split("/")[8].split(".");
				else 
					ad = this.readAttribute("href").split("/")[2].split(".");
				var type = ad[1];
				var num = ad[0];
				var width = null;
				var height = null;
				if (type == "mov") {
					width = 320;
					height = 280;
				} else if (type == "jpg") {
					switch (num) {
						case "01" : 
							width = 400;
							height = 489;
							break;
						case "02" : 
							width = 590;
							height = 154;
							break;
						case "03" : 
							width = 504;
							height = 345;
							break;
						case "04" : 
							width = 818;
							height = 152;
							break;
					}
				} else {
					width = 320;
					height = 80;
				}
				var left = Math.floor((900 - (width + 10)) / 2);
				var top = Math.floor((576 - (height + 25)) / 2);
				$("popCont").setStyle({
					width: width + "px",
					height: height + "px",
					left: left +"px",
					top: top + "px",
					opacity: "0"
				});
				$("pcStage").setStyle({
					width: width + "px",
					height: height + "px"
				});
				$("popCont").show();
				Effect.Fade("popCont", {
					duration: 1.0,
					from: 0.0,
					to: 1.0
				});
				if (type == "mov") {
					var flashvars = null;
					switch (num) {
						case "01" : 
							flashvars = {videoPath: "assets/flv/CGA_2min_ENG.flv"};
							break;
						case "02" : 
							flashvars = {videoPath: "assets/flv/CGA_ENG.flv"};
							break;
						case "03" : 
							flashvars = {videoPath: "assets/flv/CGA_SUS_ENG.flv"};
							break;
					}
					swfobject.embedSWF("media/flash/videoPlayer.swf", "pcStage", width, height, "9.0.0", "", flashvars, {}, {id: "pcStage"});
				} else if (type == "jpg") {
					$("pcStage").insert("<img src='media/jpg/" + num + ".jpg' alt='We See More Than Numbers print ad' width='" + width + "' height='" + height + "' />");
				} else {
					var flashvars = null;
					switch (num) {
						case "01" : 
							flashvars = {soundPath: "media/flash/assets/mp3/CGA-06-9R30_ACCELERATE_R2.mp3"};
							break;
						case "02" : 
							flashvars = {soundPath: "media/flash/assets/mp3/CGA-05-9R30_SURIVAL.mp3"};
							break;
						case "03" : 
							flashvars = {soundPath: "media/flash/assets/mp3/CGA-07-9R30_RECOGNIZE.mp3"};
							break;
					}
					swfobject.embedSWF("media/flash/soundPlayer.swf", "pcStage", width, height, "9.0.0", "", flashvars, {}, {id: "pcStage"});
				}
				popOpen = true;
			}
			a.stop();
		});
	});
}