var banner = new Array();
var topbanner = new Array();
var topbanner2 = new Array();
var imagelocation = '../AD/';

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}

/* For the right banner */
function getURLParam(){
	var strHref = window.location.href;
	var getURLink = new Array();
	var URL = '';
	var last1 = '';
	var last2 = '';
	var c = 0;
	
	last1 = strHref.lastIndexOf('_')-1;
	last2 = strHref.lastIndexOf('/')+1;

	if (last1 == -2){
		last1 = strHref.lastIndexOf('.')-1;
	}

	for(c = last2; c <= last1; c++){
		URL = URL + strHref.charAt(c);	
	}
	
	if (URL == 'index' || URL == ""){

		/* modified here for index page */
		
		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["../AD/SeaLagoon_0808.swf","", 160, 160]
		];
	}
	else
	if (URL == 'cover'){

		/* modified here for the cover page */
		
		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else
	if (URL == 'hottable'){

		/* modified here for the page of hottable */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else
	if (URL == 'shopping'){

		/* modified here for the page of shopping */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else
	if (URL == 'well_being_feature'){

		/* modified here for the page of well_being_feature */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else
	if (URL == 'unusual'){

		/* modified here for the page of unusual */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else
	if (URL == 'history'){

		/* modified here for the page of history */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
	else {

		/* modified here for the other pages except above */

		/* For the first top right banner (A) */
		topbanner = [
		/* modified here */
		//,["adtop01.gif","http://www.punjabhouse.com.hk"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]		
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];

		/* For the second top right banner (B) */
		topbanner2 = [
		/* modified here */
		//,["adtop03.gif","http://www.davidfashions.com.hk/"]
		//,["ad02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad01.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		];
		
		/* For the right banner (C) */
		banner = [
		["res AD.jpg","http://www.citylifehk.com/citylife/AD/res AD.jpg"]
		,["PR AD.jpg","http://www.citylifehk.com/citylife/AD/PR AD.jpg"]
		//,["adtop02.gif","http://www.citylifehk.com/citylife/pdf/Shaniel.jpg"]
		//,["ad03.gif","http://www.davidfashions.com.hk/"]
		];
	}
}
 

function right_output(){
	var outputstring = '';
	if (banner.length > 0){	
		for (x=0; x < banner.length; x++){
			if(banner[x][0].endsWith(".swf")){
				outputstring += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\""+banner[x][2]+"\" height=\""+banner[x][3]+"\">"+
						"<param name=\"movie\" value=\""+imagelocation+banner[x][0]+"\" />"+
						"<param name=\"quality\" value=\"high\" />"+
						"<embed src=\""+imagelocation+banner[x][0]+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+banner[x][2]+"\" height=\""+banner[x][3]+"\"></embed>"+
						"</object>";
			}
			else{
				outputstring += "<a id=\"adlink"+x+"\" name=\"adlink"+x+"\" href=\"\" target=\"_blank\"><img id=\"ad"+x+"\" name=\"ad"+x+"\" src=\"\" vspace=\"5\" border=\"0\" width=\"160\" /></a>";
			}
		}
		document.getElementById('adrotatediv').innerHTML = outputstring;
	}
}


/* For the first top right banner (A)*/
var change = 0;

/* do not modify code below */	
function changeBanner(){
	if(change == topbanner.length-1){
		change = 0;
	}
	else{
		change++;
	}
	
	//document.getElementById('adtop').src = imagelocation + topbanner[change][0];
	//document.getElementById('adlinktop').href = topbanner[change][1];	
	if(topbanner[change][0].endsWith(".swf")){
		document.getElementById('adtopdiv').innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"160\" height=\"90\">"+
						"<param name=\"movie\" value=\""+imagelocation+topbanner[change][0]+"\" />"+
						"<param name=\"quality\" value=\"high\" />"+
						"<embed src=\""+imagelocation+topbanner[change][0]+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"160\" height=\"90\"></embed>"+
				    "</object>";

	} else {
		document.getElementById('adtopdiv').innerHTML = "<a id=\"adlinktop\" name=\"adlinktop\" href=\""+topbanner[change][1]+"\" target=\"_blank\"><img id=\"adtop\" name=\"adtop\" src=\""+imagelocation + topbanner[change][0]+"\" vspace=\"5\" border=\"0\" width=\"160\" /></a>";
	}
	setTimer();
}

function setTimer(){	
	var t=setTimeout("changeBanner()",8000);
}


/* For the second top right banner (B)*/
var change2 = 0;

/* do not modify code below */	
function changeBanner2(){
	if(change2 == topbanner2.length-1){
		change2 = 0;
	}
	else{
		change2++;
	}
	
	//document.getElementById('adtop2').src = imagelocation + topbanner2[change2][0];
	//document.getElementById('adlinktop2').href = topbanner2[change2][1];
	if(topbanner2[change2][0].endsWith(".swf")){
		document.getElementById('adtopdiv').innerHTML = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"160\" height=\"90\">"+
						"<param name=\"movie\" value=\""+imagelocation+topbanner2[change2][0]+"\" />"+
						"<param name=\"quality\" value=\"high\" />"+
						"<embed src=\""+imagelocation+topbanner2[change2][0]+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"160\" height=\"90\"></embed>"+
				    "</object>";

	} else {
	
	//document.getElementById('adtop2').src = imagelocation + topbanner2[change2][0];
	//document.getElementById('adlinktop2').href = topbanner2[change2][1];
		document.getElementById('adtopdiv').innerHTML = "<a id=\"adlinktop\" name=\"adlinktop\" href=\""+topbanner2[change2][1]+"\" target=\"_blank\"><img id=\"adtop\" name=\"adtop\" src=\""+imagelocation + topbanner2[change2][0]+"\" vspace=\"5\" border=\"0\" width=\"160\" /></a>";
	}

	setTimer2();
}

function setTimer2(){	
	var t=setTimeout("changeBanner2()",55000);
}

/* For the right banner (C) */
function bannerFun(){ 
	
	/* do not modify code below */	
	var number = banner.length;		
	var randomnumber = Math.floor(Math.random()*number)
	var source = ''
	
	var i = 0;
	var count = 0;
	var output = new Array();
	var outL = new Array();

	while (i < banner.length) {
		
		if (i == randomnumber) {
			output[count] = banner[i][0];
			outL[count] = banner[i][1];
			banner.splice(i, 1);
			i = 0;
			count++;
			number--;
			randomnumber = Math.floor(Math.random()*number);
		} 
		else {
			i++;
		}
	}

	var j = 0;
	var outImage, imgLoc, outLink;

	for (j = 0; j < output.length; j++){
		outImage = imagelocation + output[j];
		outLink = outL[j];
		imgLoc = "ad" + j;
		linkLoc = "adlink" + j;
		if(outImage.endsWith(".swf")){
		}
		else{
			document.getElementById(imgLoc).src = outImage;
			document.getElementById(linkLoc).href = outLink;
		}
	}
}
