﻿(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
jQuery.cookie = function (key, value, options) {
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
		
$(document).ready(function() {

//Add non standard autocomplete statement to search form
$('#xSearch').attr('autocomplete','off');

    // add a "rel" attrib if Opera 7+
	    if(window.opera) {
	        if ($("a.shareBookmark").attr("rel") != ""){ // don't overwrite the rel attrib if already set
	            $("a.shareBookmark").attr("rel","sidebar");
	        }
	    }
	 
	    $("a.shareBookmark").click(function(event){
	        event.preventDefault(); // prevent the anchor tag from sending the user off to the link
	        var url = this.href;
	        var title = this.title;
	 
	        if (window.sidebar) { // Mozilla Firefox Bookmark
	            window.sidebar.addPanel(title, url,"");
	        } else if( window.external ) { // IE Favorite
	            window.external.AddFavorite( url, title);
	        } else if(window.opera) { // Opera 7+
	            return false; // do nothing - the rel="sidebar" should do the trick
	        } else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
	             alert('Unfortunately, this browser does not support the requested action,'
	             + ' please bookmark this page manually.');
	        }
	 
	    });
	    
	var toolbeltToggleCookie = 'toolbelt-toggle';
	var tbSlideCookie = 'tbSlide';
	var cookieOptions = {expires: 7, path: '/'};
	
	$('#tbSlide').addClass ($.cookie(tbSlideCookie));
	$('.toolbelt-toggle').addClass ($.cookie(toolbeltToggleCookie));
	
	
	jQuery("#breadcrumb").jBreadCrumb();

	
	var $leftScrollers = $('.left-scroller').scrollable({vertical: true,mousewheel: true,circular: true,speed: 300}).autoscroll({ autoplay: true });
	$leftScrollers.each(function() {
		var $itemsToClone = $(this).scrollable().getItems().slice(1);
		var $wrap = $(this).scrollable().getItemWrap();
		var clonedClass = $(this).scrollable().getConf().clonedClass;
		$itemsToClone.each(function() {
			$(this).clone(true).appendTo($wrap)
				.addClass(clonedClass + ' hacked-' + clonedClass);
		})
	})

  			$("a.quick-view[rel]").overlay({effect: 'apple',onBeforeLoad: function() {

  					var wrap = this.getOverlay().find(".contentWrap");

  					wrap.load(this.getTrigger().attr("href"));

  				},

  		//Replace overlay content with loader

  				onClose: function() {

  					var wrap = this.getOverlay().find(".contentWrap");

  					wrap.html('<img class="image-centre" src="templates/axisware/images/loading.gif" alt="loading"/>');

  				}

  			});
  				
	$(".standard-tooltip").tooltip({position: "center right",tipClass: "infotip" ,offset: [-2, -10],effect: "fade",opacity: 0.9});
	$(".product-block img[title]").tooltip({effect: 'fade',fadeOutSpeed: 100,predelay: 1000}).dynamic({ bottom: { direction: 'down', bounce: true } });

  	
  	$("#home-tabs-scroller img[title]").tooltip({effect: 'fade',fadeOutSpeed: 100,predelay: 1000,tipClass: "smalltip"}).dynamic({ bottom: { direction: 'down', bounce: true } });
  	 	

	$('#home-banner').hoverIntent(function() 
		{ 
	        $("#home-tabs").fadeIn("slow", "linear");
	     },
	     function() { // out
	        $("#home-tabs").fadeOut("slow", "linear");
	     }
	);
	
	$('.toolbelt-toggle').click(function() 
		{
			$('#tbSlide').animate({width: ['toggle', 'swing']});
			$('.toolbelt-toggle').toggleClass('toggled');
			$('#tbSlide').toggleClass('Slidetoggled');
			$.cookie(toolbeltToggleCookie, $('.toolbelt-toggle').attr ("class"), cookieOptions);
			$.cookie(tbSlideCookie, $('#tbSlide').attr ("class"), cookieOptions);
			
		}
	);

		$('#sections-tab').hoverIntent(function() 
		{ 
	        $(this).find('#sections-tab-contents').slideDown('slow','swing');
	     },
	     function() { // out
	        $(this).find('#sections-tab-contents').slideUp('slow','swing');
	     }
	);
	
	
		$('#tbSlide li').hoverIntent(function() 
		{ 
	        $(this).find('.toolbelt-pocket').slideDown('slow','swing');
	     },
	     function() { // out
	        $(this).find('.toolbelt-pocket').slideUp('slow','swing');
	     }
	);

	$('.product-block').hoverIntent(function() 
		{ 
	        $(this).find('.quick-view:first').slideDown();
	     },
	     function() { // out
	        $(this).find('.quick-view:first').slideUp();
	     }
	);



	$("#home-tabs-scroller").scrollable();	
  	$("ul.emo-tabs").tabs("div.panes > div",{effect: 'fade',rotate:true}).slideshow({autoplay:true,interval:6000,clickable:false});

	$("#specials-scroller").scrollable({mousewheel: true});	
	var $brandsScroller = $("#brands-scroller").scrollable({mousewheel: true,circular: true,speed: 300}).autoscroll({ autoplay: true });
	
	$brandsScroller.each(function() {
		var $itemsToClone = $(this).scrollable().getItems().slice(1);
		var $wrap = $(this).scrollable().getItemWrap();
		var clonedClass = $(this).scrollable().getConf().clonedClass;
		$itemsToClone.each(function() {
			$(this).clone(true).appendTo($wrap)
				.addClass(clonedClass + ' hacked-' + clonedClass);
		})
	})
	
	
	var newHeight = $("#main-content").height();
	$("#page-border").css("height", newHeight);
	$(".colapsable > h2").click(function(){	
		$(this).next().slideToggle('slow',function(){
			$(this).prev().toggleClass('current');
		});
	});

	$("#open-panel").click(function(){$("div#login-panel").slideDown("slow");});	
	$("#close-panel").click(function(){$("div#login-panel").slideUp("slow");});		
	$("#toggle a").click(function () {$("#toggle a").toggle();});	
	
	$('.product-image img[rel]').overlay();
	
});
	


