﻿// JavaScript Document
$(document).ready(function () {

    //Add General functionality to .glowOver
    // wait until later to add this via jquery

    /*	$('.glow-over').css({'opacity':'.5'}).hover(function(){
    $(this).stop(true,true).animate({opacity:1});
    }, function () {
    $(this).stop(true,true).animate({opacity:.5});
    });*/

    $("ul li:first-child").addClass("first");
    $("ul li:last-child").addClass("last");

    if ( (!(window.rounded === undefined) && (rounded == true)) ) { $('body').addClass('rounded') };
    if ( (!(window.grey === undefined) && (grey == true)) ) { $('body').addClass('greybodybg') };
    if ( (!(window.productsDetailA === undefined) && (productsDetailA == true)) ) { $('body').addClass('productsDetailA') };
    if ( (!(window.productsDetailB === undefined) && (productsDetailB == true)) ) { $('body').addClass('productsDetailB') };

});


    
    (function($) {

		var img = new Image();
        $(img).attr('src', '/common/images/image-loading.gif');

	$.fn.imagePreload = function( options ) {
		

		return this.each(function() {
            var localWidth = $(this).width();
            var localHeight = $(this).height();

            $(this).wrap('<div />').css({'opacity':'0'});
            $(this).parent().css({ width: localWidth, height: localHeight,'text-align':'center','background': "transparent url('/common/images/image-loading.gif') no-repeat center center"})
            

            $(this).load(function () {    // when image has loaded...

               /* if ($(this).hasClass('pop-in-img'))
                {
                    $(this).css({'width':'0px', 'height':'0px','margin-top':localHeight/2+'px'}).parent().css({'background':'none'});
                    $(this).animate({'width':localWidth, 'height':localHeight, 'opacity':'1','margin-top':'0px'},1200,'easeOutBounce'); // pop image in
                }
                else                
                {*/
                    $(this).animate({'opacity':'1'},500); // fade image in
                //}


            });
		});
	}
})(jQuery);



/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(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 hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);


/*
 * jQuery hoverFocus UI 
 */

(function($) {
	$.fn.hoverFocus = function( options ) {
		
		var settings = {
		  //'autoSelect'         : false
		};		
		
		return this.each(function() {

			if ( options ) { 
				$.extend( settings, options );
			}
			
			var theList = $(this)
			var theItems = $('li',$(this));
            theItems=$(this).children();
			
			var hash = false; 
			
			function checkHash(){ 
				if(window.location.hash != hash) { 
					hash = window.location.hash;
					length=String(hash).length
					hash = String(hash).substring(0, length - 3);
				}
			}
			
			$(window).bind( 'hashchange', function(e) {
			   checkHash();
			   if (hash) {
					theItems.removeClass('hashed');//.children().css({'opacity':'1'});
					$('a[href="'+hash+'"]').parents('li').addClass('hashed').children().stop(true,true).animate({opacity:1});
					$('li:not(".hashed")', theList).children().stop(true,true).animate({opacity:.3});
				}
		   });
			
			$(window).trigger( 'hashchange' );
			
			
			$(theItems).css({'cursor':'pointer'}).hoverIntent({
			timeout: 0,
			sensitivity: 7,
			interval: 70,
			over: function(){
						if($('.hashed').length){
							$(this).children().stop(true,true).animate({opacity:1});
							$(this).siblings('.hashed').children().stop(true,true).animate({opacity:.3});
						}
						else {$(this).siblings().children().stop().animate({opacity:.3});}
					},
			out:function () {
					if($('.hashed').length){
						if(!$(this).hasClass('hashed')) $(this).children().stop(true,true).animate({opacity:.3});
						$(this).siblings('.hashed').children().stop(true,true).animate({opacity:1});
					}
					else {$(this).siblings().children().stop(true,true).animate({opacity:1});}
				}
			});


			

		});
	}
})(jQuery);


// JQuery BIG TARGET

(function($){
$.fn.bigTarget=function(options){
debug(this);
var opts=$.extend({},$.fn.bigTarget.defaults,options);
return this.each(function(){
var $a=$(this);
var href=$a.attr('href');
var title=$a.attr('title');
var o=$.meta?$.extend({},opts,$a.data()):opts;
$a.parents(o.clickZone)
.hover(function(){
$h=$(this);
$h.addClass(o.hoverClass);
if(typeof o.title!='undefined'&&o.title===true&&title!=''){
$h.attr('title',title);
}
},function(){
$h.removeClass(o.hoverClass);
if(typeof o.title!='undefined'&&o.title===true&&title!=''){
$h.removeAttr('title');
}
})
.click(function(){
if(getSelectedText()=="")
{
if($a.is('[rel*=external]')){
window.open(href);
return false;
}
else{
window.location=href;
}
}
});
});
};
function debug($obj){
if(window.console&&window.console.log)
window.console.log('bigTarget selection count: '+$obj.size());
};
function getSelectedText(){
if(window.getSelection){
return window.getSelection().toString();
}
else if(document.getSelection){
return document.getSelection();
}
else if(document.selection){
return document.selection.createRange().text;
}
};
$.fn.bigTarget.defaults={
hoverClass:'hover',
clickZone:'li:eq(0)',
title:true
};
})(jQuery);


// Function to allow easy access to URL parameters.
// http://www.domain.com/index.html?test=456
// var test_value = get_url_parameter(’test’);

function getParameter(paramName) {
  var searchString = window.location.search.substring(1),
      i, val, params = searchString.split("&");

  for (i=0;i<params.length;i++) {
    val = params[i].split("=");
    if (val[0] == paramName) {
      return unescape(val[1]);
    }
  }
  return null;
}

/*** legacy swap image functions to keep cart working ***/

﻿function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}


// Function to allow easy access to scroll to an ID.

function scrollToID (theID) {
            var headerHeight=$('.sticky').outerHeight();
            $('html,body').animate({
            scrollTop: $("#"+theID).offset().top - headerHeight
            }, 1000);
        }


// Function to shuffle any child elements of a parent element
// usage: $("parentElement").shuffle();
(function(a){a.fn.shuffle=function(){return this.each(function(){var b=a(this).children();return b.length?a(this).html(a.shuffle(b)):this})};a.shuffle=function(a){for(var b,c,d=a.length;d;b=parseInt(Math.random()*d),c=a[--d],a[d]=a[b],a[b]=c);return a}})(jQuery)


