// JavaScript Document

// Pre Load Images 
var pics = new Array();
// Background images 
for (var i = 1; i < 9; i++) {
	pics[i] = new Image();
	pics[i].src = 'images/slogan-block-bg-'+ i +'.jpg';
}
// Banner highlight image 
pics[9] = new Image();
pics[9].src = 'images/banner-bg-102-highlight.png';
pics[10] = new Image();
pics[10].src = '../css/images/nav-menu-on.jpg';
pics[11] = new Image();
pics[11].src = '../css/images/menu-off-150.jpg';
pics[12] = new Image();
pics[12].src =  '../css/images/menu-on-150.jpg';

var count = 8; 
var idAct = 1;
var selId = 0;

var fadeDelay = 50;
var fadeVal = 0;
var fadeInProgress = 0;

var sloganObjs = new Array(); // div objects which store the slogan block
var bannerObjs = new Array(); // div objects which store the banner blocks
var imgObjs = new Array(); // image objects which signal which banner is currently active

var bannerBlkTop = 0;
var bannerBlk;
var bannerBlkSize = -414;
var bannerBlkStep = -1;

var sloganObjActId;
var sloganObjNewId;


/* Loads the div objects into their appropriate arrays */
function initializeSloganObjects () {

	for (var i =1; i <= count; i++) {
		bannerObjs[i] = document.getElementById("banner-" + i);
		sloganObjs[i] = document.getElementById('slogan-block-' + i);
		imgObjs[i] = document.getElementById('button-' + i);
		bannerBlk = document.getElementById('banner-window');
	}
	//alert('Banner: '+ document.getElementById("banner-" + 1));
}

/*
 * Shifts the banner display up or down to show the "hidden" 4 banners 
 */
function shiftBannerBlkD () {

	bannerBlkTop = bannerBlkTop + bannerBlkStep;
	bannerBlk.style.top = bannerBlkTop + 'px';
	
	if(bannerBlkStep > 0) {
		if (bannerBlkTop < 0) {
			setTimeout('shiftBannerBlkD()', fadeDelay);	
		}
		else {
			bannerBlkTop = 0;
			bannerBlk.style.top = bannerBlkTop + 'px';	
		}
	}
	else {
		//alert ("inside move up BannerBlktop: " + bannerBlkTop + " Size: " + bannerBlkSize);
		if (bannerBlkTop > bannerBlkSize) {
			setTimeout('shiftBannerBlkD()', 1);	
		}
		else {
			bannerBlkTop = bannerBlkSize;
			bannerBlk.style.top = bannerBlkSize + "px";	
		}
	}
}

/*
 * Sets the active display to the previous banner
 */
function setActiveSloganPrev () {
	
	var newId;
	
	if (idAct == 1) {
		newId = count;	
	}
	else {
		newId = idAct - 1;	
	}
	displaySlogan(newId);
	return false;
}

/*
 * Sets the active display to the next banner
 */
function setActiveSloganNext () {
	
	var newId;
	
	if (idAct == count) {
		newId = 1;	
	}
	else {
		newId = idAct + 1;	
	}
	displaySlogan(newId);
	return false;
}

function setActiveSlogan (id) {
	displaySlogan(id);	
	return false;
}

// Main function for controlling the roll over effects of the  banner 
function displaySlogan(id) {

	// Load the active elements into arrays to ease references.
	if (bannerObjs.length == 0) {
		initializeSloganObjects();	
	}
	
	if (id != idAct) {
	
	// Shift Banners if needed 
	if ((idAct <= 4) && (id > 4)) {
		bannerBlkStep = -10;
		shiftBannerBlkD();	
	}
	else if ((idAct > 4) && (id <= 4)) {
		bannerBlkStep = 10;
		shiftBannerBlkD();	
	}
	
	for(var i = 1; i <= count; i++) {
			bannerObjs[i].className = "banner png_bg";
			// turn off the active button 
			imgObjs[i].src = 'images/button-select-off.png';
	}
	// Set the active elements 
	bannerObjs[id].className = "banner-active banner png_bg";
	imgObjs[id].src = 'images/button-select-on.png';
	
	if(document.all) {
		//alert('Reseting opactivty id: ' + id + ' Active: ' + idAct );
		sloganObjs[id].style.filter = "alpha(opacity=100)"; 
		sloganObjs[idAct].style.filter = "alpha(opacity=0)"; 
			
	}
	else {
		//alert('Reseting opactivty id: ' + id + ' Active: ' + idAct );
			sloganObjs[id].style.opacity = 1;
			sloganObjs[idAct].style.opacity = 0;
		
	}
	idAct = id;
	}
}

function fadeOpacity() {
    
	fadeVal = fadeVal + 0.05;
	var actFadeVal = 1 - fadeVal;
	
	//alert('Fade Value: ' + fadeVal + ' Act Value: ' + actFadeVal);
	if (actFadeVal > 0) {
		sloganObjs[idAct].style.opacity = actFadeVal;
	}
	if (selId > 0 && fadeVal < 1) {
		sloganObjs[selId].style.opacity = fadeVal;
	}
	
	if (fadeVal < 1) {
		setTimeout('fadeOpacity()', fadeDelay);	
	} 
	else {
		fadeVal = 0;	
		for (i = 1; i <= count; i++) {
			if (i != selId) {
				sloganObjs[i].style.opacity = 0;	
			}
		}
		sloganObjs[selId].style.opacity = 1;
		idAct = selId;
		selId = 0;
		fadeInProgress = 0;
	}
}

function fadeAlpha() {
    
	fadeVal = fadeVal + 5;
	var actFadeVal = 100 - fadeVal;
	
	//alert('Fade Value: ' + fadeVal + ' Act Value: ' + actFadeVal);
	if (actFadeVal > 0) {
		sloganObjs[idAct].style.filter = "alpha(opacity=" + actFadeVal + ")";
	}
	if (selId > 0 && fadeVal < 100) {
		sloganObjs[selId].style.filter = "alpha(opacity=" + fadeVal + ")"; 
	}
	
	if (fadeVal < 100) {
		setTimeout('fadeAlpha()', fadeDelay);	
	} 
	else {
		fadeVal = 0;	
		for (i = 1; i <= count; i++) {
			if (i != selId) {
				sloganObjs[i].style.filter = "alpha(opacity=0)"; 
			}
		}
		sloganObjs[selId].style.filter = "alpha(opacity=100)"; 
		idAct = selId;
		selId = 0;
		fadeInProgress = 0;
	}
}








