$(document).ready(function(){
		
		$('.searchInput').clearType();
		$('.clearArea').clearType();
		
		var numberOfSlides = $('ul.slides li').length;
		var slidewidth = 594;
		var slideContWidth = numberOfSlides*slidewidth;
		var lessThanViewPort = slideContWidth-slidewidth;
		
		$('#heroContainer .topSlider .slider ul.slides').css('width',slideContWidth);

		setInterval(function() { moveSlider(slidewidth, slideContWidth, lessThanViewPort) } ,12000);
		
		$('ul.nav li.dot a').click(function(){
		    
			//$('ul.nav li.dot a').css({'background':'#7F678E'});
			//$(this).css({'background':'#AC94BB'});
			
			var thisDotId = $(this).attr('id');
				thisDotId = thisDotId.replace('slideNav_', "");
				thisDotPos = thisDotId-1
				$("#heroContainer .topSlider .slider ul.slides").animate({
							'margin-left': 	thisDotPos*(slidewidth*-1)							  
				},1000)
				
		});
		
		$('ul.nav li.left a').click(function(){
				
				var leftVal = $('ul.slides').css('margin-left');
				leftVal = parseInt(leftVal);
				leftVal = (leftVal*-1); 
				if (!$("#heroContainer .topSlider .slider ul.slides").is(':animated')) {
					if (leftVal>0){
						$("#heroContainer .topSlider .slider ul.slides").animate({
								'margin-left': '+=594'								  
						},1000)	
					}
				}
		});
		
		$('ul.nav li.right a').click(function(){
				
				var leftVal = $('ul.slides').css('margin-left');
				leftVal = parseInt(leftVal);
				leftVal = (leftVal*-1); 
				
				if (!$("#heroContainer .topSlider .slider ul.slides").is(':animated')) {
					if (leftVal<lessThanViewPort){
						$("#heroContainer .topSlider .slider ul.slides").animate({
								'margin-left': '-=594'								  
						},1000)	
					}
				}
			
		});
		
		
});

function moveSlider(slidewidth, slideContWidth, lessThanViewPort){
			
	var leftVal = $('ul.slides').css('margin-left');
		leftVal = parseInt(leftVal);
		leftVal = (leftVal*-1); 
	
	if (leftVal<lessThanViewPort){
		$("#heroContainer .topSlider .slider ul.slides").animate({
				'margin-left': '-=594'								  
		},1000)
	}else{
		$("#heroContainer .topSlider .slider ul.slides").animate({
				'margin-left': '0'								  
		},500)
	}
	
}		
			
$.fn.equalHeight = function () {
		var height		= 0;
		var maxHeight	= 0;
	
		// Store the tallest element's height
		this.each(function () {
			height		= $(this).outerHeight();
			maxHeight	= (height > maxHeight) ? height : maxHeight;
		});
	
		// Set element's min-height to tallest element's height
		return this.each(function () {
			var t			= $(this);
			var minHeight	= maxHeight - (t.outerHeight() - t.height());
			var property	= $.browser.msie && $.browser.version < 7 ? 'height' : 'min-height';
	
			t.css(property, minHeight + 'px');
		});
		
};

$.fn.clearType = function () {
	var thisVal = $(this).val();
	
	// CLEAR/FILL TEXT BOXES 
	$(this).focus(function() {
		if($(this).val()==thisVal){
			$(this).val('');
		}
	});
	$(this).blur(function() {
		if($(this).val()==''){
			$(this).val(thisVal);
		}					  
	});
	
};
