function nextPhoto(){
	$('#sliderPhoto li:first').hide('slow',function(){
											$(this).show().appendTo($('#sliderPhoto'));
											onloadAllPhoto();
											clrPhotoTitle();
											});
}
loadPhotoCounter = 0;
function onloadPhoto(){
	if(++loadPhotoCounter == 5){
		onloadAllPhoto();
	}
}
var nextPhotoTimer;
function onloadAllPhoto(){
	//alert('set t')
	nextPhotoTimer = setTimeout("nextPhoto()",3000);
}

function resetNextPhotoTimer(){
	//alert('clr t')
	clearTimeout(nextPhotoTimer);
}

function setPhotoTitle(text){
	$('.photoTitle').html(" - " + text);
}
function clrPhotoTitle(){
	$('.photoTitle').html(" - " + getFristPhotoTitle());
}
function getFristPhotoTitle(){
	return $('#sliderPhoto li:first img').attr('alt');
}


$(document).ready(function(){
	
	
	$('#forumPhotoFrame').bind('mouseover',function(){
														resetNextPhotoTimer();
														mouseOnPhoto = true;
													});
	$('#forumPhotoFrame').bind('mouseleave',function(){
														onloadAllPhoto();
														mouseOnPhoto = false;
													});



	$('#forumPhotoFrame').load('../lab/forumPhotoAjax.php?'+Math.floor(Math.random()*1024), function() {
																	 
		var totalWidth = 0;

		$('#forumPhotoFrame img').hide();

		$('#forumPhotoFrame li').bind('mouseover',function(){
														  
														   var text = $(this).find('img').attr('alt');
														   //alert(text);
															setPhotoTitle(text);
														});
		$('#forumPhotoFrame li').bind('mouseleave',function(){
															 clrPhotoTitle();
														});


		$('#forumPhotoFrame img').each(function(){
		
			$("#"+this.id).parents("span[id*='thread_']")
				.wrap('<div class="frameCenter"></div>')
				.parent()
				.after('<div class="frameRight"></div>')
				.before('<div class="frameLeft"></div>');
				
			totalWidth += ($("#"+this.id).width() + 15);

			var aid = $("#"+this.id).attr('load_aid');
			if(aid){
				$("#"+this.id).attr('src','../lab/forumPhoto.php?img='+$("#"+this.id).attr('load_aid')).load(function(){
					$("#"+this.id).fadeIn().parents("span[id*='thread_']").removeClass('loadingImg');
					onloadPhoto();
				});
			}else{
				onloadPhoto();
				$("#"+this.id).fadeIn();
			}
		})
		/*
		$('#sliderPhoto').jcarousel({
        // Configuration goes here
   		});
*/

		
		$('#forumPhotoFrame .forumPhotoFrameDiv').css({'width':totalWidth+'px','position': 'relative'});
		
		clrPhotoTitle();
		
		/*
		function goLeft(){
		$('#forumPhotoFrame div').animate({
			left: '-=' + (totalWidth-436)
			}, 20000, function() {
				goRight();
		  });	
		}
		
		function goRight(){
		$('#forumPhotoFrame div').animate({
			left: '0'
			}, 20000, function() {
				goLeft();
		  });	
		}
		
		goLeft();
		*/
	});
}); 