//var currentAd = 1;
//var lastAdElement;

var adRotate;

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 startAdRotation(setname,delay)
{	
	if(!adRotate)
	{
		adRotate = new Object()
	}
	
	if(!delay)
	{
		delay = 0;
	}
	
	adRotate[setname + 'currentAd'] = 1;
	//alert("First Starting To Rotate Ad: " + setname + "/" + adRotate['homesmallads' + 'currentAd']);
	setTimeout("startRotateAd('" + setname + "')",9000+delay);
	
}

function startRotateAd(setname)
{
	//alert("Starting To Rotate Ad: " + setname + "/" + adRotate[setname + 'currentAd']);
	
	adRotate[setname + 'lastAdElement'] = document.getElementById(setname + adRotate[setname + 'currentAd']);
	var lastAdNumber = adRotate[setname + 'currentAd'];
	
	adRotate[setname + 'lastAdElement'].style.zIndex = 100;
	
	adRotate[setname + 'currentAd'] = adRotate[setname + 'currentAd'] + 1;
	var newAd = document.getElementById(setname + adRotate[setname + 'currentAd']);
	
	if(newAd == null)
	{
		adRotate[setname + 'currentAd'] = 1;
		newAd = document.getElementById(setname + adRotate[setname + 'currentAd']);
	}
	
	newAd.style.zIndex = 1;	
	changeOpac(100, setname + adRotate[setname + 'currentAd']);
	newAd.style.display = 'block';
	
	opacity(setname + lastAdNumber, 100, 0, 1000);
	
	setTimeout("rotateAd('" + setname + "')",9000);
}
	
function rotateAd(setname)
{
	
	adRotate[setname + 'lastAdElement'].style.display = 'none';	
	
	setTimeout("startRotateAd('" + setname + "')",9000);
	
}
