if(window.navigator.appName == "Microsoft Internet Explorer")
IsIE = true;
else IsIE = false;

var delay = 500;//5 seconds
var delayShow = 10;//1sec
var delayHiden = 20;//1sec
var rand_before = -1;
var show = false;
var counter = 0;
var currentBillBoard = 2;
var IdSetTimeOut = null;
//var beginChange = false;

function preloadImages() 
{
	var d=document; 
	if(d.images){ 
		if(!d.ImArr){
			d.ImArr=new Array();
		}
    	var i,j=d.ImArr.length,a=preloadImages.arguments; 
    	for(i=0; i<a.length; i++){    	
		    if (a[i].indexOf("#")!=0){ 
		    	d.ImArr[j]=new Image; 
		    	d.ImArr[j++].src=a[i];
		    }
		}
	}
}
function changeClass(){
		if(IdSetTimeOut != null){
			window.clearTimeout(IdSetTimeOut);
		}	
		title_obj = document.getElementById("hpb_title");
		if(title_obj){
			title_obj.className = "bill0";
		}
		photo_obj = document.getElementById("hpb_photo");
		if(photo_obj){
			photo_obj.className="bill0";
		}
}
function billBoard(id,first){
	
	if(first == 1){
		title_obj = document.getElementById("hpb_title");
		if(title_obj){
			title_obj.className="bill0";
		}
		counter = 0;
		switchBillboard(id,0);	
	}
	
	if(IdSetTimeOut != null){
		window.clearTimeout(IdSetTimeOut);
	}

	IdSetTimeOut = window.setTimeout("billBoard()",10);
	if(counter == delay+delayHiden){
		RandomLoadBillBoard();
		counter = 0;
	}
	if(counter >= 0 && counter <= delayShow){
		switchBillboard(currentBillBoard, counter * 10);
	}
	if(counter >=delay && counter < delay+delayHiden){
		switchBillboard(currentBillBoard,Math.floor(((delay+delayHiden)-counter)*5));
	}
	if(counter == delay+delayHiden){
		title_obj = document.getElementById('hpb_title');
		if(title_obj){
			title_obj.className="bill0";
		}
	}
	counter++;
	//alert(counter);

}	
	
 function RandomLoadBillBoard()
 {
	var value;
	var rand;
	var exit;

	if(currentBillBoard == 2){
		currentBillBoard = 3;
	} else if(currentBillBoard == 3){
		currentBillBoard = 1;
	} else if(currentBillBoard == 1){
		currentBillBoard = 0;
	} else if(currentBillBoard == 0){
		currentBillBoard = 2;
	}
	
	
	/*	
	while(true){
		value = Math.random()*100000;
		if(value >=0 && value<=25000){
			rand = 0;
		}else if(value >25000 && value<=50000){
			rand = 1;
		}else if(value >50000 && value<=75000){
		 	rand = 2;
		}else if(value >75000 && value<=100000){
			rand = 3;
		}		
		if(rand != rand_before){
			currentBillBoard = rand;
			break;
		}
	}
	rand_before = rand;
	//switchBillboard(rand,0);
        */
}


function setupBillboard(title, description, photo, title_w, title_h,opac)
{
    title_obj = FindItem('hpb_title');
    if(title_obj){
       	if(!IsIE) title_obj.className="bill"+Math.floor(opac/10);    	
        title_obj.src = './public/images/home/billboards/' + title;
       	if(IsIE)title_obj.style.filter = "alpha(opacity="+opac+")";  
        title_obj.width = title_w;
        title_obj.height = title_h;
    }

    desc_obj = document.getElementById('hpb_description');
    if(desc_obj){
        desc_obj.innerHTML = description;
    }

    photo_obj = document.getElementById('hpb_photo');
    if(photo_obj){
        if(photo == 'partner-photo.gif') {
		photo_obj.style.backgroundPosition = 'bottom left';
        } else if(photo == 'branding-photo-2.jpg' || photo == 'solutions-photo.jpg') {
		photo_obj.style.backgroundPosition = 'top right';
        } else {
		photo_obj.style.backgroundPosition = 'top left';
        }
        if(!IsIE) photo_obj.className="bill"+Math.floor(opac/10);    	          
        photo_obj.style.backgroundImage = 'url(./public/images/home/billboards/' + photo + ')';
        if(IsIE)photo_obj.style.filter = "alpha(opacity="+opac+")";  
    }
}  //  setupBillboard

function turnoffNavbar()
{
    obj = FindItem('hpbn1');
    if(obj){ obj.src = './public/images/home/billboards/branding-off.gif'; }
    obj = FindItem('hpbn2');
    if(obj){ obj.src = './public/images/home/billboards/eco-off.gif'; }
    obj = FindItem('hpbn3');
    if(obj){ obj.src = './public/images/home/billboards/partner-off.gif'; }
    obj = FindItem('hpbn4');
    if(obj){ obj.src = './public/images/home/billboards/solutions-off.gif'; }
}  //  turnoffNavbar

/*


*/

function switchBillboard(id,opacity)
{
	currentBillBoard = id;
    turnoffNavbar();
    switch(id){
        case 0:
	       setupBillboard('branding-title.gif',
    	                       'Properly maintained workplaces provide the right environment for successful encounters, long standing productivity and lasting impressions.',
        	                   'branding-photo-2.jpg',
            	               343, 72,opacity);   
            obj = FindItem('hpbn1');
            if(obj){ obj.src = './public/images/home/billboards/branding-on.gif'; }
            break;
        case 1:
            setupBillboard('eco-title.gif',
                           'CCS is committed to assist its customers in being recognized as "Good Corporate Citizens".',
                           'eco-photo3.gif',
                           334, 72, opacity);
            obj = FindItem('hpbn2');
            if(obj){ obj.src = './public/images/home/billboards/eco-on.gif'; }           
            break;
        case 2:
            setupBillboard('partner-title.gif',
                           'The CCS approach of "Partnering" with its customers form the optimal platform for providing unparalleled services throughout the CCS portfolio.',
                           'partner-photo.gif',
                           382, 73, opacity);
            obj = FindItem('hpbn3');
            if(obj){ obj.src = './public/images/home/billboards/partner-on.gif'; }
            break;
        case 3:
            setupBillboard('solutions-title.gif',
                           'Staffing plans designed to accommodate budgetary restraints without compromising on quality.',
                           'solutions-photo.jpg',
                           373, 76, opacity);
            obj = FindItem('hpbn4');
            if(obj){ obj.src = './public/images/home/billboards/solutions-on.gif'; }
            break;
    }
}  //  switchBillboard
