﻿//var calWebURL = "http://localhost/weblinks/";
var calWebURL = "http://www.otosaigon.com/adslink/";
var limit = 20;
//var topIndex = <% Response.Write(Page.Session["rdTopBanner"]);%>;
//var botIndex = <% Response.Write(Page.Session["rdBotBanner"]);%>;
//var rightIndex = <% Response.Write(Page.Session["rdRightBanner"]);%>;
var secsofTop;
var secsofBot;
var	secsofRight = Array(limit, limit-1, limit-2, limit-3, limit-4, limit-5);
var delay = 1000;
var slidePicIndex = -1;
function InitializeBannerTimer()
{
	// Set the length of the timer, in seconds
	secsofTop = limit-2;
	secsofRight = Array(limit, limit-7, limit, limit-6, limit-1, limit-5);
	misnusSecOfRight = Array(0, 8, 1, 7, 2, 6);
	secsofBot = limit-1;
	StartTopBanner();
	//if (hasRightBanner)
	//	StartRightBanner();
	StartBotBanner();
	//StartSlidePicture();
}
function StartTopBanner()
{
	topElement = document.getElementById("divTopBanner"); 
	if (secsofTop==-2)
		secsofTop = limit-2;

	secsofTop = secsofTop - 1;
	if (topImgs.length>0 && secsofTop==limit-3) {
	    document.images["topBannerAds"].src = calWebURL + "view.aspx?href="+escape(topUrls[topIndex])+"&from=Home";						
	    file = topImgs[topIndex];
	    if (file.lastIndexOf('flv')<0 && file.lastIndexOf('swf')<0) {
		    if (topUrls[topIndex]!="") 
			    topElement.innerHTML = "<a href=\"#\" onClick=\"ads('"+escape(topUrls[topIndex])+"','Home','','');\"><img width='804' height='90' src='" + topImgs[topIndex] + "' border=0><a>";
		    else
			    topElement.innerHTML = "<img width='804' height='90' src='" + topImgs[topIndex] + "' border=0>";
		} else {
		    if (topHeights[topIndex]>90) 
		    {
		        topElement.innerHTML = ""+
				        "<div style='position:absolute; vertical-align:middle;'>&nbsp; &nbsp; <a href='#' onClick='secsofTop=-2;' title='Close banner'><font color='darkred'><b>X Close</b></font></a></div>"+ 
				        "<object  style='z-index:0;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'"+
				        "width='804' height='270'>"+
				        "<param name='movie' value='"+file+"'>"+
				        "<param name='quality' value='high'>"+
				        "<param name='loop' value='false'>"+
				        "<param name='wmode' value='transparent'>"+
				        "<embed src='"+file+"' quality='high' "+
					        "width='804'  style='z-index:0;' wmode='transparent' height='"+topHeights[topIndex]+"' loop='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>"+
				        "</embed>"+
			        "</object>";
			} 
			else 
			{
			    if (topHeights[topIndex] ==0 && topSecondFiles[topIndex]!="")
			        file = topSecondFiles[topIndex];
			     if (file.lastIndexOf('flv')<0 && file.lastIndexOf('swf')<0)
			     {
		            if (topUrls[topIndex]!="") 
			            topElement.innerHTML = "<a href=\"#\" onClick=\"ads('"+escape(topUrls[topIndex])+"','Home','','');\"><img width='804' height='90' src='" + file + "' border=0><a>";
		            else
			            topElement.innerHTML = "<img width='804' height='90' src='" + file + "' border=0>";
			     } else {
		            topElement.innerHTML = ""+
				            "<object  style='z-index:0;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'"+
				            "width='804' height='90'>"+
				            "<param name='movie' value='"+file+"'>"+
				            "<param name='quality' value='high'>"+
				            "<param name='loop' value='false'>"+
				            "<param name='wmode' value='transparent'>"+
				            "<embed src='"+file+"' quality='high' "+
					            "width='804'  style='z-index:0;' scale='showall' wmode='transparent' height='90' loop='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>"+
				            "</embed>"+
			            "</object>";
			     }
			}
		    topHeights[topIndex] = 0;
	    }
		topIndex++;
		if (topIndex>=topImgs.length) topIndex = 0;
	}
	self.setTimeout("StartTopBanner()", delay);
}
function StartRight00()
{
    rightIndex[0] = Math.floor(Math.random()*rightImgs[0].length);
    
    StartRightBanner(0);
}
function StartRight01()
{
    rightIndex[1] = Math.floor(Math.random()*rightImgs[1].length);
    
    StartRightBanner(1);
}
function StartRight02()
{
    rightIndex[2] = Math.floor(Math.random()*rightImgs[2].length);
    
    StartRightBanner(2);
}
function StartRight03()
{
    rightIndex[3] = Math.floor(Math.random()*rightImgs[3].length);
    
    StartRightBanner(3);
}
function StartRight04()
{
    rightIndex[4] = Math.floor(Math.random()*rightImgs[4].length);

    StartRightBanner(4);
}
function StartRight05()
{
    rightIndex[5] = Math.floor(Math.random()*rightImgs[5].length);

    StartRightBanner(5);
}
function StartRightBanner(numRight)
{
    
	rightElement = document.getElementById("divRightBanner"+numRight); 
	if (secsofRight[numRight]==0-misnusSecOfRight[numRight])
    	secsofRight[numRight] = limit-misnusSecOfRight[numRight];
    secsofRight[numRight] = secsofRight[numRight] - 1;
	if (rightImgs[numRight].length>0 && secsofRight[numRight]==limit-misnusSecOfRight[numRight]-1) {
	    document.images["rightBannerAds"+numRight].src = calWebURL + "view.aspx?href="+escape(rightUrls[numRight][rightIndex[numRight]])+"&from=Home";	
	    file = rightImgs[numRight][rightIndex[numRight]];
	    if (file!=null && file!="") {
	        if (file.lastIndexOf('flv')<0 && file.lastIndexOf('swf')<0) {
		        if (rightUrls[numRight][rightIndex[numRight]]!="") 
			        rightElement.innerHTML = "<a href=\"#\" onClick=\"ads('"+escape(rightUrls[numRight][rightIndex[numRight]])+"','Home','','');\"><img width='250' height='200' src='" + rightImgs[numRight][rightIndex[numRight]] + "' border=0><a>";
		        else
			        rightElement.innerHTML = "<img width='250' height='200' src='" + rightImgs[numRight][rightIndex[numRight]] + "' border=0>";
		    } else {
		        rightElement.innerHTML = ""+
				        "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'"+
				        "width='250' height='200'>"+
				        "<param name='movie' value='"+file+"'>"+
				        "<param name='quality' value='high'>"+
				        "<param name='loop' value='true'>"+
				        "<embed src='"+file+"' quality='high' "+
					        "width='250' height='200' loop='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>"+
				        "</embed>"+
			        "</object>";		    
		    }
    	    rightIndex[numRight]++;
		    if (rightImgs[numRight].length>1 && rightIndex[numRight]>=rightImgs[numRight].length) rightIndex[numRight] = 0;
		}
	}
	//alert(rightImgs[numRight].length);
	//if (rightImgs[numRight].length>1)
	self.setTimeout("StartRight0"+numRight+"()", delay);
	
}
function StartBotBanner()
{
	botElement = document.getElementById("divBotBanner"); 
	if (secsofBot==-1)
		secsofBot = limit-1;

	secsofBot = secsofBot - 1;
	if (botImgs.length>0 && secsofBot==limit-2) {
	    document.images["bottBannerAds"].src = calWebURL + "view.aspx?href="+escape(botUrls[botIndex])+"&from=Home";						
	    file = botImgs[botIndex];
	    if (file.lastIndexOf('flv')<0 && file.lastIndexOf('swf')<0) {
		    if (botUrls[botIndex]!="") 
			    botElement.innerHTML = "<a href=\"#\" onClick=\"ads('"+escape(botUrls[botIndex])+"','Home','','');\"><img width='804' height='90' src='" + botImgs[botIndex] + "' border=0><a>";
		    else
			    botElement.innerHTML = "<img width='804' height='90' src='" + botImgs[botIndex] + "' border=0>";
	    } else {
		    botElement.innerHTML = ""+
				    "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0'"+
				    "width='804' height='90'>"+
				    "<param name='movie' value='"+file+"'>"+
				    "<param name='quality' value='high'>"+
				    "<param name='loop' value='true'>"+
				    "<embed src='"+file+"' quality='high' "+
					    "width='804' height='90' loop='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>"+
				    "</embed>"+
			    "</object>";		    
	    }
		botIndex++;
		if (botIndex>=botImgs.length) botIndex = 0;
	}
	self.setTimeout("StartBotBanner()", delay);
}
function StartSlidePicture()
{
    slideElement = document.getElementById("divSlidePicture"); 
    slideNoteElement = document.getElementById("divSlideNote"); 
    //alert(slideElement.style.background);
    //if (
    //alert(hotPics.length);
    if (hotPics.length>0) 
    {
        slidePicIndex++;
        if (slidePicIndex>=hotPics.length) slidePicIndex = 0;
        
        var bg = slideElement.style.background;
        var prevPos = slidePicIndex-1;
        if (prevPos<0) prevPos = hotPics.length - 1;
        bg = bg.replace("img1.jpg", hotPics[slidePicIndex]);
        bg = bg.replace(hotPics[prevPos], hotPics[slidePicIndex]);
        
        slideElement.style.background = bg;
        slideNoteElement.innerHTML = "<p><a href='newsdt.aspx?ID="+hotIDs[slidePicIndex]+"' class='link-slide'>" + hotTitles[slidePicIndex] + "</a></p>";
        if (slideNoteElement.style.opacity!=null)
        {
            //alert(slideNoteElement.style.opacity);
        }
        else if (slideNoteElement.style.filter!=null) {
        }
        
        self.setTimeout("StartSlidePicture()", 5000);
    }
}
function ads(encodelink, fromWeb, session, link) {
	var mypage	= calWebURL + "ads.aspx?href="+encodelink+"&from="+fromWeb;
	var w = screen.width;
	var h = screen.height;
	winprops = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,resizable=yes';
	
	win = window.open(mypage, "Win");//, winprops);
	
	return win;
}
