$(document).ready(function() {
	$("a[rel='product_gallery']").colorbox();
	
	var flashvars = {};
	var params = {wmode: "transparent"};
	var attributes = {};
	attributes.id = "";
	swfobject.embedSWF(site("static/flash/logos2.swf"), "flash-logos", "950", "85", "7.0.0", "flash/expressInstall.swf", flashvars, params, attributes);

	var flashvars = {};
	var params = {wmode: "transparent"};
	var attributes = {};
	attributes.id = "";
	swfobject.embedSWF(site("static/flash/survey2.swf"), "flash-survey", "190", "345", "7.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent"};
	var attributes = {};
	attributes.id = "";
	swfobject.embedSWF(site("static/flash/home.swf"), "flash-homepage", "430", "220", "7.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
	
	var flashvars = {};
	var params = {wmode: "transparent"};
	var attributes = {};
	attributes.id = "";
	swfobject.embedSWF(site("static/flash/survey-large.swf"), "flash-survey-large", "230", "325", "7.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
	
	swfobject.registerObject("flash-product-video", "7.0.0");
	
	
	$(document).pngFix(); 
	
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	
	$("#tabs").tabs();

	
	// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = false;
    
    $('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = false;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.infiniteCarousel').trigger('next');
        }
    }, 0);
	
	
	$('#sorting').change(function(){
	    $('#sort').submit();
	});
	
	$('.filter_container .span').click(function() {
		$(this).next().toggle('slow');
		return false;
	});
	
	$(".buttons").click(function () {
	var divname= this.name;
	  $("#"+divname).show("slow").siblings().hide("slow");
	});
	
    $('#delivery').change(function() {
	    $(this).parents("form").submit();
	});
    $('#advanced_show').click(function(){
		$('.advanced_options').toggle(1000)
    });
    if ($.isFunction($().colorbox)) {
        $('a[rel="gallery"]', '#gallery').colorbox();
		
		var gallery = $('#product_image');
		
		$('a[rel="gallery"]', gallery).colorbox();
		
		$('a', '.switchers').click(function() {
		    
			$('a', gallery).hide();
			
			$('a[href='+this.pathname+']', gallery).show();
			
			return false;
		});
		
		$('a.gallery').click(function() {
			$('a:visible', gallery).click();
		});
		
		$('a.video').colorbox({ rel:'video', inline:true, href:"#embedded" });

	}
	
	
	$('.popup-newsletter').click(function() {
		$('.popup-newsletter-form').show('normal', function() {
			// Animation complete.
		});
		$('#login-form').hide('normal', function() {
			// Animation complete.
		});
	});
	
	$('#login').click(function() {
		$('#login-form').show('normal', function() {
			// Animation complete.
		});
		 $('.popup-newsletter-form').hide('normal', function() {
			// Animation complete.
		});
	});
	
	$('.toggle-customer').click(function() {
		$('.toggle-customer-form').show('slow', function() {
			// Animation complete.
		});
	});
	
	$('.toggle-trade').click(function() {
		$('.toggle-trade-form').show('slow', function() {
			// Animation complete.
		});
	});
	
	
	$('.toggle-wholesale').click(function() {
		$('.toggle-wholesale-form').show('slow', function() {
		  // Animation complete.
		});
	});
	
	
	
	if ($.isFunction($().galleryView)) {
		// only run once per page!
		if (
			$('#sidebanner').galleryView({
				panel_width: 180,
				show_filmstrip: false,
				transition_speed: 1500,
				transition_interval: 5000,
				nav_theme: 'dark',
				border: '0 none',
				pause_on_hover: true,
				overlay_position: 'bottom',
				overlay_height: '40',
				overlay_font_size: '0.7em',
				overlay_text_color:'#ffffff',
				overlay_color:'#005293',
				overlay_text_decoration:'none',
				background_color:'#ffffff'
			})
			.length == 0
		) {
			$('#homeslider').galleryView({
				panel_width: 520,  
				panel_height: 180,  
				show_filmstrip: true,
				easing: 'linear',
				transition_speed: 1500,
				transition_interval: 5000,
				nav_theme: 'light	',
				border: '0 none',
				pause_on_hover: true,
				overlay_position: 'bottom',
				overlay_height: '0',
				overlay_font_size: '0.7em',
				overlay_text_color:'#ffffff',
				overlay_color:'#ffffff',
				overlay_text_decoration:'none',
				frame_width: 17,
				frame_height: 17
			});
			
		}
	}
	
	$('#country').change(function() {
		
		if ($('#country').val() == 'GB') {
		    $('#notice').hide();
		    $('#submit').attr('disabled', '');
		} else {
		    $('#submit').attr('disabled', 'disabled');
		    $('#notice').show();
		}
		
	});
	
	if ($.isFunction($().innerfade)) {
		$('#news').innerfade({
			animationtype: 'fade',
			speed: 1000,
			timeout: 4000,
			type: 'random',
			containerheight: '1em'
		});
	}

	$('#del_check').click(function() {
	    var text;
	    $('input[name^=s]').each(function()
		{			    
		    text = $(this).attr("name").replace("saddress", "address");
		    text = text.replace("stelephone", "telephone");
		    text = text.replace("sfirstname", "firstname");
		    text = text.replace("ssurname", "surname");
		    $(this).val(($('input[name='+ text+']').val()));		   
	    });
	    
	    
	});
	
	$("#admin_override_visibility").change(function() {
		$(this).parents('form').submit();
	});

});




// Hehe.
if ( window.addEventListener ) {
    var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
    window.addEventListener("keydown", function(e){
        kkeys.push( e.keyCode );
        if ( kkeys.toString().indexOf( konami ) >= 0 ) {
            window.location = site('company-of-');
        }
    }, true);
}


function addres_same()
{
	  
	  if(document.getElementById("del_check").checked)
	  {
		  document.getElementById("sfirstname").value=document.getElementById("firstname").value;
		  document.getElementById("ssurname").value=document.getElementById("surname").value;
		  document.getElementById("stelephone").value=document.getElementById("telephone").value;
		  document.getElementById("saddress_line_1").value=document.getElementById("address_line_1").value;
		  document.getElementById("saddress_line_2").value=document.getElementById("address_line_2").value;
		  document.getElementById("saddress_town").value=document.getElementById("address_town").value;
		  document.getElementById("saddress_county").value=document.getElementById("address_county").value;
		  document.getElementById("saddress_postcode").value=document.getElementById("address_postcode").value;
		
	  }
	  else
	  {
		  document.getElementById("sfirstname").value="";
		  document.getElementById("ssurname").value="";
		  document.getElementById("stelephone").value="";
		  document.getElementById("saddress_line_1").value="";
		  document.getElementById("saddress_line_2").value="";
		  document.getElementById("saddress_town").value="";
		  document.getElementById("saddress_county").value="";
		  document.getElementById("saddress_postcode").value="";
  	}
}
function stock_check()
{
	if(document.getElementById("product_colour").value=="")
	{
		
		alert("Colour Required");
	}
	else if(document.getElementById("quantity").value=="" || document.getElementById("quantity").value=="0")
	{
		
		alert("Quantity Required");
	}
	else
	{
	 $.ajax({
		  type: "POST",
		  url: "/stockcheck/",
		  data: $("#frm1").serialize(),
		  success: function(data){
			
			avaialable_qty=data*1;
			qty =  (document.getElementById("quantity").value)*1;
			
			if(avaialable_qty<qty)
			{
				if(avaialable_qty==0)
					$("#stock_check_msg").html("Out of Stock");
				else
				$("#stock_check_msg").html(avaialable_qty+" in stock");
			}
			else
			{
				document.frm1.submit();
			}
				//$("#show_skating").html(msg)
		    
		  }
	});
	}
}

function stock_display()
{
	if(document.getElementById("product_colour").value=="")
	{
		alert("Colour Required");
	}
	else
	{
	$.ajax({
		  type: "POST",
		  url: "/stockdisplay/",
		  data: $("#frm1").serialize(),
		  success: function(data){
			
			$("#show_stock").html(data)
		    
		  }
	});
         getSizes(document.getElementById("node_id").value, document.getElementById("product_colour").value);
	}
}

function getSizes(product, colour){
       if(product != '' && colour !=''){
          $.ajax({
		  type: "POST",
		  url: "/sizeOptionsPopulate/",
		  data: {'product':product, 'colour':colour},
		  success: function(data){
                     $("#lnSizeList1").html(data);
		  }
	}); 
       }
}




