// JavaScript Document

$(document).ready(function()
{
	$('#feature-content')
	  .anythingSlider({
	   autoPlay            	: true, 
	   width               	: 940,
	   height              	: 360,
	   buildArrows         	: false,
	   startStopped        	: false,
	   buildNavigation     	: false,
	   enablePlay          	: false,
	   delay               	: 6000,
	   animationTime       	: 1300,
	   easing				: 'easeInOutExpo'
	});
		
	$('#product-large')
	  .anythingSlider({
	   autoPlay            	: false, 
	   width               	: 750,
	   height              	: 425,
	   buildArrows         	: false,
	   startStopped        	: false,
	   buildNavigation     	: false,
	   enablePlay          	: false,
	   delay               	: 6000,
	   animationTime       	: 1300,
	   easing				: 'easeInOutExpo'
	});
	
	$(".style-roll").click(function(){
		var id 			= $(this).attr('id');
		var title 		= $(this).attr('title');
		var prodid		= $(this).parent().attr('id');
		var baseprice	= $('#baseprice').val();	
		var styleprice	= $(this).next('[name="styleprice"]').val();
		var styleinv	= $(this).parent().find('[name="styleinventory"]').val();		
		var product		= prodid.replace("style_", "");
		
		var newprice	= Number(baseprice)+Number(styleprice);
		var finalprice	= newprice.toFixed(2);
		$('#prod-price').html('$'+finalprice);
		
		
		$('.addtocart').attr('id', 'buy_'+product);
		if(styleinv > 0){
			$('.addtocart').removeClass('displaynone');
			$('.soldout').addClass('displaynone');
		}else{
			$('.addtocart').addClass('displaynone');
			$('.soldout').removeClass('displaynone');
		}
		
		$('#product-large').anythingSlider(id, function(slider){});
		$('#current-product').html(title);
		$('#curslide').val(id);
		$('.view-box').removeClass('prod-views-sel');
		$('#useview1').parent().addClass('prod-views-sel');	
		
		var view1 = $('#large_'+id).find('.view1').length;
		var view2 = $('#large_'+id).find('.view2').length;
		var view3 = $('#large_'+id).find('.view3').length;
		
		if(view1){
			$('#useview1').css('visibility', 'visible');
		}else{
			$('#useview1').css('visibility', 'hidden');
		}
		
		if(view2){
			$('#useview2').css('visibility', 'visible');
		}else{
			$('#useview2').css('visibility', 'hidden');
		}
		
		if(view3){
			$('#useview3').css('visibility', 'visible');
		}else{
			$('#useview3').css('visibility', 'hidden');
		}
		
		return false;
	});
	$("#ship-continue").css({ 'opacity' : 0.25 }); 
	
	$(".sel-shipping").click(function(){
		$("#ship-continue").removeAttr('disabled'); 
		$("#ship-continue").css({ 'opacity' : 1 }); 
	});
	  
  	$("#address-field").focus(function(){
		$(this).val('');
		return false;
	});
	$("#address-field").focusout(function(){
		if($(this).val() == ""){
			$(this).val('Enter an address or zip code:')
		}
		return false;
	});
	$("#slide1").click(function(){
		$('#feature-content').anythingSlider(1, function(slider){ });
		return false;
	});
 	$("#slide2").click(function(){
		$('#feature-content').anythingSlider(2, function(slider){ });
		return false;
	});
	$("#slide3").click(function(){
		$('#feature-content').anythingSlider(3, function(slider){ });
		return false;
	});
  	$("#slide4").click(function(){
		$('#feature-content').anythingSlider(4, function(slider){ });
		return false;
	});
  	$("#slide5").click(function(){
		$('#feature-content').anythingSlider(5, function(slider){ });
		return false;
	});
		
	$('.prod-roll').hover(
		function(){
			$(this).animate({left:'-230px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		},
		function(){
			$(this).animate({left:'0px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		}
	);
	
	$('.prod-roll-side').hover(
		function(){
			$(this).animate({top:'-130px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		},
		function(){
			$(this).animate({top:'0px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		}
	);
	
	$('.about-image').hover(
		function(){
			var oheight = $(this).find('.overlay').height();
			$(this).find('.overlay').animate({bottom:'0px'}, { "duration": "slow", "easing": "easeInOutExpo" });
			$(this).find('.overlay-color').css('height', oheight);
			$(this).find('.overlay-color').animate({bottom:'0px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		},
		function(){
			var oheight = $(this).find('.overlay').height();
			$(this).find('.overlay').animate({bottom:'-400px'}, { "duration": "slow", "easing": "easeInOutExpo" });
			$(this).find('.overlay-color').animate({bottom:'-400px'}, { "duration": "slow", "easing": "easeInOutExpo" });
		}
	);
			
	$('#opencart').click(function(){		
		var s = $('#cart').attr('class');
		if(s == "closed"){
			$('#cart-status').css('display', 'block');	
			show_cart();
		}else{
			close_cart();
		}
	});
    	
	$('#closecart').live('click', function() {
		close_cart();
	});
	
	$('#useview1').click(function(){
		var curid = $('#curslide').val();
		$('#large_'+curid).find('.view1').fadeIn('slow');
		$('#large_'+curid).find('.view2').fadeOut('slow');
		$('#large_'+curid).find('.view3').fadeOut('slow');
		$('.view-box').removeClass('prod-views-sel');
		$(this).parent().addClass('prod-views-sel');	
	});
	$('#useview2').click(function(){
		var curid = $('#curslide').val();
		$('#large_'+curid).find('.view1').fadeOut('slow');
		$('#large_'+curid).find('.view2').fadeIn('slow');
		$('#large_'+curid).find('.view3').fadeOut('slow');
		$('.view-box').removeClass('prod-views-sel');
		$(this).parent().addClass('prod-views-sel');
	});
	$('#useview3').click(function(){
		var curid = $('#curslide').val();
		$('#large_'+curid).find('.view1').fadeOut('slow');
		$('#large_'+curid).find('.view2').fadeOut('slow');
		$('#large_'+curid).find('.view3').fadeIn('slow');
		$('.view-box').removeClass('prod-views-sel');
		$(this).parent().addClass('prod-views-sel');
	});
	
	$("#usebilling").click(function(){
		var s = $(this).attr('class');
		if(s == 'billing-on'){
			swap_bill('clear');
			$(this).removeClass('billing-on');
			$(this).addClass('billing-off');
		}else{
			swap_bill('set');
			$(this).addClass('billing-on');
			$(this).removeClass('billing-off');
		}
	});
	
	function swap_bill(todo) {
		if(todo == 'set'){
			for(i=1; i<10; i++){
				$("#s_"+i).val($("#b_"+i).val());
			}		
		}else{
			for(i=1; i<10; i++){
				$("#s_"+i).val('');
			}
		}
	}
	
	$("#b_9").change(function(){
		var country = $(this).val();
		if(country == "US"){
			$('.b_state').show();
			$('.bstatebox').val('');
			$('.bstatebox').hide();
		}else{
			$('.b_state').val('');
			$('.b_state').hide();
			$('.bstatebox').show();
		}
	});
	
	$("#s_9").change(function(){
		var country = $(this).val();
		if(country == "US"){
			$('.s_state').show();
			$('.sstatebox').val('');
			$('.sstatebox').hide();
		}else{
			$('.s_state').val('');
			$('.s_state').hide();
			$('.sstatebox').show();
		}
	});

	var country = $("#b_9").val();
	if(country == "US"){
		$('.b_state').show();
		$('.bstatebox').val('');
		$('.bstatebox').hide();
	}else{
		$('.b_state').val('');
		$('.b_state').hide();
		$('.bstatebox').show();
	}
	
	var country = $("#s_9").val();
	if(country == "US"){
		$('.s_state').show();
		$('.sstatebox').val('');
		$('.sstatebox').hide();
	}else{
		$('.s_state').val('');
		$('.s_state').hide();
		$('.sstatebox').show();
	}
	
});
