// JavaScript Document
window.onload = initBannerLink;

var ease_IO = -306;
var opacity = 0;
var actl_stps = 0;

//easeInOut initial value
var easeIOmax = easeInOut(0,6,8,29,3);

//banner rotation image holder
var adImages = new Array("images/services/banner1.png","images/services/banner2.png","images/services/banner3.png");
var thisAd = 0;
var adURL = new Array("netrepair.php?pg_name=Net Repairs","netrepair.php?pg_name=Net Repair","netrepair.php?pg_name=Net Repair");

//initializes the banner image and calls the newLocation function when the onclick event is triggered
function initBannerLink() {
	if (document.getElementById("adBanner").parentNode.tagName == "A"){
			document.getElementById("adBanner").parentNode.onclick = newLocation;
	}
				
	rotate();
	
	for (var i=0; i<document.links.length; i++) {
		document.links[i].target = "content";
		document.links[i].onclick = setiFrame;
	
}
}

//rotates the banner display
function rotate() {
	thisAd++;
	if (thisAd == adImages.length) {
			thisAd = 0;
	}
	
	blend(banner1);
	actl_stps = 0;
	ease_IO = -306;
	
	document.getElementById("adBanner").src = adImages[thisAd];
	
	setTimeout("rotate()", 4 * 1000);
	
}

//points to the new web location
function newLocation() {
		document.location.href = "../" + adURL[thisAd];
		return false;
}

//runs a recursive fucntion that mimics blending animation
function blend(obj){
	var object = obj.style;
	
	//frames incremented
	actl_stps++;
	//uses a css style to mimic bleding by using opacity object
	ease_IO += easeInOut(0,6,8,actl_stps,-1.5);
	//obj.style.left = ease_IO + easeInOut(0,6,8,actl_stps,-1.5)+"px";
	//obj.style.top = ease_IO + easeInOut(0,6,8,actl_stps,-1.5)+"px";
	
	//Calculates the opacity according to the value of the easeInOut
	//opacity = (100 / easeIOmax) * easeInOut(0,6,8,actl_stps,3);
	opacity = (100 / easeIOmax) * easeInOut(0,6,8,actl_stps,3);
	//creates opacity
	object.opacity = (opacity / 101);
	object.MozOpacity = (opacity / 101);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	//checks if the limit is reached then run the timer "setTimout"
	if(actl_stps < 30)
		window.setTimeout("blend(" +obj.id+ ")", 0);
		return true;
}
	
//Ease In Out function 
function easeInOut(minValue, maxValue, totalSteps, actualStep, powr) {
	//easeInOut generator
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps) * actualStep), powr) * delta);
	//retur stepp;
	return Math.round(stepp);
}