// Copyright (c) 2010 Accurate Hub Networks

//AD SETTINGS
var myAdsURL=new Array(4);
	myAdsURL[0]="/dedicated-servers/"; // Edit this with the 1st ads URL
	myAdsURL[1]="/company/tour-our-datacenter/"; // Edit this with the 2nd ads URL
	myAdsURL[2]="/company/why-choose-us/"; // Edit this with the 3rd ads URL
	myAdsURL[3]="/company/green/"; // Edit this with the 4th ads URL

// LEAVE THESE ALONE
var MyAdsCurrent=0;
var myAdsLoc="/images/splash/";
var myAds=new Array(4);
	myAds[0]="enterprise.jpg";
	myAds[1]="2.jpg";
	myAds[2]="why-choose-us.jpg";
	myAds[3]="4.jpg";
var myAdsButton1=new Array(4);
	myAdsButton1[0]="arrow_01.png";
	myAdsButton1[1]="out_01.png";
	myAdsButton1[2]="out_01.png";
	myAdsButton1[3]="out_01.png";
var myAdsButton2=new Array(4);
	myAdsButton2[0]="out_02.png";
	myAdsButton2[1]="arrow_02.png";
	myAdsButton2[2]="out_02.png";
	myAdsButton2[3]="out_02.png";
var myAdsButton3=new Array(4);
	myAdsButton3[0]="out_03.png";
	myAdsButton3[1]="out_03.png";
	myAdsButton3[2]="arrow_03.png";
	myAdsButton3[3]="out_03.png";
var myAdsButton4=new Array(4);
	myAdsButton4[0]="out_04.png";
	myAdsButton4[1]="out_04.png";
	myAdsButton4[2]="out_04.png";
	myAdsButton4[3]="arrow_04.png";
var myAdsImages=new Array(4);
	myAdsImages[0] = new Image(); 
	myAdsImages[1] = new Image();
	myAdsImages[2] = new Image();
	myAdsImages[3] = new Image();
	myAdsImages[4] = new Image();
	myAdsImages[5] = new Image();
	myAdsImages[6] = new Image();
	myAdsImages[7] = new Image();
	myAdsImages[8] = new Image();
	myAdsImages[9] = new Image();
	myAdsImages[10] = new Image();
	myAdsImages[11] = new Image();

// TIMER SETTINGS

var TimeForAdSwitch=7; // Set the length of the time for ad switching, in seconds
var secs=TimeForAdSwitch;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var timedelay = secs*delay;

// FADE FUNCTIONS

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function blendimage(divid, imageid, imagefile, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;

    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
} 

// TIMER FUNCTIONS

function InitializeTimer() {
    StopTheClock();
    StartTheTimer();
}

function StopTheClock() {
    if(timerRunning){ clearTimeout(timerID); }
    timerRunning = false;
}

function StartTheTimer() {
    if (secs==0) {
        StopTheClock();
		if (MyAdsCurrent==3) {
			MyAdsCurrent=0;
		} else {
			MyAdsCurrent=MyAdsCurrent+1;
		}
		//alert(MyAdsCurrent);
		select(MyAdsCurrent);
		secs=TimeForAdSwitch;		
    	StartTheTimer();
    } else {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

// AD FUNCTIONS

function preloader() {
	myAdsImages[0].src = myAdsLoc+myAds[0];
	myAdsImages[1].src = myAdsLoc+myAds[1];
	myAdsImages[2].src = myAdsLoc+myAds[2];
	myAdsImages[3].src = myAdsLoc+myAds[3];
	myAdsImages[4].src = myAdsLoc+myAdsButton1[0];
	myAdsImages[5].src = myAdsLoc+myAdsButton2[1];
	myAdsImages[6].src = myAdsLoc+myAdsButton3[2];
	myAdsImages[7].src = myAdsLoc+myAdsButton4[3];
	myAdsImages[8].src = myAdsLoc+myAdsButton1[1];
	myAdsImages[9].src = myAdsLoc+myAdsButton2[0];
	myAdsImages[10].src = myAdsLoc+myAdsButton3[0];
	myAdsImages[11].src = myAdsLoc+myAdsButton4[0];
}

function iClick(img_num) {
	StopTheClock();
	select(img_num);
}

function select(img_num) {
	blendimage('splashbody','adsImage', myAdsLoc+myAds[img_num], 1000);
	//document.getElementById('splashbody').style.background = 'url('+myAdsLoc+myAds[img_num]+')';
	//alert('url('+myAdsLoc+myAds[img_num]+')');
	document.getElementById('adsLink').href = myAdsURL[img_num];
	//alert(myAdsURL[img_num]);
	document.getElementById('s1').style.background = 'url('+myAdsLoc+myAdsButton1[img_num]+')';
	document.getElementById('s2').style.background = 'url('+myAdsLoc+myAdsButton2[img_num]+')';
	document.getElementById('s3').style.background = 'url('+myAdsLoc+myAdsButton3[img_num]+')'; 
	document.getElementById('s4').style.background = 'url('+myAdsLoc+myAdsButton4[img_num]+')'; 
	//alert('url('+myAdsButton1[img_num]+')');
}

// MAIN LOADER

function load() {
	preloader();
	select(MyAdsCurrent);
	InitializeTimer();
	
}