$(document).ready(function() {
	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...
	});
	
	
	// THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
    var autoscrolling = true;
    
    $('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    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.
		});
	});
	
	Cufon.replace('h1');
	//Cufon.replace('.header p');
	
	// Cufon.replace('.header a', {hover: true});
	Cufon.replace('.navigation a', {hover: true});	
	//Cufon.replace('.sub_navigation a', {hover: true});
	Cufon.replace('h2');
	Cufon.replace('h3');
	
	Cufon.replace('.related_products a');
	
	Cufon.replace('.login_box button');
	// Cufon.replace('.header .nav a');
	
	
	
	if ($.isFunction($().galleryView)) {
		// only run once per page!
		if (
			$('#sidebanner').galleryView({
				panel_width: 180,
				
				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
		) {
			$('#photos').galleryView({
				panel_width: 390,  
			
				transition_speed: 1500,
				transition_interval: 5000,
				nav_theme: 'dark',
				border: '0 none',
				pause_on_hover: true,
				overlay_position: 'bottom',
				overlay_height: '0',
				overlay_font_size: '0.7em',
				overlay_text_color:'#ffffff',
				overlay_color:'#005293',
				overlay_text_decoration:'none',
				background_color:''
			});
		}
	}
	
	$('#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);
}


