/**
 * Site global JS file
 *
 */

	/*
	 * Set locale (if not set already)
	 */
		if (!window.locale) {
			window.locale = "en";
		}


	/**
	 * on Dom ready functionality
	 */
		jQuery(function($) {

			// debug
			//console.log('JS Library loaded');
		
			// add an extra class to the <body> element for JS-only styling
			$("body").addClass("js");
			

			// Fix PNGs for IE6
			// $('img.png-24').supersleight({shim: '/lib/png/x.gif'});
			

			// open links in a new window
			// links.init('a[rel="external"]');
			
			//toggle fade in/out
			jQuery.fn.fadeToggle = function(speed, easing, callback) {
			   return this.animate({opacity: 'toggle'}, speed, easing, callback);
			};
			
			//toggle dropdown menu helper
			function toggleMenu() {
				$("#region a").toggleClass('open');
				$("#dropdown").fadeToggle('fast');
			}
			
			//change language
			$("#region a").click(function(e){
				e.preventDefault();
				toggleMenu();
			});
			
			//dropdown timeout
			var dropdownTimeout = null;
			$("#dropdown").bind("mouseleave", function(){
				dropdownTimeout = setTimeout(function() {
					toggleMenu();
				}, 1000);
			});
			$("#dropdown").bind("mouseenter", function(){
				if (dropdownTimeout) clearTimeout(dropdownTimeout);
			});
			
			//6 pillars rollo
			$('#pillars dl.link dt').hover(function() {
				$(this).next().toggle();
				return false;
			}, function() {
				$(this).next().toggle();
				return false;
			}).next().hide();
			
			$.easing.custom = function (x, t, b, c, d) { 
			    return c*((t=t/d-1)*t*t + 1) + b;
			}
			
			//Homepage carousel
			if ($.tools) $(".scrollable").scrollable({easing:'custom',size: 1,speed:700,'clickable':false}).circular().autoscroll({autoplay: true, interval: 4000, steps: 1});

			//distributor popup

	
			$('#popupclose').click(function() {
				$('#popupwrapper').fadeToggle();
			});
			
			//the home
			$('#descs li').hide();
			$('#i1d').show();
			$('#i1').addClass('selected');
			$('#whiskynav.interact li a').click(function(){
				$('#whiskynav.interact li a').removeClass('selected');
				$(this).addClass('selected');
				$('#descs li').hide();
				$('#'+$(this).attr("id")+'d').fadeIn();
			});

			$("#clear-cookie a").bind('click', function(e) {
			    e.preventDefault();
			    $.cookie('ageVerification', null, { path: '/', expires: '-1' });
			    $.cookie('language', null, { path: '/', expires: '-1' });
			    $.cookie('country', null, { path: '/', expires: '-1' });
			});
			
	        $("ul.selectlanguage li a").bind('click', function(e) {
	            e.preventDefault();
	            $.cookie('language', this.parentNode.id,{ path: '/', expires: '30', domain:"themacallan.com" });
	            //$.cookie('language', this.parentNode.id, {	path: '/', expires: '30' });
	            location.reload();
	        });

			// check cookies - initialise age verification page
			if (!$.cookie('ageVerification')) {
				ageVerification.createOverlay();
			}
		});

	/*
	 * Window load calls for all pages
	 */
		$(window).load(function() {
	
			// preload images
			// $.preloadImages(
			//		"/_includes/images/site/misc.png"
			// );
			
		});
