function ShipStateChange() {
	document.getElementById('frmStateSelect').submit();
}
	
$(document).ready(function() {
   // put all your jQuery goodness in here.
   // Do not instantiate elements until the document has finished loading
  
	
  	// Google Analytics - Event Tracking - Homepage Slider Offer Hovers
	$('.offers-tabs a').hover(function() {
		    	var sourceRel = $(this).attr("rel");
		    	//alert(sourceLink);
  				_gaq.push(['_trackEvent', 'HomepageSlider', 'Hover', sourceRel]);
				return true;
	});
	
	 // Google Analytics - Event Tracking - Homepage Slider Offer Clicks
  	 $('.offers-tabs a').click(function() {
		    	var sourceRel = $(this).attr("rel");
		    	//alert(sourceLink);
  				_gaq.push(['_trackEvent', 'HomepageSlider', 'Click', sourceRel]);
				return true;
	});


   	var cookieState = $.cookie('state');
   	var redirectOnce;
   	//alert(cookieState);
   	   	   	
   	if (cookieState == null) {
   		tb_show("Shipping State Verification","TB_inline?height=150&width=300&inlineId=hiddenModalContent");
   	}
   	
   	else if (cookieState != null) {
   		$("#ship-to").show();
   		$(".ship-to-state").html(cookieState + "&nbsp;<a class='state-change' href='#'>Change state</a>");
   		$("#state option[value='"+ cookieState +"']").attr('selected', 'selected');
   	}
   	
   	else if (cookieState == 'MA' || cookieState == 'CA' && redirectOnce == 'null' ) {
   		location.href = "/ComplianceRedirect.aspx"
   		redirectOnce = '1';
   		$("#ship-to").show();
   	}
   	
   	
   	$(".state-change").click(function () { 
    	tb_show("Shipping State Verification","TB_inline?height=150&width=300&inlineId=hiddenModalContent");
    	return false;
    });

	
	// Accordion functions
	$('.accordion-list:not(:first)').hide();
	
	$('.accordion-list:first').show();
	
	$('.accordion-header:first').addClass('active');	
	
	$('.accordion-list:first').addClass('content-active');
	
	$('.accordion-header').click(function () {
		$('.accordion-list:visible').slideUp().prev().removeClass('active');
		$('.accordion-list:visible').removeClass('content-active');
		$(this).addClass('active').next().slideDown();
		$('.accordion-list').addClass('content-active');
		
	});
	


		// Accordion - uses jQuery UI includes
		//$("#accordion").accordion({ header: "h3", autoHeight: false });
				
		// Main Navigation Drop Down Menu
		$('li.sitenavTab').hover(function() {
			$(this).find('.sitenavDropDown').show();
			//$(this).find('a.sitenavLink').css('backgroundColor', '#c1d34b');
			$(this).find('a.sitenavLink').addClass("sitenavHover");

		}, function() {
			$(this).find('.sitenavDropDown').hide();
			//$(this).find('a.sitenavLink').css('backgroundColor', '#830136');
			$(this).find('a.sitenavLink').removeClass("sitenavHover");
		});
		
		//Sign Up Form Validation
    	$(".email-signup #submit").click(function(){
        
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var email = $("#email-signup").val();
				
		if(email == '') {
			$(".email-error").replaceWith('<div class="email-error"><p>You forgot to enter an email address.</p></div>');
		} else if(!emailReg.test(email)) {
			$(".email-error").replaceWith('<div class="email-error"><p>Please enter a valid email address.</p></div>');
		} else {
		  		$(".track").html('<img src="http://directwines.bm23.com/public/actionpage/subscriber_add/?fn=Mail_ActionPage_FormResponse&pid=f5qu8kks0w54h9bjv1t95dhtdd0xc&ssid=12859&email=' +  email + '&list_data[214612]=checked" width="0" height="0" border="0" alt=""/>');
		  		$(".email-signup").html('<p>Thank you, you have been subscribed.</p>')
		}
		return false;
		});
		
	$('#GiftMessage').each(function(){
		var limit = 60;
		var oldLength = $(this).val().length;
		// update characters
		$(this).parent().find('.counter').html(limit - oldLength + ' characters left');
		// bind on key up event
		$(this).keyup(function(){
		// get new length of characters
		var newLength = $(this).val().length;
		// update
		$(this).parent().find('.counter').html(limit - newLength + ' characters left');
		
		if (newLength > limit) {
			$('.counter').html('You cannot write more then '+limit+' characters!');
			$(this).val($(this).val().substr(0,limit));
			return false;
		}
		else {
			$(this).parent().find('.counter').html( 60 - newLength + ' characters left');
		}
		});
	});

	});
	
	// Wine Shop 4 Panel Feature - uses jQuery UI includes
	$(function() {
		$("#tabs").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 7000);
		
	// Search Results - Mouseover Image - looks for small image something_s.jpg and shows
	// large image something_l.jpg in the mouse over. Settings can be found in jquery.thumbhover.js
	$("img[src*='_l.jpg']").thumbPopup({
				imgSmallFlag: "_l",
				imgLargeFlag: "_l"
		});
	});
	
	
	// Highlight Tab v.02 
 
	$(document).ready(function(){
		var path = location.pathname;    
		var pathResult = path.split("/");
        var level = pathResult.length;     
        
        //alert(path);
        //alert(pathResult);
        //alert(level);    
        
        if (level == 2) {
            $("a[href$='" + path + "']").addClass("selected");
        } 

        if (level == 3) {
            $("a[href$='" + path + "']").addClass("selected");
        }
            
        if (level == 4) {
            $("a[href$='" + path + "']").parent().parent().parent().find("a").addClass("selected");
        }

     });
     

     
     
     
        
            

	
	
		
