/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <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@cherne.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 p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){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.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/*	SWFObject v2.2 <http://code.google.com/p/swfobject/> 
	is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();

function placeholders(inputs) {
  $j.each(inputs, function() {
		if ($j(this).val() == '') {
			$j(this).addClass("default").val($j(this).attr("placeholder"));
		}
  });
  inputs.focus(function() {
    if ($j(this).val() == $j(this).attr("placeholder")) {
      $j(this).addClass("focused").val("").removeClass("default");
    }
    return false;
  });
  inputs.blur(function() {
    if ($j(this).val().length < 1) {
      $j(this).removeClass("focused").addClass("default").val($j(this).attr("placeholder"));
    }
  });
}

$j.fn.center = function () {
	this.css("position", "absolute");
	
	/* adjust top position in case the popup is taller than the viewport */
	if (this.outerHeight() > $j(window).height()) {
		this.css("top", ($j(window).scrollTop() + 30 + "px"));
	}
	else {
		this.css("top", ( $j(window).height() - this.outerHeight() ) / 2+$j(window).scrollTop() + "px");
	}
	this.css("left", ( $j(window).width() - this.outerWidth() ) / 2+$j(window).scrollLeft() + "px");
	return this;
}

var PopUp = function (trigger, pop, opts) {
	this.trigger = $j(trigger);
	this.pop = $j(pop);
	
	this.defaults = {
		centered: false,
		modal: false,
		modalOverlay: $j('#modal_overlay'),
		loader: $j('#lightbox_loader').center(),
		close: $j(pop).find('.close'),
		fadeDuration: $j.browser.msie ? 0 : 300,
		ajax: false,
		reposition: false,
		openCB: function(){},
		closeCB: function(){}
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};

// new PopUp($j('a.chart'), $j('#size_chart'), {centered: true, modal: true, ajax: true});

PopUp.prototype = {
	setup: function () {
		var self = this;
		this.cache = {};
		
		this.trigger.click(function (ev) { 
			ev.preventDefault();
			self.open(); 
		});
	},
	open: function () {
		var self = this;
		
		if (this.options.centered) { 
			this.pop.center(); 
			$j(window).resize(function () { self.pop.center(); });
		}
		if (this.options.modal) { this.initModalOverlay(); }
		
		if (this.options.ajax) {
			var url = this.trigger.attr('href');
			if (!self.cache[url]) {
				self.options.loader.show();
				$j.ajax(
					{ 
						url: url,
						dataType: 'html',
						context: this,
						success: function (r) {	
							
							self.options.openCB();
							$j(this.pop).find('.content').empty();
							$j(this.pop).find('.content').append(r)
							//$j(this.pop).find('.content').html(r);
					
							/* make cufon replacements here */
							
							
							if (self.options.centered) { self.pop.center(); }
							if (self.pop.outerHeight() > $j(window).height()) {
								self.pop.css('top', ($j(window).scrollTop() + 30 + 'px'));
							}
							
							self.options.loader.hide();
							
							self.pop.show().css("z-index", 500);
							
							self.cache[url] = r;
							
							//Cufon.refresh();
							
							$j('#product_addtocart_form').validate();

						},
						error: function(r) {
							self.options.closeCB();
							self.options.loader.hide();
							self.options.modalOverlay.hide();
							$j('html, body').animate({scrollTop: 0}, 'normal');
							$j('#content').prepend('<ul class="messages" id="ajax_error"><li class="error-msg"><ul><li><span>There was a technical error in your request. Please try again in a few minutes.</span></li></ul></li></ul>');
							$j('#ajax_error').delay(5000).slideUp();
						}
					}
				);
			}
			else {
				//$j(this.pop).find('.content').html(self.cache[url]);
				$j(this.pop).find('.content').empty();
				$j(this.pop).find('.content').append(self.cache[url])
				this.options.openCB();
				
				this.pop.css("z-index", 500).show();
				
				/* make cufon replacements here */
				//Cufon.now();
				
			}
		}
		else {
			if (this.options.reposition) {
				var triggerPos = this.trigger.position();
				this.pop.css('top', triggerPos['top']);
				this.pop.css('left', triggerPos['left'] - (this.pop.width() / 2));
			}
			this.pop.css("z-index", 500).show();
		}
		
		this.options.close.click(function () { self.close(); });
		
		$j(document).unbind('click');
		$j(document).bind('closePop', function () { self.close(); });
		this.pop.hover(function () { $j(document).unbind('click'); });
		this.pop.bind('mouseleave', function () { 
			$j(document).click(function () { $j(document).trigger('closePop'); });
		});
		
	},
	close: function () {
		this.options.closeCB();
		this.pop.hide();
		$j('#modal_overlay').hide();
		//$j('.formError').remove();
	},
	initModalOverlay: function () {
		var height;
		if ($j(window).height() > $j('body:first').outerHeight()) {
			height = $j(window).height();
		}
		else {
			height = $j('body:first').outerHeight();
		}
		$j('#modal_overlay').css("height", height);
		$j('#modal_overlay').show();
	},
	setContent: function (content){
	  $j(this.pop).find('.content').html(content);
	}
};

var Tooltip = function (trigger, pop, opts) {
	this.trigger = $j(trigger);
	this.pop = $j(pop);
	
	this.defaults = {
		position: 'top',
		clickable: 'false',
		fadeDuration: $j.browser.msie ? 0 : 200,
		close: pop.find('.close'),
		link: false,
		openCB: function () {},
		closeCB: function () {}
	};
	this.options = $j.extend({}, this.defaults, opts);	
	this.setup();
};
Tooltip.prototype = {
	setup: function () {
		var self = this;
		if (this.options.clickable == 'true') {
			$j(this.trigger).click(function() {
				self.open();																
			});
		}
		else {
			$j(this.trigger, this.pop).hoverIntent({
				sensitivity: 1,
				interval: 300,
				over: function () {
					self.open();
				},
				out: function () {
					self.close();
				}
			});
		}
		
		if (this.options.link == true) {
			$j(this.trigger).click(function() {
				var url = self.trigger.find('a').attr('href');	
				window.location = url;
			});
		}
		
	},
	open: function () {
		var self = this;
		var triggerPos = this.trigger.position();
		
		switch(this.options.position) {
			case 'top':
				this.pop.css('top', triggerPos['top'] - this.pop.height());
				this.pop.css('left', triggerPos['left'] - (this.pop.width() / 2));
				break;
			case 'bottom':
				this.pop.css('top', triggerPos['top'] + this.pop.height());
				this.pop.css('left', triggerPos['left'] - (this.pop.width() / 2));
				break;
			case 'left':
				this.pop.css('left', triggerPos['left'] - this.pop.width() - this.trigger.width());
				this.pop.css('top', triggerPos['top'] - this.pop.height());
				break;
			case 'right':
				this.pop.css('left', triggerPos['left'] + this.trigger.width());
				this.pop.css('top', triggerPos['top'] - (this.pop.height() /2));
				break;
		}
		this.pop.css('z-index', 1000).show();
		this.options.close.click(function () { self.close(); });
		this.options.openCB();
	},
	close: function () {
		this.pop.hide();
		this.options.closeCB();
	}
};

/* tabs */
var Tabs = function (container, options) {
	this.container = $j(container);
	this.togglers = this.container.find('.tabs li');
	this.tabs = this.container.find('.tab');
	var settings = {
		'hover': false,
		'hoverIntent': false
	}
	if (options) {
		$j.extend(settings, options);
	}
	this.settings = settings;
	this.setup();
};
Tabs.prototype = {
	setup: function () {
		var self = this;
		this.show(0);
		if (this.settings.hover == true) {
			this.togglers.each(function(i) {
				$j(this).hover(
					function() {
						self.show(i);
					},
					function() {
						return;
					}
				);
			});
		}
		else if (this.settings.hoverIntent == true) {
			this.togglers.each(function(i) {
				$j(this).hoverIntent(
					function() {
						self.show(i);
					},
					function() {
						return;
					}
				);
			});	
		}
		else {
			this.togglers.each(function (i) {
				$j(this).click(function(ev) {
					ev.preventDefault();
					self.show(i);
				});
			});
		}
	},
	show: function (idx) {
		this.togglers.removeClass('active');
		$j(this.togglers[idx]).addClass('active');
		this.tabs.hide();
		$j(this.tabs[idx]).show();
		//this.container.css("height", $j(this.tabs[idx]).height());
	}
};

/* main navigation */
var Nav = function(triggers, dropdowns) {
	this.triggers = $j(triggers);
	this.dropdowns = $j(dropdowns);
	this.setup();
};
Nav.prototype = {
	setup: function() {
		var self = this;
		this.triggers.hoverIntent({
			interval: 50,
			over: function() {
				var index = $j(this).index();
				self.open($j(this), index);
			},
			out: function() {
				return;
			}
		});
		this.dropdowns.hover(
			function() {
				return;
			},
			function() {
				var index = $j(this).index();
				self.close($j(this), index);
			}
		);
	},
	open: function(el, index) {
		var self = this;
		this.dropdowns.hide().eq(index).show();
	},
	close: function(el, index) {
		this.dropdowns.eq(index).hide();
	}
};

var Slider = function(slides, count, toggles) {
	this.slides = $j(slides);
	this.toggles = $j(toggles);
	this.mask = this.slides.parents(".mask");
	this.count = count;
	this.setup();
};
Slider.prototype = {
	setup: function() {
		
		var self = this;
		
		this.toggles.click(function() {
			if ($j(this).hasClass('prev')) {
				self.prev();
			}
			else {
				self.next();
			}
		});
	},
	next: function() {
		var self = this;
		var slide_width = this.slides.eq(0).outerWidth();
		
		this.mask.animate({
					
		}, 1000, function() {
			
		});

	},
	prev: function() {
		var init_offset = this.mask.position();
		var mask_width = this.mask.outerWidth();
		
		console.log(init_offset.left);
		
		this.mask.animate({
			left: '+=810'									
		}, 1000, function() {
			
		});
		
	}
};

var Carousel = function(slides, toggles) {
	this.slides = $j(slides);
	this.toggles = $j(toggles);
	this.mask = this.slides.parents("ul");
	this.slide_width = this.slides.eq(0).outerWidth();
	this.setup();
};
Carousel.prototype = {
	setup: function() {
		var self = this;
		
		if (this.mask.position().left == 0) {
			self.toggles.filter(".prev").hide();
		}
		
		this.toggles.click(function() {
			if ($j(this).hasClass('prev')) {
				self.prev(self.mask.position().left);
			}
			else {
				self.next(self.mask.position().left);
			}
		});
	},
	next: function(position) {
		var self = this;
		
		if ((Math.abs(position) + this.slide_width) > 0) {
			this.toggles.filter(".prev").show();
		}

		this.mask.animate({
			left: position - self.slide_width							
		}, 500);
		
		if ((this.slides.size()*this.slide_width - this.slide_width) == (Math.abs(position) + this.slide_width)) {
			this.toggles.filter(".next").hide();
		}
		
	},
	prev: function(position) {
		var self = this;
		
		if ((this.slides.size()*this.slide_width - this.slide_width) != (Math.abs(position) + this.slide_width)) {
			this.toggles.filter(".next").show();
		}
		
		this.mask.animate({
			left: position + self.slide_width							
		}, 500);

		if ((Math.abs(position) - this.slide_width) == 0) {
			this.toggles.filter(".prev").hide();
		}

	}
};

var VideoPlayer = function (trigger, pop) {
	this.trigger = $j(trigger);
	this.pop = $j(pop);
	this.close_trigger = $j(pop).find('.close')
	this.setup();
};
VideoPlayer.prototype = {
	setup: function () {
		var self = this;
		this.cache = {};
		
		this.trigger.click(function (ev) { 
			ev.preventDefault();
			self.open(); 
		});
	},
	open: function () {
		var self = this;
		
		this.pop.center(); 
		$j(window).resize(function () { self.pop.center(); });
		this.initModalOverlay();
		
		/* video instantiation goes here */
		var video_url = this.trigger.attr('href');
		var video_title = this.trigger.attr('title');
		
		var params = { allowScriptAccess: 'always', autoplay: 1 };
    var atts = { id: 'myytplayer' };
    swfobject.embedSWF(video_url + '?enablejsapi=1&playerapiid=ytplayer&autoplay=1&rel=0','ytapiplayer', '640', '390', '8', null, null, params, atts);
		
		this.pop.find('.title').html(video_title);
		
		this.pop.show();
		
		this.close_trigger.click(function () { self.close(); });
		
		$j(document).unbind('click');
		$j(document).bind('closePop', function () { self.close(); });
		this.pop.hover(function () { $j(document).unbind('click'); });
		this.pop.bind('mouseleave', function () { 
			$j(document).click(function () { $j(document).trigger('closePop'); });
		});
	},
	close: function () {
		this.pop.hide();
		$j('#modal_overlay').hide();
		this.pop.find('.video').html('<div id="ytapiplayer"></div>');
	},
	initModalOverlay: function () {
		var height;
		if ($j(window).height() > $j('body:first').outerHeight()) {
			height = $j(window).height();
		}
		else {
			height = $j('body:first').outerHeight();
		}
		$j('#modal_overlay').css("height", height);
		$j('#modal_overlay').show();
	}
};

var Quickshop = function (trigger, pop, opts) {
	this.trigger = $j(trigger);
	this.pop = $j(pop);
	
	this.defaults = {
		centered: false,
		modal: false,
		modalOverlay: $j('#modal_overlay'),
		loader: $j('#quickshop_loader'),
		close: $j(pop).find('.close'),
		fadeDuration: $j.browser.msie ? 0 : 300,
		ajax: false,
		reposition: false,
		openCB: function () {},
		closeCB: function () {}
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};
Quickshop.prototype = {
	setup: function () {
		var self = this;
		this.cache = {};
		
		this.trigger.click(function (ev) { 
			ev.preventDefault();
			self.open(); 
		});
	},
	open: function () {
		var self = this;
		
		if (this.options.centered) { 
			this.pop.center(); 
			$j(window).resize(function () { self.pop.center(); });
		}
		if (this.options.modal) { this.initModalOverlay(); }
		
		if (this.options.ajax) {
			var url = this.trigger.attr('href');
			if (!self.cache[url]) {
				self.options.loader.center().show();
				$j.ajax(
					{ 
						url: url,
						dataType: 'html',
						context: this,
						success: function (r) {	
							
							self.options.openCB();
							$j(this.pop).find('.content').empty();
							$j(this.pop).find('.content').append(r)
							//$j(this.pop).find('.content').html(r);
					
							/* make cufon replacements here */
							
							if (self.options.centered) { self.pop.center(); }
							
							if (self.pop.outerHeight() > $j(window).height()) {
								self.pop.css('top', ($j(window).scrollTop() + 30 + 'px'));
							}
							
							self.options.loader.hide();
							self.pop.css("z-index", 500).show();
							
							self.cache[url] = r;
							
							Cufon.refresh();
							
							// JS involved in this request is in product/view.phtml
							// slightly modifying magento's behavior here.
							
							
						},
						error: function(r) {
							self.options.closeCB();
							self.options.loader.hide();
							self.options.modalOverlay.hide();
							$j('html, body').animate({scrollTop: 0}, 'normal');
							$j('#content').prepend('<ul class="messages" id="ajax_error"><li class="error-msg"><ul><li><span>There was a technical error in your request. Please try again in a few minutes.</span></li></ul></li></ul>');
							$j('#ajax_error').delay(5000).slideUp();
						}
					}
				);
			}
			else {
				//$j(this.pop).find('.content').html(self.cache[url]);
				$j(this.pop).find('.content').empty();
				$j(this.pop).find('.content').append(self.cache[url])
				this.options.openCB();
				
				if (self.options.centered) { self.pop.center(); }
				
				if (self.pop.outerHeight() > $j(window).height()) {
					self.pop.css('top', ($j(window).scrollTop() + 30 + 'px'));
				}
				
				this.pop.css("z-index", 500).show();
				
				Cufon.refresh();
				
			}
		}
		else {
			if (this.options.reposition) {
				var triggerPos = this.trigger.position();
				this.pop.css('top', triggerPos['top']);
				this.pop.css('left', triggerPos['left'] - (this.pop.width() / 2));
			}
			this.pop.css("z-index", 500).show();
		}
		
		this.options.close.click(function () { self.close(); });
		
		$j('#modal_overlay').unbind('click');
		$j('#modal_overlay').bind('closePop', function () { self.close(); });
		this.pop.hover(function () { $j('#modal_overlay').unbind('click'); });
		this.pop.bind('mouseleave', function () { 
			$j('#modal_overlay').click(function () { $j('#modal_overlay').trigger('closePop'); });
		});

	},
	close: function () {
		this.options.closeCB();
		this.pop.hide();
		$j('#modal_overlay').hide();
		//$j('.formError').remove();
		
		$j('#quickshop').css('width', '').css('height', '');
		
		// clear the quickshop
		$j('#quickshop').find('.content').html('').attr('id','');

	},
	initModalOverlay: function () {
		var height;
		if ($j(window).height() > $j('body:first').outerHeight()) {
			height = $j(window).height();
		}
		else {
			height = $j('body:first').outerHeight();
		}
		$j('#modal_overlay').css("height", height);
		$j('#modal_overlay').show();
	},
	setContent: function (content){
	  $j(this.pop).find('.content').html(content);
	}
};

function validateCreditCard(s) {
    // remove non-numerics
    var v = "0123456789";
    var w = "";
    for (i=0; i < s.length; i++) {
        x = s.charAt(i);
        if (v.indexOf(x,0) != -1)
        w += x;
    }
    // validate number
    j = w.length / 2;
    k = Math.floor(j);
    m = Math.ceil(j) - k;
    c = 0;
    for (i=0; i<k; i++) {
        a = w.charAt(i*2+m) * 2;
        c += a > 9 ? Math.floor(a/10 + a%10) : a;
    }
    for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
    return (c%10 == 0);
};

var Translate = Class.create();
Translate.prototype = {
    initialize: function(data){
        this.data = $H(data);
    },

    translate : function(){
        var args = arguments;
        var text = arguments[0];

        if(this.data.get(text)){
            return this.data.get(text);
        }
        return text;
    },
    add : function() {
        if (arguments.length > 1) {
            this.data.set(arguments[0], arguments[1]);
        } else if (typeof arguments[0] =='object') {
            $H(arguments[0]).each(function (pair){
                this.data.set(pair.key, pair.value);
            }.bind(this));
        }
    }
};


var Header = function (hdr, opts) {
	this.hdr = $(hdr);
	this.defaults = {
		maxChars: 11
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};
Header.prototype = {
	setup: function () {
		var fontSize = this.hdr.css('font-size').split('px')[0];
			numChars = this.hdr.text().length;
		
		if (numChars > this.options.maxChars) {
			this.hdr.css({
				'font-size': (this.options.maxChars / numChars) * fontSize + 'px'
			});
		}
	}
};

/* FormValidator Fix for IE7 & IE9 */

var ie7 = $j.browser.msie && $j.browser.version=="7.0";
var ie9 = $j.browser.msie && $j.browser.version=="9.0";
var safari =$j.browser.safari;
/*--------------------------------------------------------------------------*/

var FormValidator = function (form, opts) {
	this.form = $j(form);
	this.required = form.find('.required-entry');
	this.defaults = {
		email: form.find('.validate-email')
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};
FormValidator.prototype = {
	setup: function () {
		var self = this;
		
		this.form.submit(function () { 
			self.onSubmit(); 
		});
	},
	validateEmail: function () {
		var emailCheck = this.options.email.val().match(/^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i);
		if (emailCheck != null) { return true; }
		else { return false; }
	},
	onSubmit: function () {
		var self = this, numFilled = 0;
		this.required.each(function (idx) {
			if ($j(this).val().length > 0) {
				numFilled++;
			}
		});
		
		var valid = this.validateEmail() && (numFilled == this.required.length);
		if (valid) {
			this.form.removeAttr('onsubmit');
			this.form.submit();
			return true;
		} else {
		/*uncomment the alert below to test your numFilled variable
		if all is going well it shouldn't incriment and match the 
		number of required inputs you have*/
		//alert(numFilled);
			
		}
	}
};

/* weee */
function taxToggle(details, switcher, expandedClassName)
{
    if ($(details).style.display == 'none') {
        $(details).show();
        $(switcher).addClassName(expandedClassName);
    } else {
        $(details).hide();
        $(switcher).removeClassName(expandedClassName);
    }
}


/* get url parameters */
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
$j(document).ready(function() {

	//paragraph truncator
	$j('#truncMe').each(function(){
		var len = $j(this).text().length;
		if(len>122){
			var content = $j(this)
			var unwrapped = content.text().substring(0, 122) 
			var wrapped = '<span class="entry-content-hidden">'+content.text().substring(122, len)+'</span>';
			content.empty();
			content.append(unwrapped+'<span class="elipsisIt">...</span>'+wrapped);
			$j('.entry-content-hidden').after('<a href="#" class="readMoreIt">Read more</a>');
			$j('#truncMe').css({display:'inline-block'});
			
			$j(this).find('.readMoreIt').bind('click', function(){
				$j('.entry-content-hidden').fadeToggle('slow');
				$j('.elipsisIt').toggle();
				$j(this).text(($j(this).text() == 'Read more') ? 'Read less' : 'Read more');
				return false;
			});
		}else{
			$j('#truncMe').css({display:'inline-block'});
		}	
	});
	
											 								
	placeholders($j(":input[placeholder]"));
	
	new Nav($j("#main_nav li"), $j(".megadrops .megadrop"));
	
	if ($j('#department_slider').length) {
		new Slider($j('#department_slider .slide'), 3, $j('#department_slider .togglers div'));
	}
	
	if ($j('.carousel').length) {
		new Carousel($j('.carousel li'), $j('.carousel .toggles div'));
	}
	
	Cufon.replace(".std h1", {fontFamily: 'Glosa Display'});
	
	Cufon.replace(".megadrop .body .header", {fontFamily: 'Gotham Medium'});
	Cufon.replace(".megadrop h2 em", {fontFamily: 'Gotham Medium'});
	Cufon.replace(".megadrop .video .title", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#sidenav h2", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#sidenav .custom button span", {fontFamily: 'Gotham Bold'});
	Cufon.replace("#content h2 span, #product h2, #featured_products h2, #gr_search_results span", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#department .heading", {fontFamily: 'Gotham Medium'});
	Cufon.replace("#sidenav .new_arrivals", {fontFamily: 'Gotham Bold'});
	Cufon.replace("#shop_callout strong", {fontFamily: 'Glosa Italic'});
	Cufon.replace(".pagination a.next, .pagination a.prev, .page-sitemap ol a.next, .page-sitemap ol a.prev, a.gift_next", {fontFamily: 'Glosa Italic', hover: true});
	Cufon.replace(".faq-index-index #content h2", {fontFamily: 'Glosa Italic'});
	
	/* pager */
	Cufon.replace(".pager p.amount em", {fontFamily: 'Glosa Italic'});
	
	/* quickshop, product */
	Cufon.replace("#product h1:not(h1.mobile_product)", {fontFamily: 'Glosa Display'});
	Cufon.replace(".product .colors p span, .product .sizes p span, .product .quantity p span, .product .amount p span", {fontFamily: 'Gotham Medium'});
	Cufon.replace('.product .add .exchange', {fontFamily: 'Gotham Medium'});
	
	Cufon.replace("#content.wide h1", {fontFamily: 'Glosa Display'});
	Cufon.replace("#content.wide h2:not(.sitemap_group h2)", {fontFamily: 'Glosa Italic'});
	
	/* cart */
	Cufon.replace("#cart .header", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#cart h1", {fontFamily: 'Glosa Italic'});
	
	/* shopping cart */
	Cufon.replace("#shopping-cart-table th:not(.enterprise-giftregistry-index-items th, #wishlist-table th)", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#shopping-cart-table h2", {fontFamily: 'Glosa Italic'});
	Cufon.replace("#module_related .header", {fontFamily: 'Glosa Italic'});
	Cufon.replace(".item-options dt", {fontFamily: 'Gotham Medium'});
	Cufon.replace("#shopping-cart-totals-table tfoot strong:first, #shopping-cart-totals-table tr.grand_total strong:first", {fontFamily: 'Gotham Medium'});
	Cufon.replace(".gift-registry-name a", {fontFamily: 'Gotham Medium'});
	
	/* my account */
	Cufon.replace(".my-account h1 span, .account h1 span, .ai-sales-order-view h1 span", {fontFamily: 'Glosa Italic'});
	Cufon.replace(".my-account h2 span, .ai-sales-order-view h2 span", {fontFamily: 'Glosa Italic'});
	Cufon.replace(".my-account h3, #checkout_confirmation h3, .ai-sales-order-view h3", {fontFamily: 'Gotham Medium'});
	Cufon.replace(".my-account .welcome-msg .header", {fontFamily: 'Gotham Medium'});
	Cufon.replace("#registry button span", {fontFamily: 'Gotham Medium'});
	
	/* brands page */
	/*Cufon.replace("ol#brands_navigation a", {fontFamily: 'Gotham Medium', hover: true});*/
	Cufon.replace("ol#brands_navigation", {fontFamily: 'Gotham Medium', hover: true});
	Cufon.replace("#brands_list h2", {fontFamily: 'Gotham Medium'});
	Cufon.replace("#container h1:not(#content h1)", {fontFamily: 'Glosa Display'});

	
	/* login, register */
	Cufon.replace("h2.legend", {fontFamily: 'Glosa Italic'});
	
	/* confirmation */
	Cufon.replace('#checkout_confirmation h2', {fontFamily: 'Glosa Italic'});
	Cufon.replace('#checkout_confirmation h1', {fontFamily: 'Gotham Medium'});
	Cufon.replace('#checkout_confirmation .order_number span', {fontFamily: 'Gotham Medium'});
	Cufon.replace('#checkout_confirmation #account_benefits .header', {fontFamily: 'Gotham Medium'});
	Cufon.replace('#customerLocations h3', {fontFamily: 'Gotham Medium'});
	
	/* search */
	Cufon.replace('.catalogsearch-result-index #content h1', {fontFamily: 'Glosa Display'});
	Cufon.replace('.catalogsearch-result-index #content h2', {fontFamily: 'Glosa Italic'});
	Cufon.replace('.event_list h2', {fontFamily: 'Glosa Italic'});
	Cufon.replace('#pressBoxImg h2', {fontFamily: 'Glosa Italic'});
	
	Cufon.replace('.catalogsearch-result-index #content button', {fontFamily: 'Gotham Medium'});
	
	Cufon.replace('.gallery .label', {fontFamily: 'Gotham Medium'});
	Cufon.replace("#store_locations h2", {fontFamily: 'Gotham Medium'});
	
	Cufon.replace('.cms-loyalty-program #content h2', {fontFamily: 'Glosa Italic'});
	
	/* category pages */	
	if ($j('.category-brands').length) { 
		Cufon.replace(".brand_voice .lead", {fontFamily: 'Gotham Medium'});
	}
	if ($j('.catalog-category-view').length) {
		Cufon.replace('#container h1:not(#content h1)', {fontFamily: 'Glosa Display'});
		new Header($j('#container h1:not(#content h1)'));
	}
	
	/* generic content h1 */
	Cufon.replace('#content h1:not(h1.mobile_product)', {fontFamily: 'Glosa Italic'});
	/* generic content h2 */
	Cufon.replace("h2.glosa_general", {fontFamily: 'Glosa Italic'});

	/*popup for shipping in account*/
	new PopUp($j('a.lineLink'), $j('#shipping_exchanges_info'), {centered: true, modal: true});
	
	/* validate footer signup */
	if ($j('#newsletter-validate-detail').length) {
		$j('#newsletter-validate-detail').validate();
	}
	
	/* video popups */
	$j('a.play_video').each(function() {
	  new VideoPlayer($j(this), $j('#video_player'));																			 
	});
	
	/* we'll probably want a specially made class for this, but for now... */
	$j('ul.products li').hover(
		function() {
			$j(this).find('.quickshop_trigger').show();
		},
		function() {
			$j(this).find('.quickshop_trigger').hide();
		}
	);
	$j('.simple_photo').hide();
	
	$j(".swatch").click(function(){		
		$j(this).parent().parent().prev().find('.simple_photo').hide();
		$j(this).parent().parent().prev().find('.photo').hide();
		$j("#"+$j(this).attr("rel")).show();		
	})

		if($j('#coupon_tooltip_trigger').length>0){
				new Tooltip($j('#coupon_tooltip_trigger'), $j('#tooltip_coupon'), {position: 'right', clickable: true}); 
}
	
	//checks to see if the news has an image, if not resizes
	if($j('.event_item').length>0){
		$j('.pressContentContain').next('p').remove();
		$j('.event_item').each(function(){
			if($j(this).children('img').length >0){
				$j(this).children('.event_details').css({width:'75%'});
			}else{
				$j(this).children('.event_details').css({width:'100%'});
			}
		});
		$j('.seeMore').live('click', function(){
			$j('.showIt').slideToggle('slow', function(){
				$j('.event_item h3, .item_options dt .cufon').css({height:'auto'})
			});
			$j(this).text(($j('.seeMore').text() == 'Show More Events') ? 'Hide Past Events' : 'Show More Events');
		});		
		if($j('#contentTwo').length >0){
			if($j('#contentTwo .event_item').length>1){
				var len = $j('#contentTwo .event_item').length;
				$j('#contentTwo .event_item:last').after('<a href="javascript:void(0);" class="seeMore">Show More Events</a>')
				$j("#contentTwo .event_item:gt(0)").wrapAll('<div class="showIt"></div>');
				$j('.showIt').hide();
			}
		}
		
	}

	
	$j('.quickshop_trigger a').each(function() {
		quickshop_pop = new Quickshop($j(this), $j('#quickshop'), {modal: true, centered: true, ajax: true});						
	});

	/* signin popup form submit */
	//$j('#login #loader').hide();
	$j('#login #loader').hide();
	$j('#login #login-form').submit(function(){
	    $j('#login #loader').show();
	    url = $j(this).attr("action");
	    $j.ajax(
	      { 
		url: url,
		dataType: 'json',
		type: 'POST',
		data:{
		    'login[username]' : $j('#login #login-form #email').val(),
		    'login[password]' : $j('#login #login-form #pass').val(),
		    'success_url' : $j('#login #login-form #success_url').val()
		    },
		cache: false,
		context: this,
		async: true,
		success: function (data) {
		  $j('#login .messages').html('');
		  if (data.success=='true') {
		    if (data.url){
		      window.location=data.url;
		    }else{
		      location.reload()
		    }
		  }
		  else {
		      $j('#login #loader').hide();
		      messages = data.messages;
		      messages.each(function(msg){
			$j('#login .messages').append('<li class="error-msg"><ul><li><span>' + msg + '</span></li></ul></li>');
		      });
		  }
		  
		}
	      }
	    );
	    return false;
	});
	

	
	
      /* add to giftregistry popup to be called via an AJAX call */
      add_to_giftregistry_popup = new PopUp($j('a.add_to_giftregistry_trigger'), $j('#add_to_giftregistry'), {centered: true, modal: true});

	/* cart popup to be called via an AJAX call */
      cart_popup = new PopUp($j('a.cart_trigger'), $j('#cart'), {centered: true, modal: true});
			
	/* reposition footer */
	if (($j('body').height() + 40) < $j(window).height()) {
		$j('#footer').addClass('fixed');
	}
	$j(window).resize(function() {
		if (($j('body').height() + 40) < $j(window).height()) {
			$j('#footer').addClass('fixed');
		}
		else {
			$j('#footer').removeClass('fixed');	
		}
	});
	
	shipping_info_popup = new PopUp($j('a.shipping_info_trigger'), $j('#shipping_info'), {centered: true, modal: true, ajax: true});
	
});

function goToByScroll(id){
      $j('html,body').animate({scrollTop: $j("#"+id).offset().top},'slow');
}

//validate gift registry
var validateItGift = function(e){
	$j('.requiredIt').each(function(){
	if($j(this).val().length == 0){
		e.preventDefault();
		$j(this).next('.reqGift').fadeIn('slow');
		$j(this).addClass('validation-failed');	
	}else if($j(this).val().length == 1){
		e.preventDefault();
		$j(this).closest('div').find('.twoletter').fadeIn('slow');
		$j(this).addClass('validation-failed');
		
	}else{
		$j(this).closest('div').children('.validation-advice').fadeOut('slow')
		$j(this).removeClass('validation-failed');	
	}
	});
}
$j('#gr-quick-search-form .button').live('click', function(e){
	validateItGift(e);
});

$j('#gr-quick-search-form').live('keypress', function(e){
	 if (e.keyCode == 13) {
		 validateItGift(e);
    }
	
});
$j('.requiredIt').live('blur', function(e){
	validateItGift(e);
});


//show more brands - left nav
$j('a.view_more').live('click', function(e) {
	e.preventDefault();
	$j(".brands_more").toggle("slow");
	$j(this).text($j(this).text() == 'View More' ? 'View Less' : 'View More');
	
});


