/*	Copyright (c) WebPurity Limited
*	Author: Andrew Larkin
* 	Description: JQquery code file for dorsetsafetyfootwear.co
*/

	/*
	 * jQuery.testimonials() Documentation
	 * 
	 * jQuery.testimonials({int attack, int sustain, int release})
	 * 
	 * - attack: fade in time (ms)
	 * - sustain: hold visible time (ms)
	 * - release: fade out time (ms)
	 * */
	
	
	$(document).ready(function(){

		checkStyling(); // check css on checkout
        handleDropdowns(); // hide and set dropdown boxes
				
		$(".st_testimonials").testimonials({
			attack: 200,
			sustain: 8000,
			release: 200
		}); 
		
		$(".st_productFocus").jcarousel({
			auto: 4,
       		wrap: 'circular',
			scroll: 1,
			initCallback: jcarouselCallback
		});		
		
	function jcarouselCallback(c)
	{
	    c.clip.hover(function() {
	        c.stopAuto();
	    }, function() {
	        c.startAuto();
	    });
        };

		
	});

/* swaps the css on checkout */
function checkStyling() {

  var newCss = "css/stainers.css";
	var url = document.referrer;
	var cssToSwitch = $("link[href='css/replaceme.css']");
	if(url.indexOf("stainers") >= 0)  {
		newCss = "css/stainers.css";
		document.title = "Stainers Shoes - Checkout";
	} else {
		newCss = "css/dorsetsafetyfootwear.css";
		document.title = "Dorset Safety Footwear - Checkout";
	}
	if(cssToSwitch) {		
		cssToSwitch.attr("href",newCss);
	}
}

/* Pop up box */
function handleDropdowns() {

     // contact dropdown
     $('#contact-link').click(function () {
        if ($('#contact-dropdown').is(":visible")) {
            $('#contact-dropdown').hide()
			$('#session').removeClass('active');
        } else {
            $('#contact-dropdown').show()
			$('#contact-link').addClass('active');
			$('#sub-dropdown').hide()
			$('#sub-link').removeClass('active');
        }
		return false;
    });
	$('#contact-dropdown').click(function(e) {
        e.stopPropagation();
    });
	
	 // subscribe dropdown
     $('#sub-link').click(function () {
        if ($('#sub-dropdown').is(":visible")) {
            $('#sub-dropdown').hide()
			$('#session').removeClass('active');
        } else {
            $('#sub-dropdown').show()
			$('#sub-link').addClass('active');
			$('#contact-dropdown').hide();
			$('#contact-link').removeClass('active');
        }
		return false;
    });
	$('#sub-dropdown').click(function(e) {
        e.stopPropagation();
    });
	
	$(document).click(function() {
        $('#contact-dropdown').hide();
        $('#contact-link').removeClass('active');
		$('#sub-dropdown').hide();
        $('#sub-link').removeClass('active');
    });
}
