jQuery(document).ready(function($){
	$('.tabs li').hover(function(){
		$(this).find('span:first').show();
	},function(){
		$(this).find('span:first').hide();
		});

	searchInputFocus();
});


function slider_init(){
	startTextSlide();
	thumbSelectContent();	
	thumbSlider();		
}

var fs = {
		container: ".feat_content",
		image: ".feat_content img",
		descBg: ".feat_descbg",
		descText: ".feat_description",
		thumb: ".featthumbs",
		thumbnavPrev: ".featnav a.prev",
		thumbnavNext: ".featnav a.next"
		};

function startTextSlide(){
	$(fs.container+':first').addClass('selected');
	
	fs.txtHeight = $(fs.descText).height() * 1.1;
	
	$(fs.descBg).css({ 
					 	height: (fs.txtHeight + 10 )+"px",
						opacity: ".7"
					})
				.css("filter", "alpha(opacity=70)")
				.animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" } ,300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)

	$(fs.descText).animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" }, 300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)
	
	rot = 1;
	rot_int = 5000;
	content_count = $(fs.container).size();
	setTimeout("featAutoSlide(rot)", rot_int);					
}

function featAutoSlide(){
	if(rot < content_count){
	RotSelectContent(rot);
	setTimeout('featAutoSlide()', rot_int);	
	++rot;
	}else{
		rot = 0;	
		featAutoSlide();
	}
}	



function RotSelectContent(rot){
	$(fs.container).hide();
	$(fs.container+":eq("+ rot +")").show();	
	
	fs.txtHeight = $(fs.descText+":eq("+ rot +")").height() * 1.1;
	
	$(fs.descBg+":eq("+ rot +")")
				.css({ 
					 	height: (fs.txtHeight + 10 )+"px",
						opacity: ".7"
					})
				.css("filter", "alpha(opacity=70)")
				.css({ marginTop: "0px" })
				.animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" }, 300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)

	$(fs.descText)
				.css({ marginTop: "0px" })
				.animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" }, 300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)
	
}


function thumbSelectContent(){
	$(fs.thumb + ' a').click(function(event){
		event.preventDefault();
		thumbIndex = $(fs.thumb + ' a').index(this);
		$(fs.container).hide();
		$(fs.container+":eq("+ thumbIndex +")").show();
	
	
	fs.txtHeight = $(fs.descText+":eq("+ thumbIndex +")").height() * 1.1;
	
	$(fs.descBg+":eq("+ thumbIndex +")")
				.css({ 
					 	height: (fs.txtHeight + 10 )+"px",
						opacity: ".7"
					})
				.css("filter", "alpha(opacity=70)")
				.css({ marginTop: "0px" })
				.animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" }, 300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)

	$(fs.descText)
				.css({ marginTop: "0px" })
				.animate({ marginTop: "-"+(fs.txtHeight + 10 )+"px" }, 300)
				.animate({ marginTop: "-"+fs.txtHeight+"px" }, 100)
	});
}


function thumbSlider(){
	thumbCount = $(".featthumbs img").size();
	thumbInterval = 61;
	
	clickLimit = thumbCount - 6;
	clickCount = 0;
	
	thumbCurrentPosition = 0;	
	$(fs.thumbnavPrev).click(function(event){
		event.preventDefault();
		if(clickCount < clickLimit){
			clickCount++;
		thumbCurrentPosition -= thumbInterval;			  
		$(fs.thumb+ ' img').animate({ left: thumbCurrentPosition+'px' });
		}
	});
	
	$(fs.thumbnavNext).click(function(event){
		event.preventDefault();
		if(clickCount > 0){
			clickCount--;
		thumbCurrentPosition += thumbInterval;			  
		$(fs.thumb+ ' img').animate({ left: thumbCurrentPosition+'px' });
		}
	});
}


function searchInputFocus(){
	searchInput = '.searchbox .searchinput';
	
	$(searchInput).focus(function(){
			$(this).addClass('searchfocus');
		});
	
	$(searchInput).blur(function(){
			if( $(this).val() == '')
				$(this).removeClass('searchfocus');
		});
}