/*--------------------------------------------------------------------------*/


var ie6 = $j.browser.msie && $j.browser.version=="6.0";
var ieModern = $j.browser.msie && $j.browser.version>="9.0";
/*--------------------------------------------------------------------------*/
/**
* 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($j){$j.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$j.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){$j(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;$j(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$j(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);

/*--------------------------------------------------------------------------*/

// jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function(f,h,i){function k(a,c){var b=(a[0]||0)-(c[0]||0);return b>0||!b&&a.length>0&&k(a.slice(1),c.slice(1))}function l(a){if(typeof a!=g)return a;var c=[],b="";for(var d in a){b=typeof a[d]==g?l(a[d]):[d,m?encodeURI(a[d]):a[d]].join("=");c.push(b)}return c.join("&")}function n(a){var c=[];for(var b in a)a[b]&&c.push([b,'="',a[b],'"'].join(""));return c.join(" ")}function o(a){var c=[];for(var b in a)c.push(['<param name="',b,'" value="',l(a[b]),'" />'].join(""));return c.join("")}var g="object",m=true;try{var j=i.description||function(){return(new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}()}catch(p){j="Unavailable"}var e=j.match(/\d+/g)||[0];f[h]={available:e[0]>0,activeX:i&&!i.name,version:{original:j,array:e,string:e.join("."),major:parseInt(e[0],10)||0,minor:parseInt(e[1],10)||0,release:parseInt(e[2],10)||0},hasVersion:function(a){a=/string|number/.test(typeof a)?a.toString().split("."):/object/.test(typeof a)?[a.major,a.minor]:a||[0,0];return k(e,a)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(a){if(!a.swf||this.expressInstallIsActive||!this.available&&!a.hasVersionFail)return false;if(!this.hasVersion(a.hasVersion||1)){this.expressInstallIsActive=true;if(typeof a.hasVersionFail=="function")if(!a.hasVersionFail.apply(a))return false;a={swf:a.expressInstall||this.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:this.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:a.swf,type:"application/x-shockwave-flash",id:a.id||"flash_"+Math.floor(Math.random()*999999999),width:a.width||320,height:a.height||180,style:a.style||""};m=typeof a.useEncode!=="undefined"?a.useEncode:this.encodeParams;a.movie=a.swf;a.wmode=a.wmode||"opaque";delete a.fallback;delete a.hasVersion;delete a.hasVersionFail;delete a.height;delete a.id;delete a.swf;delete a.useEncode;delete a.width;var c=document.createElement("div");c.innerHTML=["<object ",n(attrs),">",o(a),"</object>"].join("");return c.firstChild}};f.fn[h]=function(a){var c=this.find(g).andSelf().filter(g);/string|object/.test(typeof a)&&this.each(function(){var b=f(this),d;a=typeof a==g?a:{swf:a};a.fallback=this;if(d=f[h].create(a)){b.children().remove();b.html(d)}});typeof a=="function"&&c.each(function(){var b=this;b.jsInteractionTimeoutMs=b.jsInteractionTimeoutMs||0;if(b.jsInteractionTimeoutMs<660)b.clientWidth||b.clientHeight?a.call(b):setTimeout(function(){f(b)[h](a)},b.jsInteractionTimeoutMs+66)});return c}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject);

/*--------------------------------------------------------------------------*/ 

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5($j){5 L(a){a.3x.1F[a.3r]=3o(a.3n,10)+a.3l}6 j=5(a){3k({3i:"1E.1d.3d 3c 3b",38:a})};6 k=5(){7(/*@2S!@*/19&&(2Q 2N.1w.1F.2K==="2F"))};6 l={2C:[0,4,4],2B:[1u,4,4],2y:[1s,1s,2v],2u:[0,0,0],2t:[0,0,4],2s:[1q,1p,1p],2o:[0,4,4],2n:[0,0,B],2m:[0,B,B],2l:[1b,1b,1b],2j:[0,1c,0],2i:[2h,2g,1o],2e:[B,0,B],2d:[2c,1o,2b],2a:[4,1n,0],27:[24,21,20],1Z:[B,0,0],1Y:[1R,1P,1O],1N:[3s,0,Y],2f:[4,0,4],1Q:[4,2z,0],2E:[0,t,0],22:[26,0,28],29:[1u,1z,1n],2p:[2r,2w,1z],2x:[1h,4,4],2A:[1i,2G,1i],2L:[Y,Y,Y],2M:[4,2O,2W],33:[4,4,1h],34:[0,4,0],35:[4,0,4],36:[t,0,0],39:[0,0,t],3e:[t,t,0],3j:[4,1q,0],3m:[4,W,3t],1H:[t,0,t],1I:[t,0,t],1J:[4,0,0],1K:[W,W,W],1L:[4,4,4],1M:[4,4,0],9:[4,4,4]};6 m=5(a){U(a&&a.1j("#")==-1&&a.1j("(")==-1){7"1S("+l[a].1T()+")"}1U{7 a}};$j.1V($j.1W.1X,{w:L,x:L,u:L,v:L});$j.1k.23=5(){7 V.1l(5(){6 a=$j(V);a.1d(a.F(\'1m\'))})};$j.1k.1d=5(i){7 V.1l(5(){6 c=$j(V),3,$j8,C,11,1f,1e=k();U(c.F(\'S\')){7 19}6 e={R:(5(a){2k(a){X"T":7"Z";X"Z":7"T";X"15":7"14";X"14":7"15";2q:7"Z"}})(i.R),y:m(i.A)||"#H",A:m(i.y)||c.z("12-A"),1r:c.N(),D:i.D||1t,Q:i.Q||5(){},K:i.K||5(){},P:i.P||5(){}};c.F(\'1m\',e).F(\'S\',1).F(\'2D\',e);3={s:c.s(),p:c.p(),y:m(i.y)||c.z("12-A"),1v:c.z("2H-2I")||"2J",R:i.R||"T",E:m(i.A)||"#H",D:i.D||1t,o:c.1x().o,n:c.1x().n,1y:i.1r||2P,9:"9",18:i.18||19,Q:i.Q||5(){},K:i.K||5(){},P:i.P||5(){}};1e&&(3.9="#2R");$j8=c.z("16","2T").8(2U).F(\'S\',1).2V("1w").N("").z({16:"1g",2X:"2Y",n:3.n,o:3.o,2Z:0,30:31,"-32-1A-1B":"G G G #1C","-37-1A-1B":"G G G #1C"});6 f=5(){7{1D:3.9,1v:0,3a:0,w:0,u:0,v:0,x:0,M:3.9,O:3.9,I:3.9,J:3.9,12:"3f",3g:\'3h\',p:0,s:0}};6 g=5(){6 a=(3.p/1c)*25;6 b=f();b.s=3.s;7{"q":b,"1a":{w:0,u:a,v:a,x:0,M:\'#H\',O:\'#H\',o:(3.o+(3.p/2)),n:(3.n-a)},"r":{x:0,w:0,u:0,v:0,M:3.9,O:3.9,o:3.o,n:3.n}}};6 h=5(){6 a=(3.p/1c)*25;6 b=f();b.p=3.p;7{"q":b,"1a":{w:a,u:0,v:0,x:a,I:\'#H\',J:\'#H\',o:3.o-a,n:3.n+(3.s/2)},"r":{w:0,u:0,v:0,x:0,I:3.9,J:3.9,o:3.o,n:3.n}}};11={"T":5(){6 d=g();d.q.w=3.p;d.q.M=3.y;d.r.x=3.p;d.r.O=3.E;7 d},"Z":5(){6 d=g();d.q.x=3.p;d.q.O=3.y;d.r.w=3.p;d.r.M=3.E;7 d},"15":5(){6 d=h();d.q.u=3.s;d.q.I=3.y;d.r.v=3.s;d.r.J=3.E;7 d},"14":5(){6 d=h();d.q.v=3.s;d.q.J=3.y;d.r.u=3.s;d.r.I=3.E;7 d}};C=11[3.R]();1e&&(C.q.3p="3q(A="+3.9+")");1f=5(){6 a=3.1y;7 a&&a.1E?a.N():a};$j8.17(5(){3.Q($j8,c);$j8.N(\'\').z(C.q);$j8.13()});$j8.1G(C.1a,3.D);$j8.17(5(){3.P($j8,c);$j8.13()});$j8.1G(C.r,3.D);$j8.17(5(){U(!3.18){c.z({1D:3.E})}c.z({16:"1g"});6 a=1f();U(a){c.N(a)}$j8.3u();3.K($j8,c);c.3v(\'S\');$j8.13()})})}})(3w);',62,220,'|||flipObj|255|function|var|return|clone|transparent||||||||||||||left|top|height|start|second|width|128|borderLeftWidth|borderRightWidth|borderTopWidth|borderBottomWidth|bgColor|css|color|139|dirOption|speed|toColor|data|0px|999|borderLeftColor|borderRightColor|onEnd|int_prop|borderTopColor|html|borderBottomColor|onAnimation|onBefore|direction|flipLock|tb|if|this|192|case|211|bt||dirOptions|background|dequeue|rl|lr|visibility|queue|dontChangeColor|false|first|169|100|flip|ie6|newContent|visible|224|144|indexOf|fn|each|flipRevertedSettings|140|107|42|165|content|245|500|240|fontSize|body|offset|target|230|box|shadow|000|backgroundColor|jquery|style|animate|purple|violet|red|silver|white|yellow|darkviolet|122|150|gold|233|rgb|toString|else|extend|fx|step|darksalmon|darkred|204|50|indigo|revertFlip|153||75|darkorchid|130|khaki|darkorange|47|85|darkolivegreen|darkmagenta|fuchsia|183|189|darkkhaki|darkgreen|switch|darkgrey|darkcyan|darkblue|cyan|lightblue|default|173|brown|blue|black|220|216|lightcyan|beige|215|lightgreen|azure|aqua|flipSettings|green|undefined|238|font|size|12px|maxHeight|lightgrey|lightpink|document|182|null|typeof|123456|cc_on|hidden|true|appendTo|193|position|absolute|margin|zIndex|9999|webkit|lightyellow|lime|magenta|maroon|moz|message|navy|lineHeight|error|plugin|js|olive|none|borderStyle|solid|name|orange|throw|unit|pink|now|parseInt|filter|chroma|prop|148|203|remove|removeData|jQuery|elem'.split('|'),0,{}))

/*--------------------------------------------------------------------------*/

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/*--------------------------------------------------------------------------*/

/**
 * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 3/11/2009
 * @author Ariel Flesler
 * @version 1.2.7
 **/
;(function($){var l=location.href.replace(/#.*/,'');var g=$.localScroll=function(a){$('body').localScroll(a)};g.defaults={duration:1e3,axis:'y',event:'click',stop:true,target:window,reset:true};g.hash=function(a){if(location.hash){a=$.extend({},g.defaults,a);a.hash=false;if(a.reset){var e=a.duration;delete a.duration;$(a.target).scrollTo(0,a);a.duration=e}i(0,location,a)}};$.fn.localScroll=function(b){b=$.extend({},g.defaults,b);return b.lazy?this.bind(b.event,function(a){var e=$([a.target,a.target.parentNode]).filter(d)[0];if(e)i(a,e,b)}):this.find('a,area').filter(d).bind(b.event,function(a){i(a,this,b)}).end().end();function d(){return!!this.href&&!!this.hash&&this.href.replace(this.hash,'')==l&&(!b.filter||$(this).is(b.filter))}};function i(a,e,b){var d=e.hash.slice(1),f=document.getElementById(d)||document.getElementsByName(d)[0];if(!f)return;if(a)a.preventDefault();var h=$(b.target);if(b.lock&&h.is(':animated')||b.onBefore&&b.onBefore.call(b,a,f,h)===false)return;if(b.stop)h.stop(true);if(b.hash){var j=f.id==d?'id':'name',k=$('<a> </a>').attr(j,d).css({position:'absolute',top:$(window).scrollTop(),left:$(window).scrollLeft()});f[j]='';$('body').prepend(k);location=e.hash;k.remove();f[j]=d}h.scrollTo(f,b).trigger('notify.serialScroll',[f])}})(jQuery);

/*--------------------------------------------------------------------------*/

/*
 Color animation jQuery-plugin
 http://www.bitstorm.org/jquery/color-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Released under the MIT and GPL licenses.
*/
(function(d){function i(){var b=d("script:first"),a=b.css("color"),c=false;if(/^rgba/.test(a))c=true;else try{c=a!=b.css("color","rgba(0, 0, 0, 0.5)").css("color");b.css("color",a)}catch(e){}return c}function g(b,a,c){var e="rgb"+(d.support.rgba?"a":"")+"("+parseInt(b[0]+c*(a[0]-b[0]),10)+","+parseInt(b[1]+c*(a[1]-b[1]),10)+","+parseInt(b[2]+c*(a[2]-b[2]),10);if(d.support.rgba)e+=","+(b&&a?parseFloat(b[3]+c*(a[3]-b[3])):1);e+=")";return e}function f(b){var a,c;if(a=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(b))c=
[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16),1];else if(a=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(b))c=[parseInt(a[1],16)*17,parseInt(a[2],16)*17,parseInt(a[3],16)*17,1];else if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(b))c=[parseInt(a[1]),parseInt(a[2]),parseInt(a[3]),1];else if(a=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(b))c=[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10),parseFloat(a[4])];return c}
d.extend(true,d,{support:{rgba:i()}});var h=["color","backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","outlineColor"];d.each(h,function(b,a){d.fx.step[a]=function(c){if(!c.init){c.a=f(d(c.elem).css(a));c.end=f(c.end);c.init=true}c.elem.style[a]=g(c.a,c.end,c.pos)}});d.fx.step.borderColor=function(b){if(!b.init)b.end=f(b.end);var a=h.slice(2,6);d.each(a,function(c,e){b.init||(b[e]={a:f(d(b.elem).css(e))});b.elem.style[e]=g(b[e].a,b.end,b.pos)});b.init=true}})(jQuery);

/*--------------------------------------------------------------------------*/

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $j(window).height() - this.height() ) / 2+$j(window).scrollTop() + "px");
    this.css("left", ( $j(window).width() - this.width() ) / 2+$j(window).scrollLeft() + "px");
    return this;
}

/*--------------------------------------------------------------------------*/

function externalLinks() {
 	if (!document.getElementsByTagName) return;
 	var externals = $j("a[rel='external']");
	
	externals.each(function () {
		if ($j(this).attr('href')) {
			$j(this).bind('click', function (ev) {
				ev.preventDefault();
				window.open($j(this).attr('href'));
			});
		}
	});
}

/*--------------------------------------------------------------------------*/

function EqualHeight (cols) {
	var maxHeight = 0;
	$j.each(cols, function () { 
		if ($j(this).outerHeight(true) > maxHeight) {
			maxHeight = $j(this).height();
		}
	}).css('height', maxHeight);
}

/*--------------------------------------------------------------------------*/

var PopUp = function (trigger, pop, opts) {
	this.trigger = $j(trigger);
	this.pop = $j(pop).css('visibility', 'hidden');
	this.pop.appendTo($j('body:first'));
	
	this.defaults = {
		centered: false,
		modal: false,
		ajax: false,
		modalOverlay: $j('#modal_overlay'),
		//loader: pop.find('.loader'),
		//close: pop.find('.close'),
		fadeDuration: $j.browser.msie ? 0 : 200,
		openCB: function () {},
		closeCB: function () {}
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};
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.ajax) {
			var error = $j('<div></div>').text('An Error Has Occurred.  Please Try Again.').addClass('error');
			var loader = $j('<div></div>').addClass('loader').append($j('<div></div>').text('Loading...'));
			this.pop.find('.inner:first').append(loader);
			var url = this.trigger.attr('href');
			
			
			if (!self.cache[url]) {
				$j(self.pop).find('.content:first').html('');
				self.pop.find('.loader').show();
				$j.ajax(
					{ 
						url: url,
						dataType: 'html',
						context: this,
						success: function (r) {	
							
							$j(self.pop).find('.content:first').html(r);
							self.options.openCB();
							
							if (self.options.centered) { self.pop.center(); }
							
							self.pop.find('.loader').hide();
							
							self.pop.center();
							self.pop.css('visibility', 'visible');
							self.pop.fadeIn(self.options.fadeDuration);
							
							self.cache[url] = r;
							
							if (self.options.modal) { self.initModalOverlay(); }
							
							$j(document).trigger('pop:loaded');
						},
						error: function () {
							self.pop.find('.loader').hide();
							$j(self.pop).find('.content:first').html(error);
							self.pop.center();
							self.pop.css('visibility', 'visible');
							self.pop.fadeIn(self.options.fadeDuration);
							if (self.options.modal) { self.initModalOverlay(); }
							$j(document).trigger('pop:loaded');
						}
					}
				);
			}
			else {
				$j(this.pop).find('.content:first').html(self.cache[url]);
				this.options.openCB();
				this.pop.center();
				this.pop.css('visibility', 'visible');
				this.pop.fadeIn(this.options.fadeDuration);
				if (this.options.modal) { this.initModalOverlay(); }
				$j(document).trigger('pop:loaded');
			}
		}
		else { 
			if (this.options.modal) { this.initModalOverlay(); }
			this.pop.center();
			this.pop.css('visibility', 'visible');
			this.pop.fadeIn(this.options.fadeDuration); 
			$j(document).trigger('pop:loaded');
			this.options.openCB();
		}
		
		if (!this.hasOpened) {
			var close = $j('<div></div>').text('Close_X').addClass('close');
			//this.pop.find('header:first').append(close);
			this.pop.append(close);
			this.hasOpened = true;
			this.pop.find('.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'); });
		});
		$j(document).keyup(function (ev) {
			if (ev.keyCode == 27) { self.close(); }
		});
	},
	close: function () {
		var self = this;
		this.pop.fadeOut(this.options.fadeDuration, function () {
			self.options.closeCB();
		});
		
		if ($j.browser.msie) { this.modalOverlay.hide(); }
		else { this.modalOverlay.fadeOut(this.options.fadeDuration); }
	},
	initModalOverlay: function () {
		
		if (!$j('#modal_overlay').length) {
			$j('body:first').append($j('<div></div>').attr('id', 'modal_overlay').hide());
			this.modalOverlay = $j('#modal_overlay');
			this.modalOverlay.css("height", $j('#content').height());
		}
		
		if ($j.browser.msie) { this.modalOverlay.show(); }
		else { this.modalOverlay.fadeIn(this.options.fadeDuration); }
	}
};

/*--------------------------------------------------------------------------*/

var Prompt = function (field) {
	this.input = field.children('input[type="text"]');
	this.label = field.children('label');
	this.defaultText = this.label.text();
	this.setup();
};
Prompt.prototype = {
	setup: function () {
		var self = this;
		this.input.val('');
		this.label.click(function () { self._focus(true); });
		this.input.bind('focus', function () { self._focus(); });		
		this.input.bind('blur', function () { self._blur(); });
	},
	_focus: function (focus) {
		this.label.hide();
		if (focus) { this.input.focus(); }
		this.input.addClass('active');
	},
	_blur: function () {
		if (this.input.val() == '') { this.label.show(); }
		this.input.removeClass('active');
	}
};

/*--------------------------------------------------------------------------*/

var SlideShow = function (container, slides, delay, initial) {
    this.container = $j(container);
    this.slides = $j(slides);
    this.delay = delay;
    this.current = initial;
	this.togglersContainer = this.container.find('.togglers ul');
	//this.togglersContainer = this.container.find('.togglers ul').html('');
    this.setup();
};
SlideShow.prototype = {
    setup: function () {
    	   	
        var self = this;
        this.showOnly($j(this.slides[this.current]));
		
		for (i = 0; i < this.slides.length; i++) {
			var li = $j('<li>Slide ' + i + '</li>');
			self.container.find('.togglers ul');
			//self.container.find('.togglers ul').append(li);
		}
		
		this.togglers = this.togglersContainer.find('li');
		$j(this.togglers[0]).addClass('first');
		$j(this.togglers.last()).addClass('last');
        $j(this.togglers[this.current]).addClass('active');
        
        this.togglers.bind('click', function () {
            self.pause();
            self.goTo($j(this).index());
        });
		
		this.start();
    },
    showOnly: function (el) {
        this.slides.hide();
        el.show();
    },
    goTo: function (idx) {
        var self = this;
		
        if (idx === this.current) {	return; }
		
        $j(this.togglers[this.current]).removeClass('active');
		
		
        this.fade = $j(this.slides[this.current]).stop(true, true).fadeOut('slow');
        this.current = idx;
		
        $j(this.togglers[this.current]).addClass('active');
        
		
		this.appear = $j(this.slides[this.current]).stop(true, true).fadeIn('slow');
		
        this.start();
    },
    start: function () {
        if (this.timer) { return; }
        var self = this;
        this.timer = setTimeout(function(){
            self.next();
        }, this.delay * 1500);
    },
    pause: function () {
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = false;
        }
        else { return; }
    },
    next: function() {
        this.timer = false;
        if (this.current === this.slides.length - 1) { this.goTo(0); }
        else { this.goTo(this.current + 1); }
        this.start();
    }
};

/*--------------------------------------------------------------------------*/

var Tabs = function (togglers, tabs, start, opts) {
	this.togglers = $j(togglers);
	this.tabs = $j(tabs);
	this.start = start;
	
	this.defaults = {
		showCB: function () {},
		fade: false
	};
	this.options = $j.extend({}, this.defaults, opts);
	
	this.setup();
};
Tabs.prototype = {
	setup: function () {
		var self = this;		
		this.show(this.start);

		this.togglers.click(function (ev) {
			ev.preventDefault();
			self.show($j(this).index());
		});
	},
	show: function (idx) {
		this.togglers.removeClass('active');
		$j(this.togglers[idx]).addClass('active');
				
		if (this.options.fade) { 
			this.tabs.fadeOut(); 
			$j(this.tabs[idx]).fadeIn();
		}
		else { 
			this.tabs.hide(); 
			$j(this.tabs[idx]).show();
		}
		
		this.options.showCB();
	}
};	

/*--------------------------------------------------------------------------*/

var Carousel = function (container, increment, delay, opts) {
	this.container = $j(container);	
	this.increment = increment;
	this.contents = this.container.find('.slides:first');
	this.slides = this.container.find('.slide');

	this.prevBtn = this.container.find('.prev:first');
	this.nextBtn = this.container.find('.next:first');
	this.slideCount = this.slides.length / this.increment;
	
	//this.slideCount = slideCount;
	if (this.contents.length) {
		this.offset = this.contents.position()['left'];
	}
	//this.width = $j(this.slides[0]).outerWidth(true);
	this.delay = delay | 5;
	
	this.defaults = {
		current: 0,
		keyboard: false,
		slideCB: function () {}
	};
	this.options = $j.extend({}, this.defaults, opts);
	
	this.current = this.options.current;
	
	this.setup();
};
Carousel.prototype = {
	setup: function () {
		var self = this;
		
		this.prevBtn.click(function (ev) {
			ev.preventDefault();
			self.back();
		});
		
		this.nextBtn.click(function (ev) {
			ev.preventDefault();
			self.forward();
		});
		
		/* enable keyboard controls */
		if (this.options.keyboard) {
			$j(document).keydown(function (ev) {
				var keyCode = ev.keyCode || ev.which,
					arrow = { left: 37, up: 38, right: 39, down: 40 };
				ev.preventDefault();
				switch (keyCode) {
					case arrow.left:
						self.back();
						break;
						
					case arrow.right:
						self.forward();
						break;
				}
			});
		}
		
		this.goTo(this.current);
		
		/*
		if (this.slides.length <= this.increment) {
			this.prevBtn.addClass('disabled');
			this.nextBtn.addClass('disabled');
		}
		*/
		
		
		//this.start();
	},
	goTo: function (idx) {
		var self = this;
		//this.prevBtn.removeClass('disabled');
		//this.nextBtn.removeClass('disabled');
		
		/*
		if (idx == 0) { this.prevBtn.addClass('disabled'); }
		if (idx == parseInt(this.increment / this.slideCount)) { this.nextBtn.addClass('disabled'); }	
		*/
		
	    if (this.current === idx) { return; }		
		if (idx < 0 || idx >= this.slideCount) { return; }
		
		this.current = idx;	
		
		var width = this.increment * this.slides.outerWidth(true);
		//var width = this.slides.outerWidth(true);
		$j(this.contents).stop().animate(
			{ left: (-(idx * width) + this.offset) },
			{ duration: 500, easing: 'easeOutExpo', complete: function () { self.options.slideCB();  } }
		);
		//return this.current;
	},
	getCurrent: function () { return this.current; },
	start: function () {
        if (this.timer) { return; }
        var self = this;
        this.timer = setTimeout(function(){
            self.next();
        }, this.delay * 1000);
	},
	pause: function () {
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = false;
        }
        else { return; }
	},
	back: function () {
		this.pause();
        if (this.current === 0) {
			return; 
        	//this.goTo(this.slides.length - 1);	
        }
        else {
            this.goTo(this.current - 1);	
        }
        //this.start();	
	},
	forward: function () {
        this.pause();
        this.next();
	},
	next: function () {
        if (this.current+1 === this.slides.length) {
			//this.timer = false;
			return;
			//this.goTo(0);
		}
        else {
            this.goTo(this.current + 1);
        }
        //this.start();
	}
};

/*--------------------------------------------------------------------------*/

var Dock = function (container) {
	this.container = $j(container);
	this.slides = container.find('.slide');
	this.mainTogglers = container.find('nav.main li');
	this.tabsWrap = container.find('.tabs');
	this.togglers = this.tabsWrap.find('nav li');
	this.tabs = this.tabsWrap.find('.tab');
	this.viewed = {};
	this.PER_SLIDE = 2;
	this.slideWidth = 412;
	this.slideMargin = 25;
	this.dockCarousels = [];
	//this.setup();
};
Dock.prototype = {
	setup: function () {
		var self = this;
		
		this.mainTogglers.click(function () { self.open($j(this).index()); });
		this.togglers.click(function () { self.bindCarousel($j(this).index()); });
	
		this.resizeGap();
		$j(window).resize(function () { self.resizeGap(); });
	},
	firstLoad: function () {
		var self = this;
		var togglers = $j('footer nav.main li');
		if (!$j.browser.msie) { togglers.css('opacity', 0); }
		
		$j('footer').delay(500).animate(
			{ bottom: 0 }, 
			{ 
				duration: 900, 
				easing: 'easeOutQuad',
				complete: function () {
					togglers.each(function (i) {
						var toggler = $j(this);
						setTimeout(function () { 
							if (!$j.browser.msie) { toggler.animate({ opacity: 1 }, 1000); }
						}, 200 * i); 
					});
				}
			}
		);
	},
	open: function (idx) {
		var self = this;
		this.container.addClass('active');
		this.mainTogglers.fadeOut();
		$j('.touts.home').fadeOut();
		$j('.hero.home .togglers').fadeOut();
		$j('footer nav.utility .social li').css('position', 'static');
		this.tabsWrap.animate(
			{ top: 0 }, 
			{ duration: 400, easing: 'easeOutCirc', complete: function () { self.show(idx); } }
		);
	},
	show: function (idx) {
		var self = this;
		this.tabsWrap.find('.close').click(function () { self.close(idx); });
		this.togglers.removeClass('active');
		$j(this.togglers[idx]).addClass('active');
		
		this.bindCarousel(idx);
		
		if (!this.loaded) {
			
			new Tabs(this.togglers, this.tabs, idx);
		
			this.bindSocial(this.tabs.find('.slide'));
		
			if (!$j.browser.msie) { 
				$j(this.tabs[idx]).find('.slide').css('opacity', 0);
				$j(this.tabs[idx]).find('.slide').each(function (idx) {
					var slide = $j(this);
					setTimeout(function () { slide.animate({ opacity: 1}, { duration: 1200 }); }, 100 * idx);
				});
			}
			
			$j(this.tabs[idx]).find('.slides').css('left', $j(window).width());
			$j(this.tabs[idx]).find('.slides').animate(
				{ left: 0 },
				{ duration: 800, easing: 'easeOutExpo' }
			);				
			
			this.loaded = true;
		}
		
		//$j(window).resize(function () { self.bindCarousel(idx, self.numSlides); });
	},
	resizeGap: function () {
		var self = this;
		var btn = this.tabsWrap.find('.toggle');
		var slides = this.tabsWrap.find('.slide');
		this.overflowWidth = $j(window).width() - (btn.width() * 2);
		var gap = Math.ceil(($j(window).width() - (slides.width() * this.PER_SLIDE) - (btn.width() * 2)) / this.PER_SLIDE);
		
		this.numPerSlide = Math.ceil(this.overflowWidth / this.slideWidth);
		

		this.bindPeaks();		
	
		//this.addPeeks(this.numPerSlide);
		
		this.tabsWrap.find('.overflow').css('width', this.overflowWidth);
		//this.tabsWrap.find('.slide').css('margin-right', Math.max(gap, 17));
		this.tabsWrap.find('.slide').css('margin-right', 25);
	},
	bindCarousel: function (idx) {
		var self = this;
		
		if (!this.viewed[idx]) {
			this.dockCarousels[idx] = new Carousel($j(this.tabs[idx]), 1, 5, { keyboard: true });
		}
		this.viewed[idx] = true;
		
	},
	bindPeaks: function () {
		var self = this, next = true;
		this.tabs.each(function (idx) {
			self.addPeeks(self.numPerSlide, idx, 0);
			
			$j(this).find('.prev').click(function () {
				self.addPeeks(self.numPerSlide, idx, -1);
			});
			$j(this).find('.next').click(function () {
				self.addPeeks(self.numPerSlide, idx, 1);
			});
		});	
	},
	addPeeks: function (numPSlide, tabIdx, offset) {
		var self = this, current = null;
		var min = 0, max = $j(this.tabs[tabIdx]).find('.slide').length;
		
		var numSlides = $j(this.tabs[tabIdx]).find('.slide').length;
	
		if (numSlides < this.numPerSlide) { 
			$j(this.tabs[tabIdx]).find('.toggle').addClass('disabled');
		} else { 
			$j(this.tabs[tabIdx]).find('.toggle').removeClass('disabled');
		}
		
		if (this.dockCarousels[tabIdx]) { 
			if (this.dockCarousels[tabIdx].getCurrent() == 0 && offset == -1) { offset = 0; }
			if (this.dockCarousels[tabIdx].getCurrent() == (max - 1) && offset == 1) { offset = 0; }
			current = this.dockCarousels[tabIdx].getCurrent(); 
		}
		else { current = 0; }
		
		current += offset;
		
		$j(this.tabs[tabIdx]).find('.slide').each(function (i) {	
			$j(this).removeClass('peek').unbind('mouseover mouseout');
			if (i != 0) {
				if (i % (numPSlide - 1 + current) == 0) {
					$j(this).addClass('peek');
				}
			}
		});
		
		this.peeks = $j(this.tabs[tabIdx]).find('.peek');
		this.peeks.hoverIntent({
			sensitivity: 1,
			interval: 100,
			over: function () { self.peekIn($j(this), numPSlide); },
			out: function () { self.peekOut($j(this), numPSlide); }
		});
		
	},
	peekIn: function (slide, idx) {
		var slideContainer = slide.parents('.slides'),
			slideLeftWidth = (this.slideWidth * idx) - this.overflowWidth - this.slideMargin;
		slideContainer.animate(
			{ marginLeft: -slideLeftWidth },
			{ duration: 500, easing: 'easeOutExpo' }
		);
	},
	peekOut: function (slide, idx) {
		var slideContainer = slide.parents('.slides'),
			slideLeftWidth = (this.slideWidth * idx) - this.overflowWidth;
		slideContainer.animate(
			{ marginLeft: 0 }, 
			{ duration: 500, easing: 'easeOutExpo' }
		);
	},
	close: function (idx) {
		var self = this;
		this.tabsWrap.animate(
			{ top: 246 }, 
			{ 
				duration: 300, 
				easing: 'easeOutCirc',
				complete: function () { 
					self.mainTogglers.fadeIn(); 
					$j('.touts.home').fadeIn();
					$j('.hero.home .togglers').fadeIn();
					self.container.removeClass('active');
					$j('footer nav.utility .social li').css('position', 'relative');
				}
			}
		);
	},
	bindSocial: function (slides) {
		var self = this;
		slides.each(function () {
			var slide = $j(this);
			$j(this).find('.quote').toggle(
				function () { self.showSocial(slide); },
				function () { self.hideSocial(slide); }
			);
		});
	},
	showSocial: function (slide) {
		slide.addClass('sn');
		slide.animate({ borderBottomColor: '#13c0f2'}, 300);
		slide.find('.info:not(".social")').fadeOut(300);
		slide.find('.social').fadeIn();
	},
	hideSocial: function (slide) {
		slide.removeClass('sn');
		slide.animate({ borderBottomColor: '#fff'}, 300);
		slide.find('.info:not(".social")').fadeIn(300);
		slide.find('.social').fadeOut();
	}
};

/*--------------------------------------------------------------------------*/

var GlobalSearch = function (container) {
	this.container = $j(container);
	this.trigger = container.find('.trigger');
	this.overlay = container.find('.overlay');
	this.closeBtn = container.find('.close');
	this.setup();
};
GlobalSearch.prototype = {
	setup: function () {
		var self = this;
		this.trigger.click(function () { self.open(); });
	},
	open: function () {
		var self = this;
		this.overlay.fadeIn(200);
		this.trigger.fadeOut(200);
		this.closeBtn.fadeIn(200);
		this.closeBtn.click(function () { self.close(); });
	},
	close: function () {
		this.overlay.fadeOut(200);
		this.trigger.fadeIn(200);
		this.closeBtn.fadeOut(200);
	}
};

/*--------------------------------------------------------------------------*/

var Accordion = function (slides, narrowWidth, openWidth) {
	this.slides = $j(slides);
	this.defaultWidth = $j(slides[0]).width();
	this.narrowWidth = narrowWidth;
	this.openWidth = openWidth;
	this.dur = 350;
	this.ease = 'easeOutSine';
	this.origLeft = this.slides.find('.photo').css('left');
	this.setup();
};
Accordion.prototype = {
	setup: function () {
		var self = this;
		/*
		this.slides.hoverIntent({
			sensitivity: 1,
			interval: 100,
			over: function () { self.dispatch($j(this)); },
			out: function () { self.close($j(this)); }
		});
		*/
		this.slides.find('.photo').click(function (ev) { 
			ev.preventDefault();
			self.dispatch($j(this).parents('.item')); 
		});
		
		this.dispatch($j(this.slides[0]));
	},
	dispatch: function (slide) {
		var self = this;
		var center = .3 * this.narrowWidth / 2;
		this.slides.each(function () {
			if ($j(this).index() != slide.index()) {
				self._animate($j(this), self.narrowWidth, center, false);
			}
			else { 
				self.slides.find('.info').hide();
				self._animate($j(this), self.openWidth, 0, true); 
			}
		});	
	},
	_animate: function (slide, width, left, isActive) {
		var self = this;
		slide.find('.photo').stop().animate(
			{ left: left },
			{ duration: self.dur, easing: self.ease }
		);
		slide.stop().animate(
			{ width: width },
			{ 
				duration: self.dur, 
				easing: self.ease, 
				complete: function () {
					if (isActive) {
						slide.find('.info').fadeIn(200);
						slide.addClass('active');
					}
					else {
						slide.removeClass('active');
					}
				}
			}
		);
	}
};

/*--------------------------------------------------------------------------*/

var ProductControl = function (container, opts) {
	this.container = $j(container);
	this.sizes = container.find('.sizes li');
	this.colors = container.find('.swatches li');
	this.colorName = container.find('.swatches .name');
	
	this.defaults = {
		initial: null
	};
	this.options = $j.extend({}, this.defaults, opts);	
	
	this.setup();
};
ProductControl.prototype = {
	setup: function () {
		var self = this;
		this.done = true;
		
		if (this.options.initial != null) { 
			this.setColor(this.options.initial); 
		}
		else { this.setColor($j(this.colors[0])); }

		this.sizes.click(function () { self.setSize($j(this), false); });
		this.colors.click(function () { self.setColor($j(this));});
		
	},
	setSize: function (size, checkFirst) {
		var isDisabled = size.hasClass('disabled');
		var itemColor = size.data('item-color');
		var itemSize = size.data('item-size');
		
		if (!isDisabled) {
			this.container.find('#out-of-stock').css('display', 'none');
			this.container.find('.product-options-bottom .btn').removeClass('disabled');
			this.sizes.removeClass('active');
			$j(this.sizes[size.index()]).addClass('active');
			this.container.find('#size-attribute').attr('value', $j(this.sizes[size.index()]).attr('rel'));
		} else {
			this.container.find('#out-of-stock').css('display', 'block');
			this.container.find('.product-options-bottom .btn').addClass('disabled');
			this.container.find('#out-of-stock-size').text(itemSize);
			this.container.find('#out-of-stock-color').text(itemColor);
		}
	},
	setColor: function (color) {
		//this.colors.removeClass('active');
		//$j(this.colors[color.index()]).addClass('active');
		this.sizes.removeClass('active');
		this.colorName.text(color.text());
		var colorID = color.attr('rel'),
			numSizes = 0,
			numDisabled = 0,
			addToCart = this.container.find('.product-options-bottom .btn').removeClass('disabled');
		
		if (colorID == undefined) {
			var initialColor = color.attr('class').split('active')[0].replace(' ', '');
			this.colors.each(function () {
				if ($j(this).hasClass(initialColor)) { colorID = $j(this).attr('rel'); }
			});		
		}
		
		this.sizes.each(function () {
			var sizeID = $j(this).attr('class').split('disabled')[0].split('size-')[1].replace(' ', '');
			if (sizeID == colorID) {
				numSizes++;
				if ($j(this).hasClass('disabled')) { numDisabled++; }
			}
		});
		
		
		if (numDisabled == numSizes) { 
			addToCart.addClass('disabled'); 
		} 
	}
};

/*--------------------------------------------------------------------------*/

var CurrencySwitcher = function (container) {
	this.container = $j(container);
	this.menu = container.find('ul');
	this.countries = container.find('li.flag');
	this.current = container.find('.current');
	this.setup();
};
CurrencySwitcher.prototype = {
	setup: function () {
		var self = this;
		
		this.current.hoverIntent({
			sensitivity: 1,
			interval: 25,
			over: function () { 
				self.menu.show(); 
				self.container.css('z-index', 10);
			},
			out: function () { return; }
		});		
		
		this.menu.mouseleave(function () { $j(this).hide(); });
		
		this.countries.click(function () {
			self.current.children('a').attr('class', $j(this).children('a').attr('class'));
			self.current.children('a').text($j(this).children('a').text());
			self.menu.hide();
			self.container.css('z-index', 2);
			//$j(this).insertBefore(self.countries.first());
		});
	}
};

/*--------------------------------------------------------------------------*/

var DynamicResize = function (images, opts) {
	//this.images = $j(images).height('100%');
	this.images = $j(images);
	this.defaults = {
		min: 1370
	};
	this.options = $j.extend({}, this.defaults, opts);

	this.setup();
};
DynamicResize.prototype = {
	setup: function () {
		var self = this;
		this.minHeight = this.images.height();
		
		this._resize($j(window).width());
		$j(window).resize(function () { 
			self._resize($j(window).width());
		});
	},
	_resize: function (width) {
		
		if (width > this.options.min) {
			this.images.width(width);
		}
	}
};	

/*--------------------------------------------------------------------------*/

var ReverseResize = function (wrappers, images, width, height) {
	this.wrappers = $j(wrappers);
	
	this.images = $j(images);
	this.imgW = width;
	this.imgH = height;
	this.imgRatio = height / width;
	
	this.setup();
};
ReverseResize.prototype = {
	setup: function () {
		var currWidth = $j(window).width();
		var currHeight = $j(window).height();
		var windowRatio = currHeight / currWidth;
		
		var taller = this.imgRatio < windowRatio;
		
		var wDiff = this.imgW - currWidth;
		var hDiff = this.imgH - currHeight;

		if (taller){ wDiff = hDiff / this.imgRatio; } 
		else { hDiff = wDiff * this.imgRatio; }
		
		this.images.css({
			'width': Math.max(this.imgW + wDiff, taller ? currHeight / this.imgRatio : currWidth),
			'height': Math.max(this.imgH + hDiff, taller ? currHeight : currWidth * this.imgRatio)
		});
		
		this.wrappers.css({
			'top': Math.min(0, -(hDiff)),
			'left': Math.min(0, -(wDiff))
		});
	}
};

/*--------------------------------------------------------------------------*/

var ProductColors = function (container, opts) {
	this.container = $j(container);
	this.triggers = container.find('.swatches li');
	this.defaults = {
		zoom: false,
		initial: null
	};
	this.options = $j.extend({}, this.defaults, opts);
	this.setup();
};
ProductColors.prototype = {
	setup: function() {
		var self = this;

		this.triggers.live('click', function (ev) {
			ev.preventDefault();
			self.toggle($j(this).attr('class'));
		});
		
		if (this.options.initial != null) {
			if ($j(this.options.initial).hasClass('cat-prod-img-parent')) {
				this.toggle($j(this.triggers[0]).attr('class'));
			}
			else {
				this.toggle($j(this.options.initial).attr('class'));
			}
			
		}
		else {
			this.toggle($j(this.triggers[0]).attr('class'));
		}
	},
	toggle: function (color) {
		var self = this;
		this.toggleMain(color);
		//this.toggleMore(color);
	},
	toggleMain: function (color) {
		var self = this;
		color = color.replace(" active", "");
		this.triggers.filter(function () {
			self.triggers.removeClass('active');
			return $j(this).attr('class').split("active")[0] == color;
		}).addClass('active');
		
		var mainImage = '#main-image-' + color;
		var show = this.container.find(mainImage);
		
		var zoom = this.container.find(".zoom-" + color);
		var dur = $j.browser.msie ? 0 : 200;
		
		this.container.find('#out-of-stock').hide();
		this.container.find('.product-options-bottom .btn').removeClass('disabled');
		
		this.container.find('.product-image').each(function () {
			if ($j(this).attr('id') != $j(show).attr('id')) {
				if ($j.browser.msie && !ieModern) { 
					$j(this).css('visibility', 'hidden'); 
				}
				else { $j(this).animate({ opacity: 0 }, dur); }
	
				
				colorId = $j(this).attr('rel');
				var size = '.size-' + colorId;
				$j(size).hide();
			}
		});	
		
		//$j(show).fadeIn(dur);
		if ($j.browser.msie && !ieModern) {  $j(show).css('visibility', 'visible'); }
		else { $j(show).animate({ opacity: 1 }, dur); }

		colorId = $j(show).attr('rel');
		var size = this.container.find('.size-' + colorId);
		$j(size).show();
		this.container.find('#color-attribute').attr('value', $j(show).attr('rel'));
		
		sizeSelected = false;
		
		
		$j(size).each(function () {

			var isDisabled = $j(this).hasClass('disabled');
			var itemColor = $j(this).data('item-color');
			var itemSize = $j(this).data('item-size');
			
			if (!isDisabled && !sizeSelected) {
				self.container.find('#out-of-stock').css('display', 'none');
				$j(this).addClass('active');
				self.container.find('#size-attribute').attr('value', $j(this).attr('rel'));
				sizeSelected = true;
			}
		});
		
		var zoom_id = '#zoom-' + color;
		var zoom = $j(zoom_id);
		var zoom_image_path = zoom.data('path');
		
		zoom.attr('href', zoom_image_path);
		if (this.options.zoom) { zoom.CloudZoom(); }
	},
	toggleMore: function(color) {
		var show = '#more-views-' + color;
		$j('.more-views').hide();
		$j(show).show();
	}
};

/*--------------------------------------------------------------------------*/

var Mega = function (trigger, menu) {
	this.trigger = $j(trigger);
	this.menu = $j(menu);
	this.setup();
};
Mega.prototype = {
	setup: function () {
		var self = this;
		this.trigger.hoverIntent({
			sensitivity: 1,
			interval: 50,
			over: function () { 
				self.menu.show(); 
				EqualHeight(self.menu.find('.col ul'));
			},
			out: function () { return; }
		});
		this.menu.mouseleave(function () { $j(this).hide(); });
	}
};

/*--------------------------------------------------------------------------*/

function hideFlags () {
	var flags = $j('header.main .currency li');
	//$j(flags[2]).hide();
	$j(flags[3]).hide();
}

/*--------------------------------------------------------------------------*/

var AjaxCart = function (container) {
	this.container = $j(container);
	var currentURL = document.URL;
	
	if (currentURL.indexOf("can") != -1) {
		this.url = '/can/sugoicatalog/index/cartCount';
	} else {
		this.url = '/usa/sugoicatalog/index/cartCount';
	}
	this.setup();
};
AjaxCart.prototype = {
	setup: function () {
		var self = this;
		$j.getJSON(this.url, function (data) {
			self.container.text(data.cart_qty);
			self.container.css('visibility', 'visible');
		});
	}
};

/*--------------------------------------------------------------------------*/

function recordOutboundLink (link, category, action) {
	_gat._getTrackerByName()._trackEvent(category, action);
	setTimeout('document.location = "' + link.href + '"', 100);
}

/*--------------------------------------------------------------------------*/

function EqualHeight (cols, offset) {
	var maxHeight = 0, os=offset || 0;
	$j.each(cols, function () { 
		if ($j(this).outerHeight(true) > maxHeight) {
			maxHeight = $j(this).outerHeight(true);
		}
	}).css('height', maxHeight + os);
}

/*--------------------------------------------------------------------------*/

function loadScript (path, content) {
	var script = $j('<script></script>').attr({
		type: 'text/javascript',
		src: path
	});
	content.append(script);
}

/*--------------------------------------------------------------------------*/

var AddToCart = function (container, form) {
	this.container = $j(container);
	this.form = $j(form);
	this.trigger = container.find('.product-options-bottom .btn');
	
	this.lightbox = $j('#just_added').appendTo('body:first');
	this.lightbox.center();
	
	this.loader = this.container.find('.product-options-bottom .loader');

	this.fadeDuration = $j.browser.msie ? 0 : 200;
	this.setup();
};
AddToCart.prototype = {
	reconstruct: function (trigger) {
		var self = this;
		
		this.trigger.live('click', function (ev) {
			self.doNothing();
		});
		
		this.trigger = $j(trigger);
		this.loader = this.container.find('.product-options-bottom .loader');
		//this.setup();
	},
	doNothing: function () {},
	setup: function () {
		var self = this;
		
		this.trigger.unbind('click').bind('click', function (ev) {
			if (!$j(this).hasClass('disabled')) {
				self.add();
			}
			ev.preventDefault();
		});
	},
	add: function () {	
		var self = this;
		this.loader.show();
	
		var req = $j.ajax({
			url: self.trigger.attr('href'),
			data: self.form.serialize()
		});
		
		req.then(
			function (data) {
				
				var content = self.lightbox.find('.content:first');
				
				if (data.indexOf('-ERROR-') != -1) {
					alert(data.replace('-ERROR-', ''));
					self.close();
				}
				else {
					content.html(data);
					self.open();
					new AjaxCart($j('header.main .utility .cart span'));
				}
				self.loader.hide();
			}
		);		
	},
	open: function () {
		var close = $j('<div></div>').text('Close_X').addClass('close'),
			self = this;
		this.lightbox.append(close);
		this.lightbox.find('.close').click(function () { self.close(); });
		this.lightbox.center();
		
		$j(window).resize(function () { self.lightbox.center(); });
		
		this.initModalOverlay();
		this.lightbox.fadeIn(this.fadeDuration);
	},
	close: function () {
		this.lightbox.fadeOut(this.fadeDuration);
		if ($j.browser.msie && this.modalOverlay!=null) { this.modalOverlay.hide(); }
		else { if(this.modalOverlay!=null){ this.modalOverlay.fadeOut(this.fadeDuration);} }
	},
	initModalOverlay: function () {
		if (!$j('#modal_overlay').length) {
			$j('body:first').append($j('<div></div>').attr('id', 'modal_overlay').hide());
			this.modalOverlay = $j('#modal_overlay');
			this.modalOverlay.css("height", $j('#content').height());
		}
		
		if ($j.browser.msie && this.modalOverlay!=null) { this.modalOverlay.show(); }
		else { if(this.modalOverlay!=null){ this.modalOverlay.fadeIn(this.fadeDuration);} }
	}
};

/*--------------------------------------------------------------------------*/

var QuickView = function (product) {
	this.product = $j(product);
	this.photo = product.find('.photo');
	this.lightbox = $j('#quickview');
	this.qv = product.find('.qv');
	this.loader = product.find('.loader');
	this.cache = {};
	this.dur = 200;
	this.setup();
};
QuickView.prototype = {
	setup: function () {
		var self = this;
		this.photo.hoverIntent({
			sensitivity: 1,
			interval: 1,
			over: function () { $j(this).addClass('hover'); },
			out: function () { $j(this).removeClass('hover'); }
		});
		
		var currentURL = document.URL;
		
		var country = '/usa';
		
		if (currentURL.indexOf("can") != -1) {
			country = '/can';
		}
		if (currentURL.indexOf("fra") != -1) {
			country = '/fra';
		}
		
		var url = country + "/ajaxproductimage/index/quickview?sku=" + this.qv.attr('rel');
		this.color = null;
		this.photo.find('.qv').click(function () { 
			self.color = self.product.find('.swatches li.active');
			if (self.color.length == 0) {
				if ($j(this).hasClass('solo')) {
					self.solo = true;
				}
				
				if ($j(this).parents('.might-like').length) {
					self.color = self.product.find('img');
				} else { self.color = self.product.find('img.cat-prod-img-parent'); }
			}
			self.open(url); 
		});
	},
	open: function (url) {	
		var self = this;
		this.lightbox.find('.close').live('click', function () { self.close(); });
		var error = $j('<div></div>').text('An Error Has Occurred.  Please Try Again.').addClass('error');
		$j(document).keyup(function (ev) {
			if (ev.keyCode == 27) { self.close(); }
		});
		
		if (!this.cache[url]) {
			this.loader.show();
			// $j.ajaxSetup({ cache: false });
			$j.ajax({
				url: url,
				dataType: 'html',
				context: this,   
				success: function (r) {
					//self.lightbox.find('.inner:first').html(r);
					self.cache[url] = r;
					self.reset(r);
					
				},
				error: function () {	
					self.content = error;
					self.reset(error);
					//self.lightbox.find('.inner:first').html(error);
				}
			});
		}
		else {
			//this.lightbox.find('.inner:first').html(this.cache[url]);
			this.reset(this.cache[url]);
		}
	},
	reset: function (content) {
		var self = this;
		this.loader.hide();
		this.productControl = null, this.swatchControl = null;
		this.initModalOverlay();
		this.lightbox.fadeIn(this.dur);
		this.lightbox.center();
		this.lightbox.find('.inner:first').html(content);
		
		new AddToCart(this.lightbox, this.lightbox.find('#product_addtocart_quickview_form'));
		
		if (this.solo) {
			this.productControl = new ProductControl(this.lightbox, { initial: self.lightbox.find('.swatches li:first') });
			this.swatchControl = new ProductColors(this.lightbox, { initial: self.lightbox.find('.swatches li:first') });
		}
		else {
			this.productControl = new ProductControl(this.lightbox, { initial: self.color });
			this.swatchControl = new ProductColors(this.lightbox, { initial: self.color });
		}
		
		//this.lightbox.css('visibility', 'visible');
	},
	close: function () {
		this.lightbox.fadeOut(this.dur);
		if ($j.browser.msie) { this.modalOverlay.hide(); }
		else { this.modalOverlay.fadeOut(this.dur); }
		this.firstTime = true;
	},
	initModalOverlay: function () {
		if (!this.hasOpened) {
			var body = $j('body:first');
			body.append($j('<div></div>').attr('id', 'modal_overlay').hide());
			this.modalOverlay = $j('#modal_overlay');
			this.modalOverlay.css("height", $j('#content').height());
			this.hasOpened = true;
		}
		
		if ($j.browser.msie) { this.modalOverlay.show(); }
		else { this.modalOverlay.fadeIn(this.dur); }
	}
};

/*--------------------------------------------------------------------------*/

$j(document).ready(function () {

	/* ajax cart */
	new AjaxCart($j('header.main .utility .cart span'));
	
	/* currency switcher */
	new CurrencySwitcher($j('header.main .currency'));
	
	/* global search */
	new GlobalSearch($j('header.main .search'));
		
	/* megas */
	$j('header.main nav li').each(function () { new Mega($j(this), $j(this).find('.mega')); });

	/* dock */
	var dock = new Dock($j('.dock'));
	dock.setup();
	
	/* newsletter lightbox */
	new PopUp($j('footer nav.utility .newsletter a'), $j('#newsletter'), {
		centered: true,
		modal: true,
		openCB: function () { new Prompt($j('#newsletter .text')); }
	});
	
	var cols = $j('#right_column, #main');
	if (cols.length == 2) { EqualHeight(cols); }
	
	/* fullbleed hero's */
	if ($j('.fullbleed').length && !$j('.body:first').hasClass('home')) { 
		new DynamicResize($j('.hero img.main, .hero .slide img')); 
	}
	
	if ($j('.cms-custom').length) { new DynamicResize($j('#content .slide img')); }
	
	externalLinks();
	

});

