var sw_picArray;

var sw_currentPic;

var sw_loadedPic;

var sw_currentLeft = 0;



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

function f_banner_initialize(pictures) {

	sw_picArray = pictures;

	sw_currentPic = 0;

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

	jQuery("#sw_banner_inner").css({position: "relative", top: 0, left: 0, zIndex: "10", height: jQuery("#sw_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("#sw_banner_inner").height();

	var left;

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

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

		jQuery("#sw_banner_inner").append("<div id='tPic" + index + "'><a href='" + sw_picArray[index].link + "' alt='" + sw_picArray[index].link + "'><img src='http://startupweekend.org/global sponsors/" + sw_picArray[index].filename + "' title='" + sw_picArray[index].name + "' /></a></div>");

	}

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

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

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

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

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

	} else {

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

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

		sw_currentLeft += sw_picArray[index].width + 30; //30 pixel spacing btwn logos

	}

	

	sw_loadedPic = index;

}



function f_destroyPic(index)

{

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

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

	if (index > sw_currentPic)

		sw_currentLeft -= sw_picArray[index].height * (temp / sw_picArray[index].filename);

}



function f_center() 

{

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

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

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

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

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

}



function f_fadeIn(index) 

{

	jQuery("#tPic" + index + " img").fadeTo(1000, 0.6);

}



function f_fadeOut(index) 

{

	jQuery("#tPic" + index + " img").fadeTo(1000, 0.1);

}



function f_animate()

{

	f_center();

	f_fadeIn(sw_currentPic);

	if (sw_currentPic == 0)

		f_fadeOut(sw_picArray.length - 1);

	else	

		f_fadeOut(sw_currentPic - 1);

}



function f_nextPic() 

{

	sw_currentPic++;

	if (sw_currentPic == sw_picArray.length)

		sw_currentPic = 0;

	f_animate();

	if (sw_currentPic + 2 < sw_picArray.length)

		f_createPic(sw_currentPic + 2);

	else if (sw_currentPic + 2 == sw_picArray.length)

		f_createPic(0);

	else if (sw_currentPic + 2 > sw_picArray.length)

		f_createPic(1);

	setTimeout("f_nextPic()",5000);	

}



	
