/*
	ad module
	by kevin han
	2008-03-27
*/


function ads_refresh_google_ad(ad_info, iframe_id, ads_list) {
	ad_info = ad_info || window._show_google_ads_728x90;
	iframe_id = iframe_id || "google_ads_div_"+ad_info.id;
	ads_list = ads_list || ["dating", "cell_phones", "credit", "online_dating"];
	
	var bgcolor = ad_info.bgcolor || "#ffffff";
	var selected_ads_page = ads_list[parseInt(Math.random()*ads_list.length) % ads_list.length];

	document.getElementById(iframe_id).src = 
		"http://www.pagii.com/ads/"+selected_ads_page+".html?adid="+ad_info.id+"&bgcolor="+encodeURIComponent(bgcolor);
}

function ads_init() {
/*
	if (window._show_front_doritos) {
		document.write("<iframe id='google_ads_div_pagii_homepage_410x80' frameborder='0' scrolling='no' allowTransparency='true' src='/Home/app/admodule/front_doritos.html'></iframe>");
		document.getElementById("doritos_slot").appendChild(document.getElementById("google_ads_div_pagii_homepage_410x80"))
	}

	if (window._show_topbar_doritos) {
		document.write("<iframe id='google_ads_div_pagii_top_bar_113x27' frameborder='0' scrolling='no' allowTransparency='true' src='/Home/app/admodule/topbar_doritos.html' width='115px' height='27px'></iframe>");
		document.getElementById("top_doritos_ads").appendChild(document.getElementById("google_ads_div_pagii_top_bar_113x27")); 
	}
*/
	//var ads_pages = ["cell_phones", "mobile_phone", "online_dating", "match_person", "loan", "laptop", "airlines", "coupon", "credit", "insurance"];
	//var ads_pages = ["cell_phones", "mobile_phone", "online_dating", "match_person", "loan", "cameras", "car", "travel", "stock", "airlines", "computers", "insurance"];
	var ads_pages = ["cell_phones", "online_dating", "match_person", "airlines"];

	// top banner
	if (window._show_google_ads_728x90) {
		//var ads_pages = ["dating", "cell_phones", "match_person", "online_dating"];
		//var ads_pages = ["dating", "cell_phones", "mobile_phone", "match_person", "online_dating", "loans", "digital_cameras", "airlines", "computers", "personals", "stock_brokerage", "car_insurance", "ringtones", "books"];

		// register pages
		if (window._show_google_ads_728x90.id == "pagii_register" || window._show_google_ads_728x90.id == "pagii_invite") {
			ads_pages = ["cell_phones", "online_dating", "loan", "match_person"];
		}


		var ad_info = window._show_google_ads_728x90;
		var dealy_load = (navigator.userAgent.indexOf("MSIE") != -1)?"style='display:none;' onload='this.style.display=\"block\"'":"";

		document.write("<iframe id='google_ads_div_"+ad_info.id+"' frameborder='0' scrolling='no' "+
			"width='"+ad_info.width+"' height='"+ad_info.height+"' "+dealy_load+" ></iframe>");
		
		
		ads_refresh_google_ad(ad_info, "google_ads_div_"+ad_info.id, ads_pages);

		if (ad_info.callback) {
			ad_info.callback();
		}
	}

	// square middle 
	if (window._show_google_ads_rect) {
		//var ads_pages = ["dating", "cell_phones", "auction", "online_dating"];
		
		if (window._show_google_ads_rect.id == "pagii_profile_336x280") {
			ads_pages = ["dating_336x280", "match_person_336x280", "online_dating_336x280", "personals_336x280"];
		}
/*		
		else if (window._show_google_ads_rect.id == "pagii_browse_rect"
			|| window._show_google_ads_rect.id == "pagii_forum_rect") {
			ads_pages = ["tatto_300x250"];
		}
*/
		var ad_info = window._show_google_ads_rect;
		var dealy_load = (navigator.userAgent.indexOf("MSIE") != -1)?"style='display:none;' onload='this.style.display=\"block\"'":"";

		document.write("<iframe id='google_ads_rect' frameborder='0' scrolling='no' "+
			"width='"+ad_info.width+"' height='"+ad_info.height+"' "+dealy_load+" ></iframe>");
		
		ads_refresh_google_ad(ad_info, "google_ads_rect", ads_pages);

		if (ad_info.callback) {
			ad_info.callback();
		}
	}

	// photolog middle
	if (window._show_google_ads_side) {
		//ads_pages = ["online_dating", "cell_phones", "computers", "credit", "loan"];

		var ad_info = window._show_google_ads_rect;
		var dealy_load = (navigator.userAgent.indexOf("MSIE") != -1)?"style='display:none;' onload='this.style.display=\"block\"'":"";

		document.write("<iframe id='google_ads_side' frameborder='0' scrolling='no' "+
			"width='"+ad_info.width+"' height='"+ad_info.height+"' "+dealy_load+" ></iframe>");
		
		ads_refresh_google_ad(ad_info, "google_ads_side", ads_pages);

		if (ad_info.callback) {
			ad_info.callback();
		}
	}


	// bottom banner
	if (window._show_google_ads_bottom) {
		//ads_pages = ["online_dating", "cell_phones", "computers", "credit", "loan"];
		//ads_pages = [, "money", "auction", "game", "auction"];

		var ad_info = window._show_google_ads_bottom;
		var dealy_load = (navigator.userAgent.indexOf("MSIE") != -1)?"style='display:none;' onload='this.style.display=\"block\"'":"";

		document.write("<iframe id='google_ads_bottom' frameborder='0' scrolling='no' "+
			"width='"+ad_info.width+"' height='"+ad_info.height+"' "+dealy_load+" ></iframe>");
		
		ads_refresh_google_ad(ad_info, "google_ads_bottom", ads_pages);

		if (ad_info.callback) {
			ad_info.callback();
		}
	}

}

var __ads_box_id = (new Date).getTime();

function ads_make_box(ad_parent, ad_info, box_id) {
	if (!box_id) {
		box_id = "__ads_box_" + __ads_box_id;
		__ads_box_id++;
	}
	

	var ads_pages = ["cell_phones", "mobile_phone", "online_dating", "match_person", "airlines"];

/*
	if (ad_info.id == "pagii_browse_rect"
		|| ad_info.id == "pagii_forum_rect") {
		ads_pages = ["tatto_300x250"];
	}
*/

	var dealy_load = (navigator.userAgent.indexOf("MSIE") != -1)?"style='display:none;' onload='this.style.display=\"block\"'":"";

	var iframe = document.createElement("iframe");
	iframe.id = box_id;

	iframe.frameBorder = 0;
	iframe.scrolling = "no";
	iframe.width = ad_info.width;
	iframe.height = ad_info.height;

	if (navigator.userAgent.indexOf("MSIE") != -1) {
		/*
		iframe.style.display = "none";
		iframe.onload = function() {
			debugger;
			this.style.display = "block";
		}
		*/
	}

	ad_parent.appendChild(iframe);
	ads_refresh_google_ad(ad_info, box_id, ads_pages);
		
	if (ad_info.callback) {
		ad_info.callback();
	}
	
	return iframe;
}



if (!window.nus || !nus.env.address.parameters.disable_ads) {
	ads_init();
}
