
function onLoadAdLoc(mainPage,subPage){
	// loads the initial ad, position set based on the URL
	var isSubPage = location.href.indexOf('#');
	if(isSubPage == -1){
		loadAd(mainPage); 
	} else {
		if(subPage != 'none'){
			loadAd(subPage);
		}
	}
}

// position content layer relative to coordinates of main table
function loadAd(onPage) {
	// set x + y based on which page
	if(onPage == "home"){
		var adX = 20;
		var adY = 590;
		
		positionDiv("adbox1", adX, adY);
		fillFrame("ad_frame1", onPage);
		
	} else if(onPage == "sceneHome"){
		var adX = 660;//680;
		var adY = 349;
		
		hideAd("adbox2", "ad_frame2");
		positionDiv("adbox1", adX, adY);
		fillFrame("ad_frame1", onPage);
		
	} else if(onPage == "sceneEvent"){
		var adX = 660;//680;
		var adY = 665;
		
		hideAd("adbox1", "ad_frame1");
		positionDiv("adbox2", adX, adY);
		fillFrame("ad_frame2", onPage);
	
	} else if(onPage == "featuredHome"){
		// TEMPORARILY CHECK THIS UNTIL FELIX FIXES THE BUG LOADING THE AD WHEN AN IN-PAGE FEATURE IS LAUNCHED DIRECTLY
		//var isSubPage = location.href.indexOf('#');
		//if(isSubPage == -1){
			var adX = 660;
			var adY = -664;
		
			positionDiv("adbox1", adX, adY);
			fillFrame("ad_frame1", onPage); 
		//}
		
	}
}

// initiate the div size and css
function positionDiv(whichDiv, whichX, whichY){

	var obj_layer = document.getElementById(whichDiv);
	// temporarily hide it
	obj_layer.style.display = "none";
	// set the css
	obj_layer.style.position = "absolute";
	obj_layer.style.width = 300;
	obj_layer.style.height = 250;	
	obj_layer.style.textAlign = "left";
	//obj_layer.style.backgroundColor = "#FFFFFF";
	// set the x and y
	obj_layer.style.left = whichX;
	obj_layer.style.top = whichY;
	
	obj_layer.style.display = "block";
}

// fill the frame with the ad
function fillFrame(whichFrame, whichPage){
	var obj_iframe = document.getElementById(whichFrame);
	obj_iframe.style.display = "block";
	if(whichPage == "home"){
		frames[whichFrame].location.replace("ads/300x250_ad.php?page=" + whichPage);
	} else {
		frames[whichFrame].location.replace("../ads/300x250_ad.php?page=" + whichPage);
	}
}
// unload document and hide content frame
function hideAd(whichDiv, whichFrame) {
		// empty the div
		var obj_layer = document.getElementById(whichDiv);
		obj_layer.style.display = "none";
		// empty the iframe
		var obj_iframe = document.getElementById(whichFrame);
		obj_iframe.style.display = "none";
		frames[whichFrame].location.replace("../ads/no_ad.html");

}

