
function getcookie(name)
{
  var start = document.cookie.indexOf(name+"=");
  var len = start+name.length+1;
  if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
  if (start == -1) return null;
  var end = document.cookie.indexOf(";",len);
  if (end == -1) end = document.cookie.length;
  return unescape(document.cookie.substring(len,end).replace('+',' '));
}

function setcookie(name,value,days)
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function in_array(element, array)
{
	for (var i = 0; i < array.length; i++) {
		if (array[i] == element) {
			return true;
		}
	}
	return false;
}


function checklogin()
{
  var username = getcookie('csbname');
  if (username != null && getcookie('csbsesh') != null) {
    document.getElementById('fxhomeusername').appendChild(document.createTextNode(username));

	if (username.match(/^FXhomer[0-9]+$/)) {
		otherOptions = '<a href="http://fxhome.com/account/username">Change Name</a>';
		document.getElementById('loggedInOptions').innerHTML = otherOptions;
	}

    document.getElementById('loggedOut').style.display = 'none';
    document.getElementById('loggedIn').style.display = 'inline';
  }
  else {
    document.getElementById('loggedOut').style.display = 'block';
    document.getElementById('loggedIn').style.display = 'none';
  }
}

(function($) {
	$(document).ready(function() {
		// hides the overlay when the darkened bg is clicked
		$('.overlay .bg').click(function() {
			$(this).parent().hide();
			return false;
		});

		// hides the overlay when the close button is clicked
		$('.overlay .close').click(function() {
			$(this).parent().parent().hide();
			return false;
		});

		// displays the overlay when an activating button is clicked
		$('a.overlayActivator[rel]').click(function() {
			$($(this).attr('rel')).show();
			return false;
		});

		// when the page loads if the overlay is specified in the url show it
		if (window.location.search) {
			var qs = window.location.search.substring(1);
			var qsitems = qs.split("&");
			for (i=0; i<qsitems.length; i++) {
				var item = qsitems[i].split('=');
				if (item[0] == 'showoverlay') {
					$('#'+item[1]).show();
				}
			}
		}
	});
})(jQuery);
		
// initializes the nicer button transforms and loads in the community footer
(function($) {
	$(document).ready(function() {
		// load the community footer
		$('#fx-community-footer-placeholder').load('http://fxhome.com/community-footer');
	});
})(jQuery);

// fixes all the currency sensitive text elements on the page
function fixPrices() {

	if((window.altPrices !== undefined) && (window.userCurrencyCode !== undefined) && (window.userCurrencyCode != 'USD')) {
		var spanTags = document.getElementsByTagName('span');
		var parts;
		var numChanged = 0;

		for (var i = (spanTags.length - 1); i >= 0; i--){

			parts = /^([a-z]+)price$/.exec(spanTags[i].className);

			if(parts){

				for(var j = 0; j < altPrices.length; j++){
					if(altPrices[j].id == ''+parts[1]+window.userCurrencyCode){
						while(spanTags[i].childNodes.length > 0) {
							spanTags[i].removeChild(spanTags[i].childNodes[0]);
						}
					    spanTags[i].appendChild(document.createTextNode(altPrices[j].price.replace('&pound;','�')));
						numChanged++;
						break;
					}
				}
			}
		}
	}

	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
		if(version < 6){
			// versions of IE less than 6.0 cant cope with button swapping
			return;
		}
	}
}

(function($) {
	$(document).ready(function() {
		fixPrices();

		$('.currency').each(function() {
			var $el = $(this);
			var currency = userCurrencyCode || 'USD';
			var correctedCurrency = $el.data(currency.toLowerCase());
			if (correctedCurrency) {
				$el.text(correctedCurrency);
			}
		});
	});
})(jQuery);


// adds the show/hide on click behaviour to the currency selector
(function($) {
	var currencyMap = {
		USD: {label: '$ US Dollars', flag: 'http://static.fxhome.com/images/flagUS.gif'},
		GBP: {label: '&pound; GB Pounds', flag: 'http://static.fxhome.com/images/flagUK.gif'},
		EUR: {label: '&euro; EU Euros', flag: 'http://static.fxhome.com/images/flagEuro.gif'}
	};

	$(document).ready(function() {
		$('.currencySelector').each(function() {
			var $currSel = $(this);
			$activeCurrency = $currSel.find('a.activeCurrency');
			$currencyList = $currSel.find('ul.currencyList');

			$activeCurrency.click(function(e) {
				e.preventDefault();
				$currencyList.toggle();
			});

			// switch out the currency with the current currency
			var currency = currencyMap[userCurrencyCode] || currencyMap['USD'];
			$activeCurrency.html('<img height="16" width="22" src="' + currency.flag + '" alt=""/> ' + currency.label + ' <small>(change)</small>');
		});
	});

})(jQuery);


/*
 * Turns links with the mediaPopup class into a overlay where the contents are
 * either a flash video player or image based on what the href of the link is.
 */
(function($) {

	$(document).ready(function() {
		var mediaLinks = $('a.mediaPopup');

		if (mediaLinks.length > 0) {
			$('<div class="overlay" id="mediaPopup" style="display:none;"><div class="box"><a class="close" href="?"><img height="30" width="30" title="close" alt="close" src="http://static.fxhome.com/images/white/overlay/close.png"/></a><div class="content"></div></div><div class="bg"></div></div>').appendTo('body');

			var $overlay = $('#mediaPopup');
			var $overlayContent = $overlay.find('div.content');
			var $overlayBox = $overlay.find('div.box');

			$overlay.find('.close, div.bg').click(function() {
				$overlayContent.empty();
				$overlay.hide();

				return false;
			});

			mediaLinks.click(function() {
				$link = $(this);
				var href = $link.attr('href');

				if (href.match(/\.(flv|f4v)$/i)) {
					// its a video
					$overlayContent.html('<div id="popupVideoPlayer" style="padding-bottom:20px;"><div class="padTsRmBnLm"><p class="alignCenter medium"><span class="alert">Adobe</span> Flash is required to play this embedded movie. <a href="http://www.macromedia.com/go/getflashplayer" class="minib">Get Flash now!</a></p></div></div>');
					$overlay.show();

					// now use swfobject to replace the video
					var swfobj = new SWFObject("/media-player.swf","player","600","360","9");
					swfobj.addParam("allowfullscreen","true");
					swfobj.addParam("wmode","opaque");
					swfobj.addVariable("autostart","true");
					swfobj.addVariable("file",href);
					swfobj.addVariable("displayheight","340");
					swfobj.addVariable("backcolor","0x212121");
					swfobj.addVariable("lightcolor","0x4b7dff");
					swfobj.addVariable("frontcolor","0xCCCCCC");
					swfobj.addVariable("bufferlength","5");
					swfobj.write("popupVideoPlayer");

					// resize the window appropriately
					$overlayBox.css({
						height: '360px',
						width: '600px',
						marginLeft: '-301px'
					});
					$overlayContent.css({
						height: 'auto',
						width: '600px',
						maxHeight: '400px'
					});
				}
				else if(href.match(/\.(gif|jpg|png)$/i)) {
					$overlayContent.html('<div class="padTsRmBsLm"><p class="alignCenter"><br/><img src="http://static.fxhome.com/images/ajax-loader.gif" width="16" height="16" alt="loading image" /></p></div>');

					var img = new Image();
					img.onload = function() {
						// its an image
						$overlayContent.html('<img src="'+href+'" alt="'+$link.text()+'" />');
						$overlayBox.css({
							height: img.height+'px',
							width: img.width+'px',
							marginLeft: '-'+((img.width / 2)+1)+'px'
						});
						$overlayContent.css({
							height: img.height+'px',
							width: img.width+'px',
							maxHeight: 'none'
						});
					}
					img.onerror = function () {
						$overlayContent.html('<div class="padTsRmBsLm"><p class="alignCenter hilight">Sorry... we could not find a bigger version of the image you clicked on.</p></div>');
						$overlayBox.css({
							height: 'auto',
							width: '600px',
							marginLeft: '-301px'
						});
						$overlayContent.css({
							height: 'auto',
							width: '600px',
							maxHeight: 'none'
						});
					}
					img.src = href;

					$overlay.show();
				}

				return false;
			});
		}
	});

})(jQuery);

/*
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
 * 
 * Version: 1.3.4 (11/11/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);

(function($) {
	
	$.fn.fxGallery = function(opts) {
		opts = $.extend({}, $.fn.fxGallery.defaults, opts);

		return this.each(function() {
			var gallery = {
				opts: opts,
				el: $(this),
				items: $(this).find('.' + opts.galleryItemsClass),
				itemNav: null,
				itemCount: $(this).find('.' + opts.galleryItemsClass).children().length || 0,
				currentItem: null,
				selectedItemIndex: opts.initialItemIndex || 1,
				autoAdvanceTimeout: null,

				init: function() {
					var that = this;

					// if there is only one item then whats the point in gallerifying it :)
					if (this.itemCount < 2) {
						return;
					}
					
					this.el.width(this.opts.itemWidth + 'px');
					this.items.width((this.opts.itemWidth * this.itemCount) + 'px');
					this.items.children().each(function() {
						$(this).width(that.opts.itemWidth + 'px');
					});

					this.el.height(this.opts.itemHeight + 'px');

					// lets add the next nav btn
					if (this.opts.nextBtn === true) {
						$('<a class="' + this.opts.nextBtnClass + '" href="#">Next</a>').appendTo(this.el).click(function(e) {
							e.preventDefault();
							that.moveToNext();
							that.stopAutoAdvancer();
						});
					}

					// lets add the prev btn
					if (this.opts.prevBtn === true) {
						$('<a class="' + this.opts.prevBtnClass + '" href="#">Prev</a>').prependTo(this.el).click(function(e) {
							e.preventDefault();
							that.moveToPrev();
							that.stopAutoAdvancer();
						});
					}

					// lets add the item nav
					if (this.opts.itemNav === true) {
						var itemNavHtml = '<ul class="' + this.opts.itemNavClass + '">'
						for (var i = 1; i <= this.itemCount; i++) {
							itemNavHtml += '<li><a href="#">' + i + '</a></li>';
						}
						itemNavHtml += '</ul>';

						this.itemNav = $(itemNavHtml);
						this.itemNav.find('a').click(function(e) {
							e.preventDefault()
							var index = parseInt($(this).text());
							if (index) {
								that.moveToItem(index);
							}
							
							that.stopAutoAdvancer();
						});
						this.el.append(this.itemNav);

						// adds half the element with as a negative left margin allowing it
						// to be horizontally centered
						if (this.opts.navAnchorCenter === true) {
							var navWidth = parseInt(this.itemNav.width()) || 0;

							if (navWidth > 0) {
								this.itemNav.css({
									marginLeft: '-' + Math.floor(navWidth / 2) + 'px'
								});
							}
						}
					}

					this.showCurrentSlide();
					this.startAutoAdvancer();
				},

				startAutoAdvancer: function() {
					var that = this;

					if (this.opts.autoAdvance === false) {
						return;
					}

					this.autoAdvanceTimeout = window.setInterval(function() {
						that.moveToNext();
					}, this.opts.autoAdvanceDuration);
				},

				stopAutoAdvancer: function() {
					window.clearTimeout(this.autoAdvanceTimeout);
				},

				showCurrentSlide: function() {
					var newOffset = '-' + (this.opts.itemWidth * (this.selectedItemIndex - 1)) + 'px';

					if (this.opts.animated == true) {
						this.items.stop().animate({left: newOffset}, this.opts.animationDuration);
					}
					else {
						this.items.css({left: newOffset});
					}

					if (opts.itemNav) {
						this.itemNav.find('li').removeClass('selected');
						this.itemNav.find('li:nth-child(' + this.selectedItemIndex + ')').addClass('selected');
					}

					this.currentItem = this.items.children().removeClass('selected');
					this.currentItem = this.items.children(':nth-child(' + this.selectedItemIndex + ')').addClass('selected');

					if (this.opts.itemHeight === 'auto') {
						this.el.height(this.currentItem.height() + 'px');
					}
				},

				moveToNext: function() {
					if (this.selectedItemIndex === this.itemCount) {
						this.selectedItemIndex = 1;
					}
					else {
						this.selectedItemIndex++;
					}

					this.showCurrentSlide();
				},

				moveToPrev: function() {
					if (this.selectedItemIndex === 1) {
						this.selectedItemIndex = this.itemCount;
					}
					else {
						this.selectedItemIndex--;
					}

					this.showCurrentSlide();
				},

				moveToItem: function(index) {
					if (index < 1 || index > this.itemCount) {
						return;
					}

					this.selectedItemIndex = index;
					this.showCurrentSlide();

					this.stopAutoAdvancer();
				}
			};

			gallery.init();
		});
	}

	$.fn.fxGallery.defaults = {
		galleryItemsClass: 'gallery-items',
		nextBtnClass: 'gallery-next-btn',
		prevBtnClass: 'gallery-prev-btn',
		itemNavClass: 'gallery-nav',
		itemNavItemClass: 'gallery-nav-item',
		itemNavItemSelectedClass: 'gallery-nav-item-selected',
		animated: true,
		animationDuration:250,
		nextBtn:false,
		prevBtn:false,
		itemNav:true,
		itemWidth:940,
		itemHeight:510,
		initialItemIndex:1,
		// adds half the element with as a negative left margin allowing it
		// to be horizontally centered
		navAnchorCenter:true,
		autoAdvance:false,
		autoAdvanceDuration:7000
	};

})(jQuery);

(function($) {
				
	/**
	 * Adds disclosure (aka show/hide) behaviour to a activation element and piece of content.
	 * When the activation element is clicked the matching element with the href is toggled
	 * open and close.
	 */
	$.fn.fxDisclosure = function(opts) {
		var settings = $.extend({}, $.fn.fxDisclosure.defaults, opts);
		
		return this.each(function() {
			var activator = $(this);
			var contentSelector = activator.attr('href');
			if (contentSelector.charAt(0) !== '#' || contentSelector.length < 2) {
				return;
			}
			var content = $(contentSelector);
	
			if (settings.initiallyClosed === true) {
				content.hide();
			}
			
			activator.bind('click', function(evt) {
				evt.preventDefault();
	
				if (content.is(':visible')) {
					if (settings.animated === true) {
						content.stop().slideUp(settings.animationSpeed);
					}
					else {
						content.hide();
					}
					
					activator.removeClass(settings.activatorOpenClass);
					activator.addClass(settings.activatorClosedClass);
					content.removeClass(settings.contentOpenClass);
					content.addClass(settings.contentClosedClass);
				}
				else {
					if (settings.animated === true) {
						content.stop().slideDown(settings.animationSpeed);
					}
					else {
						content.show();
					}
					
					activator.addClass(settings.activatorOpenClass);
					activator.removeClass(settings.activatorClosedClass);
					content.addClass(settings.contentOpenClass);
					content.removeClass(settings.contentClosedClass);
				}
			});
		});
	};
	
	$.fn.fxDisclosure.defaults = {
		activatorOpenClass: 'disclosure-activator-open',
		activatorClosedClass: 'disclosure-activator-closed',
		contentOpenClass: 'disclosure-content-open',
		contentClosedClass: 'disclosure-content-closed',
		animated: true,
		animationSpeed: 250,
		initiallyClosed: true
	};

})(jQuery);

/**
 * Adds a bahaviour to images where it swipes showing you the before/after and allows
 * the user to control the swipe to inspect parts of the image.
 */
(function($) {
	
	$.fn.fxBeforeAfter = function(opts) {
		var opts = $.extend({}, $.fn.fxBeforeAfter.defaultOpts, opts);
		
		return $(this).each(function() {
			var $container = $(this);
			if ($container.children().length < 2) {
				// we can only do the before/after thing if there are two elements
				return;
			}
			
			var $before = $container.children('.before');
			var $after = $container.children('.after');
			
			var containerHeight = Math.max($before.height(), $after.height());
			var containerWidth = Math.max($before.width(), $after.width());
			
			$container.css({
				display:'block',
				position:'relative',
				width: containerWidth + 'px',
				height: containerHeight + 'px',
			});
			
			$before.css({
				display:'block',
				position:'absolute',
				zIndex:1,
				left:0,
				top:0,
				width: containerWidth + 'px',
				height: containerHeight + 'px',
				overflow: 'hidden'
			});
			
			$after.css({
				display:'block',
				position:'absolute',
				zIndex:2,
				left:0,
				top:0,
				width: Math.floor(containerWidth / 2) + 'px',
				height: containerHeight + 'px',
				overflow: 'hidden'
			});
			
			var timer = null;
			var paused = false;
			var fps = 40;
			var frameInterval = 1000 / fps;
			var inc = containerWidth / (opts.duration / frameInterval);
			function start()
			{
				if (opts.animated === false) {
					return
				}
				
				paused = false;
				timer = setInterval(function() {
					var currentWidth = parseInt($after.css('width')) || 0;
					if (!paused) {
						if (currentWidth >= containerWidth - Math.abs(inc)) {
							inc = -Math.abs(inc);
						}
						else if (currentWidth <= Math.abs(inc)) {
							inc = Math.abs(inc);
						}
						
						currentWidth += inc;
						$after.css({width: currentWidth + 'px'});
					}
				}, frameInterval);
			}
			
			function stop()
			{
				paused = false;
				window.clearInterval(timer);
			}
			
			function pause()
			{
				paused = true;
			}
			
			function resume()
			{
				paused = false;
			}
			
			start();
			
			if (opts.followMouse === true) {
				$container.mousemove(function(evt) {
					var xMouse = evt.pageX;
					var containerX = parseInt($(this).offset().left) || 0; 
					$after.width((xMouse - containerX) + 'px');
				});
				
				if (opts.animated === true) {
					$container.mouseenter(function(evt) {
						pause();
					});
					
					$container.mouseleave(function(evt) {
						// restart the animator
						resume();
					});
				}
			}
		});
	};
	
	$.fn.fxBeforeAfter.defaultOpts = {
		duration: 3000,
		animated: true,
		followMouse: true
	};
})(jQuery);

/**
 * Turns a element with a list of links to effects into a examples gallery which
 * can be navigated through by the user and will also autoplay to bring the page
 * alive initially inviting the user to investigate the examples.
 */
(function($) {
	$.fn.fxExampleGallery = function(opts) {
		var settings = $.extend({}, $.fn.fxExampleGallery.defaults, opts);
       
		return this.each(function() {
			var container = $(this);

			// add the preview canvas html
			var canvasHTML = '<div class="' + settings.previewCanvasClass + '" style="overflow:hidden; background-image:url(' + settings.previewImage + '); width:' + settings.previewWidth + 'px; height:' + settings.previewHeight + 'px;">';
			canvasHTML += '<div class="' + settings.previewClass + '" style="overflow:hidden; width:' + settings.previewWidth + 'px; height:' + settings.previewHeight + 'px;">';
			canvasHTML += '<img src="' + settings.previewImage + '" width="' + settings.previewWidth + '" height="' + settings.previewHeight + '"/>';
			canvasHTML += '</div>';
			canvasHTML += '</div>';
			container.append(canvasHTML);

			// fetch a bunch of references to the key parts of the UI we just contructed
			var previewCanvas = container.find('.' + settings.previewCanvasClass);
			var previewElement = previewCanvas.find('.' + settings.previewClass);
			var previewElementImg = previewElement.find('img');
			var exampleAnchors = container.find('a');

			var autoPlayTimer = null;
			var autoPlayPaused = false;

			// switch the classes out so we can give a nice experience for js and non-js
			container.removeClass(settings.nojsClass);
			container.addClass(settings.jsClass);

			container.find('> ul').css('height', settings.previewHeight + 'px');

			function showExample(exampleAnchor)
			{
				var previewImgURL = exampleAnchor.attr('href') || '';

				exampleAnchors.parent().removeClass('selected');

				if (settings.swipe === true) {
					previewElement.css('width', 0);
				}
				else {
					previewElement.hide();
				}

				// now we load the image
				var img = new Image();
				img.src = previewImgURL;
				img.onload = function() {
					previewElementImg.attr('src', previewImgURL);

					if (settings.swipe === true) {
						previewElement.stop().animate({width:settings.previewWidth + 'px'}, settings.swipeDuration);
					}
					else {
						previewElement.show();
					}

					exampleAnchor.parent().addClass('selected');
				}
			}

			// add the apply behaviour
			exampleAnchors.click(function(evt) {
				evt.preventDefault();

				var el = $(this);
				showExample(el);

				window.clearInterval(autoPlayTimer);
			});

			// add the hover before/after behaviour
			if (settings.swipe === true) {
				previewCanvas.mousemove(function(evt) {
					autoPlayPaused = true;
					var xMouse = evt.pageX;
					var containerX = parseInt($(this).offset().left) || 0;
					previewElement.stop().width((xMouse - containerX) + 'px');
				});
				previewCanvas.mouseout(function() {
					autoPlayPaused = false;
					previewElement.animate({width:settings.previewWidth + 'px'}, settings.swipeDuration);
				});
			}

			// add the autoplay behaviour
			if (settings.autoPlay === true) {
				var currentElementIndex = 0;
				autoPlayTimer = window.setInterval(
					function() {
						if (autoPlayPaused === true) {
							return;
						}

						if (currentElementIndex === exampleAnchors.length) {
							currentElementIndex = 0;
						}

						var currentExampleAnchor = container.find('a:eq(' + currentElementIndex + ')');
						showExample(currentExampleAnchor);

						// is there a scroll offset set in the itemScrollOffsetMap
						if (settings.itemScrollOffsetMap[currentElementIndex]) {
							container.find('> ul').scrollTop(settings.itemScrollOffsetMap[currentElementIndex]);
						}

						currentElementIndex++;
					},
					settings.autoPlayDuration
				);
			}

			// show the first image immediately
			showExample(container.find('a:eq(0)'));
		});
	};
	$.fn.fxExampleGallery.defaults = {
		jsClass: 'examples-js',
		nojsClass: 'examples-nojs',
		listClass: 'examples-list',
		previewCanvasClass: 'canvas',
		previewClass:'preview',
		previewImage: '',
		previewWidth:700,
		previewHeight:300,
		autoPlay:true,
		autoPlayDuration:3000,
		swipe:true, // the before/after effect
		swipeDuration:500,
		// here you put "itemIndex: scrollValue," pairs to determine how far down to scroll when you hit that element
		itemScrollOffsetMap:{}
	};
})(jQuery);


/**
 * Will make a layer builder widget when it reveals (via slide animation) one layer on top
 * of the previous until it gets to the final slide where it then provides a replay button.
 *
 * Usage:
 *
 * <div id="builder" class="fxbuilder">
 * 	<div class="fxlayer"><div class="fxlayer-content">Content</div></div>
 *	<div class="fxlayer"><div class="fxlayer-content">Content</div></div>
 *	<div class="fxlayer"><div class="fxlayer-content">Content</div></div>
 * </div>
 *
 * $('#builder').fxBuilder();
 */
(function($) {
	$.fn.fxLayerBuilder = function(opts) {
		opts = $.extend({}, $.fn.fxLayerBuilder.defaults, opts);
		
		this.each(function() {
			var canvas = $(this);
			var layers = canvas.children();
			var layersContents = layers.children();
			var autoPlayInterval;
			var layersShown = 0;
			var layerCount = layers.length;
			
			// build replay control
			var replayBtn = $('<a href="#" class="' + opts.replayBtnClass + '">Replay</a>');
			replayBtn.css({'z-index': layerCount + 1});
			replayBtn.appendTo(canvas);
			replayBtn.click(function(evt) {
				evt.preventDefault();
				stopAutoPlay();
				startAutoPlay();
			});
			
			// layout
			canvas.css({
				'position': 'relative',
				'width': opts.layerWidth+'px', 
				'height': opts.layerHeight+'px'
			});
			layers.each(function(index) {
				$(this).css({
					'position': 'absolute', 
					'left': 0, 
					'top': 0, 
					'overflow': 'hidden',
					'z-index': index
				});
			});
			layersContents.css({
				'width': opts.layerWidth+'px', 
				'height': opts.layerHeight+'px'
			});
						
			function showNextLayer()
			{
				if (layersShown >= layerCount) {
					stopAutoPlay();
					replayBtn.show();
				}
								
				$(layers[layersShown]).stop().animate(
					{
						'width': opts.layerWidth+'px'
					}, 
					opts.layerTransitionDuration
				);
				
				layersShown++;
			}
			
			function startAutoPlay()
			{
				layersShown = 0;
				layers.css({width:0});
				replayBtn.hide();
				showNextLayer();
				autoPlayInterval = window.setInterval(showNextLayer, opts.layerIntervalDuration);
			}
			
			function stopAutoPlay()
			{
				window.clearInterval(autoPlayInterval);
			}
			
			// setup auto play after pre-loading all image content
			preload(
				layers.find('img').map(function() {
					return $(this).attr('src');
				}).get(),
				startAutoPlay
			);
		});
	};
	
	$.fn.fxLayerBuilder.defaults = {
		layerWidth: 960,
		layerHeight: 480,
		layerIntervalDuration: 3000, 
		layerTransitionDuration: 250,
		replayBtnClass: 'fxlayerbuilder-replaybtn'
	};
	
	/**
	 * Given an array of images will preload all of them and invoke loadedCb
	 * once all of the images have been loaded.
	 */
	function preload(imgArr, loadedCb) 
	{		
		var total = imgArr.length;
		var loaded = 0;
		
		for(var i in imgArr) {
			$("<img />").attr("src", imgArr[i]).load(function() {
				loaded++;
				if(loaded == total) {
					loadedCb(loaded, total);
				}
			});
		}	
	}
})(jQuery);

/**
 * Custom jquery plugin to enable smooth, animated scrolling on anchor links.
 */
(function($) {
	$.fn.smoothScrollToAnchor = function(opts) {
		var settings = $.extend({offset: 40, duration:250}, opts);
		return $(this).each(function() {
			$(this).click(function(evt) {
				evt.preventDefault();
				var el = $(this);
				var elHref = el.attr("href");
				if (elHref.charAt(0) == '#') {
					var destination = $(elHref).offset().top;
					if (destination) {
						$('html, body').stop().animate({ scrollTop: destination - settings.offset}, settings.duration);
					}
				}
			});
		});
	};
})(jQuery);
// setup fancybox
(function($) {
	$(document).ready(function() {
		if ('fancybox' in $) {
			$('.lightbox-photo').fancybox({
				padding:0,
				overlayOpacity:0.9,
				overlayColor:'#333'
			});
		}
	});
})(jQuery);
