var logo_picArray;

var logo_currentPic;

var logo_loadedPic;

var logo_currentLeft = 0;



//Initializes banner by taking picture array, creating an inner div to id=logo_banner, and initializing css

function f_banner_initialize(pictures) {

	logo_picArray = pictures;

	logo_currentPic = 0;

	jQuery("#logo_banner").append("<div id='logo_banner_inner'></div>").css({overflow: "hidden", zIndex: "20"});

	jQuery("#logo_banner_inner").css({position: "relative", top: 0, left: 0, zIndex: "10", height: jQuery("#logo_banner").height() - 20});

	f_createPic(0);

	f_createPic(1);

	f_createPic(2);

	f_center();

	f_fadeIn(0);

	setTimeout("f_nextPic()",5000);	

}



//Creates picture div for a particular index. Needs div to create it in.

function f_createPic(index) 

{

	var temp = jQuery("#logo_banner_inner").height();

	var left;

	if (jQuery("#tPic" + index).length == 0) {

		var website = logo_picArray[index].filename.slice(0, -4);

		jQuery("#logo_banner_inner").append("<div id='tPic" + index + "'><a href='" + logo_picArray[index].link + "' alt='" + logo_picArray[index].link + "'><img src='" + logo_picArray[index].filename + "' title='" + logo_picArray[index].name + "' /></a></div>");

	}

	//Resize logos if larger than 70% height of the div

	if (logo_picArray[index].height > 0.7 * temp) {

		jQuery("#tPic" + index).css({position: "absolute", top: 0.15 * temp, left: logo_currentLeft});

		jQuery("#tPic" + index + " img").css({position: "absolute", opacity: 0.1, height: 0.7 * temp, width: logo_picArray[index].width * ((0.7 * temp) / logo_picArray[index].height)});

		logo_currentLeft += logo_picArray[index].width * ((0.7 * temp) / logo_picArray[index].height) + 30; //30 pixel spacing btwn logos

	} else {

		jQuery("#tPic" + index).css({position: "absolute", top: (temp - logo_picArray[index].height) / 2, left: logo_currentLeft});

		jQuery("#tPic" + index + " img").css({position: "absolute", opacity: 0.1, width: logo_picArray[index].width});

		logo_currentLeft += logo_picArray[index].width + 30; //30 pixel spacing btwn logos

	}

	//TODO Grayscale
	//var el = document.getElementById( "tPic" + index + " img" );
	//grayscale( el );

	logo_loadedPic = index;

}



function f_destroyPic(index)

{

	var temp = jQuery("#logo_banner_inner").height();

	jQuery("#tPic" + index).remove();

	if (index > logo_currentPic)

		logo_currentLeft -= logo_picArray[index].height * (temp / logo_picArray[index].filename);

}



function f_center() 

{

	var picPosition = jQuery("#tPic" + logo_currentPic).position();

	var picWidth =  jQuery("#tPic" + logo_currentPic + " img").width();

	var stripPositon = jQuery("#logo_banner_inner").position();

	var left = (0.5 * jQuery("#logo_banner").width()) - (picPosition.left + 0.5 * picWidth);

	jQuery("#logo_banner_inner").animate({left: left}, 1000);

}



function f_fadeIn(index) 

{

	jQuery("#tPic" + index + " img").fadeTo(1000, 0.9);
	
	//TODO grayscale off 
	//var el = document.getElementById( "tPic" + index + " img" );
	//grayscale( el );
}



function f_fadeOut(index) 

{

	jQuery("#tPic" + index + " img").fadeTo(1000, 0.1);
	
	
	//TODO grayscale 
	//var el = document.getElementById( "tPic" + index + " img" );
	//grayscale.reset( el );
	

}



function f_animate()

{

	f_center();

	f_fadeIn(logo_currentPic);

	if (logo_currentPic == 0)

		f_fadeOut(logo_picArray.length - 1);

	else	

		f_fadeOut(logo_currentPic - 1);

}



function f_nextPic() 

{

	logo_currentPic++;

	if (logo_currentPic == logo_picArray.length)

		logo_currentPic = 0;

	f_animate();

	if (logo_currentPic + 2 < logo_picArray.length)

		f_createPic(logo_currentPic + 2);

	else if (logo_currentPic + 2 == logo_picArray.length)

		f_createPic(0);

	else if (logo_currentPic + 2 > logo_picArray.length)

		f_createPic(1);

	setTimeout("f_nextPic()",5000);	

}



	
	
	
	

