var frPathBack = (langSuffix == "_fr")?"../":"";
var galleryImages = new Array(frPathBack+"img/results.jpg",frPathBack+"img/sponsors1.jpg",frPathBack+"img/afr-route-map-2010.png",frPathBack+"img/tv-spot.jpg",frPathBack+"img/kandahar.jpg","dummy",frPathBack+"img/sponsors2.jpg");
jQuery.preLoadImages(galleryImages);
var current = -1;
var sponsor = 0;
$(document).ready(function() {
						  	 $("#preload").show();
						   });
$(window).load( function () {
						  	 $("#preload").hide();
							 var ghostItem = $("#gallery > #doc-list").clone();
							 ghostItem.css({position:"absolute",top:$("#doc-list").position().top,left:$("#doc-list").position().left,width:"350px"}).attr("id","ghost");
							 var arrow = $("#arrow");
							 ghostItem.find("ul li").css({background:"url("+frPathBack+"img/gallery_btn_OVER.png) repeat-x",border:"1px solid #a01014",borderRight:"none",width:"329px",clear:"both",float:"left"}).after(arrow.clone());
							 ghostItem.appendTo("#gallery");
							 $("#ghost ul li, #ghost img").fadeTo(0,0);
							 selectItem((current+1)%5,current);
							 var galleryTimer = setInterval("selectItem((current+1)%5,current)",3000);
							 $("#ghost ul li").hoverIntent(function () {
																	 if(galleryTimer) {
																		 clearInterval(galleryTimer);
																		 galleryTimer = false;
																	 }
																	 selectItem($(this).index()/2,current);
																	 },
															function () {
																if (!galleryTimer) {
																	galleryTimer = setInterval("selectItem((current+1)%5,current)",3000);
																}
															});
							 $(window).resize( function() {
														$("#ghost").css("left",$("#doc-list").position().left);
														});
							 });
							 
function selectItem(_in, _out) {
	if(_in == 1) {
		if (sponsor == 1) {
			_in = 6;
			sponsor = 0;
		} else {
			sponsor = 1;
		}
	}
	$("#ghost ul li:eq("+_out+"), #ghost img:eq("+_out+")").fadeTo(1000,0);
	$("#ghost ul li:eq("+_in%5+"), #ghost img:eq("+_in%5+")").fadeTo(1000,1);
	$("#gallery-content").css("background-image","url("+galleryImages[_in]+")");
	$("#gallery-content img").fadeTo(1000,0, function() {
																		  $("#gallery-content img").attr("src",galleryImages[_in]).fadeTo(0,1);
																		  });
	current = _in%5;
}