var thisPHeight=0;
var NfoIndex=0;


	var dir = 1;
	var dur = 10000;
	var previndex=0;
	
	
	
	
	$(document).ready(function(){
			
		$('#images2 #infocontainer').animate({opacity:.8},10);

		$('a, img').mouseover(function(){
			if($(this).attr('title')!=undefined){
				titleStr=$(this).attr('title');
				$(this).removeAttr('title');
			}
		}).mouseout(function(){
			if(titleStr!=""){
			$(this).attr('title',titleStr);
				titleStr="";
			}
		});
		
		$(window).bind("load",function(){
									   
			fInfoHeight=$('.nfotxt').eq(0).height();
			$('#images2 #infocontainer').css({height:fInfoHeight}).show();
			$('.nfotxt').eq(0).show();
			
			$('#images2 img').hide().eq(0).fadeIn(300);
			$('#review_container .review_content').show().css({left:'-550px'}).eq(0).css({left:0});
			
			$('#showhide').click(function(){
				thisVal=$(this).text();
				thisEheight=$(this).height();
				
				if(thisVal=="Hide text")
				{
					thisPHeight=$(this).parent().height();
					$(this).parent().animate({height:thisEheight},500);
					$('.nfotxt').hide();
					$(this).text("Show text");
				}
				else if(thisVal=="Show text")
				{
					$(this).parent().animate({height:thisPHeight},500,function(){
						$('.nfotxt').eq(NfoIndex).show();													
					});
					$(this).text("Hide text");
				}
			});
		});
		
		
		
		$('.peoplelinkbg').mouseover(function(){
			thisIndex=$('.peoplelinkbg').index(this);
			vInfo=$(this).attr('rel');
			NfoIndex=thisIndex;
			
			if(vInfo=="nonfo")
			{
				$('#images2 #infocontainer').hide();
				$('.nfotxt').hide();
				
				if($('#images2 img').eq(thisIndex).css('display')=="none")
				{
					$('#images2 img').fadeOut(200).eq(thisIndex).fadeIn(200,function(){
						//$('#images2').crossfade();														
					});
				}
			}
			else
			{
				//$('#images2').stop();
				
				if($('#images2 img').eq(thisIndex).css('display')=="none")
				{$('#images2 img').fadeOut(200).eq(thisIndex).fadeIn(200,function(){
					fInfoHeight=$('.nfotxt').eq(thisIndex).height();
					if(fInfoHeight>0)
					{
						$('#images2 #infocontainer').css({height:fInfoHeight}).show();
						$('.nfotxt').hide().eq(thisIndex).show();
					}
					else{$('#images2 #infocontainer').hide();$('.nfotxt').hide();}													
				});}	
			}	
		});
		
		
		
		
		$('.reviewlinkbg').mouseover(function(){
			thisIndex=$('.reviewlinkbg').index(this);
			
			if(thisIndex!=previndex)
			{
				$('#review_container .review_content').queue([]).eq(previndex).animate({
				left:550},300,function(){
					$(this).css({left:'-550px'});																					
				});
				
				$('#review_container .review_content').eq(thisIndex).animate({left:0},{
				duration: 300, queue: false});
				previndex=thisIndex;
			}
		});	

		
		//thumbs generation
		var thumbs=$('#thumbs');		
		$('#images img').each(function(){
			ts=$(this).attr('src');
			thumbs.append('<div><span><img src="' + ts + '" alt="" /></span></div>');
		});
		
		//subthumbs 
		
		$('#thumbs > div').hover(function(){
			imgsrc=$(this).children('span').children('img').attr('src');
			$(this).append('<div><img src="'+ imgsrc +'" alt=""/></div>').children('div').hide().fadeIn();
		},function(){
			$(this).children('div').hide().remove();
		});
		
		$('#images img').hide().eq(0).show();
		
		$('#thumbs div span').click(function(){
			ti=$('#thumbs div span').index(this);
			$('#images img').fadeOut().eq(ti).fadeIn();
			$('#images').stopTime();
		});
		
				//variables (outside doc.ready)
		var c;	var l;	var images;
		
		//images (inside doc.ready)	   
		images = $('#images img');
		if(images.length>0){
			c=0; l=images.length-1;
			images.hide().eq(c).show();
			$('#images').everyTime(5000, function(){
				if(c==l) c=0; else c++; 
				images.fadeOut().eq(c).fadeIn();
			});
		}
	});
	
(function($) {
   
   $.fn.crossfade=function(){
		var imStart=4;
		var imFin=7;
		var thisName=$(this)
		var thisChildren=thisName.children('img');
		var nexIn=0;
		var prevIn=0;
		
		$(this).animate({top:0},2500,function(){
			thisChildren.each(function(){
				thisIndex=thisChildren.index(this);
				if(thisIndex>=imStart && thisIndex<=imFin)
				{
					if($(this).css('display')=="inline")
					{
						nexIn=thisIndex+1;
						prevIn=thisIndex;
						if(thisIndex>=imFin){nexIn=4;}
					}
				}
			});
			thisChildren.eq(prevIn).fadeOut(600);
			thisChildren.eq(nexIn).fadeIn(600);
			thisName.crossfade();
		});
   }
   
})(jQuery);
