//javascript rotate banner
var banner_y = 0;
var img_h = 0;
var tot_h = 0;
var banner_id = "";

function changeBackground(ms, h, total_h, id, id2) {
	img_h = h;
	tot_h = total_h;
	banner_id = id;
	changeOpac(200, id);
	shiftOpacity(id, 2000, id2);
	change = setInterval ( "shiftOpacity(banner_id, 2000)", ms );
	
}


function banner(h, total_h, id) {
	if (banner_y < (total_h - h)) {
		banner_y = banner_y + h;
		banner_ypx = "-" + banner_y + "px";
	} else { 
		banner_y = 0;
		banner_ypx = banner_y + "px";
	}
	
	bid = getId(id);
	
	bid.style.backgroundPosition = "0px " + banner_ypx;

}



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 shiftOpacity(id, millisec, id2) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
		banner(img_h, tot_h, id);
        opacity(id, 0, 200, millisec);
    } else {
        opacity(id, 200, 0, millisec);
        if(document.getElementById(id).style.opacity == 200) {
        	banner(img_h, tot_h, id2);
    	}

    }
    
} 
