// JavaScript Document
var $j=jQuery;
//same-height
function sameHeight(c, scope){
	if (scope){
		$j(scope).each(function(){
			var set = $j(this).find(c);
			sameHeight(set);
		});
	}
	else {
		var h = 0;		
		$j(c).each(function(){
			var th = $j(this).height()
			h = (th > h)? th : h;
		});	
		$j(c).height(h);	
	}
}
$j(window).bind('load', function(){
	sameHeight('.prod-image', '.prods-cont');

});

//image centering
jQuery.fn.vCenterImg = function(){
	jQuery(this).each(function(){
		var h = jQuery(this).height();
		var ih = jQuery(this).find('img').height();
		var p = Math.floor((h - ih) / 2);
		jQuery(this).css('paddingTop', p + 'px').height(h-p);
	});
	return this;
}
jQuery(window).bind('load', function(){
	jQuery('.prod-image').vCenterImg();
});


//slide-show
$j(document).ready(function() {
	$j(".paging").show();
	$j(".paging a:first").addClass("active");	

	var imageWidth = $j(".promo-inner").width();
	var imageSum = $j(".image_reel .promo").size();
	var imageReelWidth = imageWidth * imageSum;
	
	$j(".image_reel").css({'width' : imageReelWidth});
	rotate = function(){	
		var triggerID = $jactive.attr("rel") - 1; 
		var image_reelPosition = triggerID * imageWidth;

		$j(".paging a").removeClass('active'); 
		$jactive.addClass('active'); 
	
		$j(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
	}; 
	rotateSwitch = function(){		
		play = setInterval(function(){ 
			$jactive = $j('.paging a.active').next();
			if ( $jactive.length === 0) {
				$jactive = $j('.paging a:first'); 
			}
			rotate(); 
		}, 7000);
	};
	
	rotateSwitch();
	$j(".image_reel a").hover(function() {
		clearInterval(play); 
	}, function() {
		rotateSwitch(); 
	});	

	$j(".paging a").click(function() {	
		$jactive = $j(this); 
		clearInterval(play); 
		rotate();
		rotateSwitch(); 
		return false; 
	});		
});

//cart - currency boxes
$j(document).ready(function(){
	$j(".btn-slide").click(function(){
		$j("#cart").slideToggle("slow");
		$j(this).toggleClass("cart-active"); return false;
	});
	$j(".btn-slide-2").click(function(){
		$j("#currency").slideToggle("slow");
		$j(this).toggleClass("currency-active"); return false;
	});
});


//cat menu accordian - disabled due to accordian menu being poor on shops with lots of cats...
 function initMenu() {
 	$j('#categories ul ').hide();
 	$j('#categories li a').hover(
 function() {
 $j(this).next().slideToggle('normal');
 });
 }
$j(document).ready(function() {initMenu();});

//cookie jQuery

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};





