$(document).ready(function(){   
   
sublinkTR = function(){	
	
	  $('.cartBox').hover(function() {
		  var loginLinkWrap = $('.loginLinkWrap').width();
		  $('.loginBox').stop().animate({opacity: '1',width: loginLinkWrap+100}, 'fast');  
		  } , function() {
		  $('.loginBox').stop().animate({opacity: '0',width: '0px'}, 'fast');
	  });
	  
	  $('.loginBox').hover(function() {
		  var loginLinkWrap = $('.loginLinkWrap').width();
		  $(this).stop().animate({opacity: '1',width: loginLinkWrap+100}, 'fast');  
		  } , function() {
		  $(this).stop().animate({opacity: '0',width: '0px'}, 'fast');
	  });

};

sublinkTR();



$('.sideCon h6').each(function(i){
	$(this).click(function(){
	
		var mmBoxHeight = $('.mmWrap:eq('+i+')').height();
		if ($('.subBox').is(':animated')) {
			  
		}
		else{			
			if ($(this).is('.sideCon h6.open')) {
				$('.open').removeClass('open');
				$('.subBox').animate({'height': '0px'}, 400);
				$.cookie('tabCookie', null);
			}
			else{			
				$('.subBox').animate({'height': '0px'}, 400);  
				$('.subBox:eq('+i+')').animate({'height': mmBoxHeight}, 300);  
				$('.open').removeClass('open');
				$(this).addClass('open');
				$.cookie('tabCookie', null);
				$.cookie('tabCookie', i, {expires: 7, path: '/', domain: 'arlenness.com'});
			}	
		}
	});
});
	
	
	if($.cookie('tabCookie') == null) {
		return; 
	}
	else {
		var c = $.cookie('tabCookie');
		var thisBoxH = $('.mmWrap:eq('+c+')').height();
		$('.sideCon h6:eq('+c+')').addClass('open');
		$('.subBox:eq('+c+')').animate({'height': thisBoxH}, 300);	
	}



	$('.searchAdBox').click(function(){		
		$('.formWrap').animate({height:'300px'}, 400);
		$('.searchAd').animate({'margin-top':'-320px'}, 400);
		$(this).animate({height:'0px'}, 400);
	});
	
	$('.btnClose').click(function(){		
		$('.formWrap').animate({height:'0px'}, 400);
		$('.searchAd').animate({'margin-top':'-120px'}, 400);
		$('.searchAdBox').animate({height:'100px'}, 400);
	});

$('.btnPop').click(function(){                      
	if ($(this).is('.btnPop.dealer')) {
		$('#ajaxPop').load('/includes/dealerLoc.php');
	}
	else if ($(this).is('.btnPop.video')) {
	var videoURL = $(this).attr('name');
		$('.overLay.video').css({display:'block'});              
		$('#videoURL').val(videoURL);  
		$('#videoEmbed').attr('src', videoURL);
	}
	else if ($(this).is('.btnPop.ask')) {
		$('.overLay.video').css({display:'block'});              
		$('#videoURL').val(videoURL);  
		$('#videoEmbed').attr('src', videoURL);
	}
	else{                                     
	return;
	}
});

$('.overClose').click(function(){		
	$('.overLay').css({display:'none'});  
});

$('.cllOutPlus').each(function(i){		
	$(this).click(function() {
		$(this).toggle(200);
		$('.callOut:eq('+i+')').animate({width: '500px'}, 400);
		$('.callOutCon:eq('+i+')').slideToggle(400);
					
	});
});	

input = function(){          
  $(':text').each(function(){
	var default_value = this.value;
	$(this).focus(function() {
		if(this.value == default_value) {
	this.value = '';
	}             
	});
	$(this).blur(function() {
		if(this.value == '') {
	this.value = default_value;
	}
	});
	});          
  };
input();

$('.productInfo br').remove();
$('#SearchGo').click(function(){
	var searchVal = $('#SearchBox').val();
	if(searchVal==''||searchVal=='Enter Part Name or Number'){alert('please enter a value for your search'); return false;}
	location.href = 'http://shop.arlenness.com/search.aspx?searchterm='+escape(searchVal);
	
	});

$('#flName').focus(function(){
	$('.moreInfo').slideDown(300);
	});


$('#submit').click(function() {
		
	$('#waiting').show(500);
	/*$('#demoForm').hide(0);*/
	$('#message').hide(0);
	
	$.ajax({
		type : 'POST',
		url : 'postEmail.php',
		dataType : 'json',
		data: {
			email : $('#email').val()
		},
		success : function(data){
			$('#waiting').hide(500);
			$('#message').removeClass().addClass((data.error === true) ? 'error' : 'success')
				.html(data.msg).show(500);
			if (data.error === true)
				return;
				/*$('#demoForm').show(500);*/
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			$('#waiting').hide(500);
			$('#message').removeClass().addClass('error')
				.html('<span>Thank you.</span>').show(500);
			/*$('#demoForm').show(500);*/
		}
	});
	
	return false;
});

$('.mainImage a img').each(function(i){
    var myNewSRC= $(this).attr('src');
    $('.thumWrap:eq('+i+')').attr('name', i).prepend('<img id="theImg" class="thumImg" name="_00" src="'+myNewSRC+'" /><img id="theImg" class="thumImg" name="_01" src="'+myNewSRC+'" /><img id="theImg" class="thumImg" name="_02" src="'+myNewSRC+'" /><img id="theImg" class="thumImg" name="_03" src="'+myNewSRC+'" />');
});
$('.thumImg').each(function(i){;
	var attrName= $(this).attr('name');   
	var src = $(this).attr('src').replace('_00', attrName);
	$(this).attr('src', src);
	$(this).error(function(){
		$(this).remove();
		/*if ($('.thumPro').is(':empty')) {$(this).remove();}*/
	});
	$(this).fadeIn(400);
	$(this).wrap('<div class="thumMask"><span></span></div>');
});

$('.thumImg').each(function(i){	
	$(this).hover(function() {
		var src = $(this).attr('src').replace('icon', 'large');
		var lrgSrc = $(this).parent().parent().parent().attr('name');
	
		$('.thumWrap:eq('+lrgSrc+')').stop().prepend('<div class="largeWrap"><img id="theImg" class="largeImg" src="'+src+'" /></div>');
		$(this).addClass('hover');
		} , function() {
		$(this).removeClass('hover');
		$('.largeWrap').remove();
	});
});

	
	

});

