// JavaScript Document

$.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');
		});
};

$(document).ready(function() { 
		
		$('input.name').clearType();
		$('input.email').clearType();
		$('input.tel').clearType();
		$('textarea.message').clearType();
		
		$('.equalHeight').equalHeight();
		$('.eq1').equalHeight();
		$('.eq2').equalHeight();
		$('.eq3').equalHeight();
		$('.eq4').equalHeight();
		$('.eq5').equalHeight();
		$('.eq6').equalHeight();
		$('.eq7').equalHeight();
		$('.eq8').equalHeight();
		
		/////////////////////////////////////////////////////////////////////
		
		var topNumberOfSlides = $('#slider ul.slides li').length;
		var topSlidewidth = 624;
		var topViewPort = 624;
		var topSliderWidth = topNumberOfSlides*topSlidewidth;
		var topLessThanViewPort = topSliderWidth-topViewPort;
		
		$('#slider ul.slides').css('width',topSliderWidth);
		
		var topFlag;
				
		
		setInterval(function() { moveTopSlider(topSlidewidth, topLessThanViewPort) } ,10000);
		
		
		$('#slider ul.nav li').mouseenter(function() {
			
				var curID = $(this).attr('id');
				
				var prevID = parseInt(curID.replace('slide_', '')) - 1;
				var onHover = topSlidewidth*prevID;

				$('#slider ul.slides').stop().animate({'margin-left':(onHover*-1)},1000);
				
				$('#slider ul.nav li').removeClass('active');
				$(this).addClass('active');
		
		});
		
		
});

function moveTopSlider(topSlidewidth, topLessThanViewPort){
			
			var topLeftVal = $('#slider ul.slides').css('margin-left');
				topLeftVal = parseInt(topLeftVal);
				topLeftVal = (topLeftVal*-1); 
				
				if (topLeftVal==0){
					topFlag = 1;
				}
				
				
			
				if (topLeftVal<topLessThanViewPort && topFlag==1){
					$('#slider .overlay .slideContent.active').hide().removeClass('active').next().addClass('active').fadeIn();
					$('#slider ul.slides').stop().animate({
							'marginLeft': '-='+topSlidewidth							  
					},1000)
				
					$('#slider ul.nav li.active').removeClass('active').next().addClass('active');
				
				}else if (topLeftVal>=0){
					$('#slider .overlay .slideContent.active').hide().removeClass('active').prev().addClass('active').fadeIn();
					$('#slider ul.slides').stop().animate({
							'marginLeft': '+='+topSlidewidth									  
					},1000)
					topFlag = 0;
					$('#slider ul.nav li.active').removeClass('active').prev().addClass('active');
				}
		
			
}

$.fn.clearType = function () {
	var thisVal = $(this).val();
	$(this).focus(function() {
		if($(this).val()==thisVal){
			$(this).val('');
		}
	});
	$(this).blur(function() {
		if($(this).val()==''){
			$(this).val(thisVal);
		}					  
	});
	
};
