/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright Â© 2008 George McGinley Smith
 * All rights reserved.
*/
jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInCubic:function(e,f,a,h,g){return h*(f/=g)*f*f+a},easeOutCubic:function(e,f,a,h,g){return h*((f=f/g-1)*f*f+1)+a},easeInOutCubic:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f+a}return h/2*((f-=2)*f*f+2)+a},easeInQuart:function(e,f,a,h,g){return h*(f/=g)*f*f*f+a},easeOutQuart:function(e,f,a,h,g){return -h*((f=f/g-1)*f*f*f-1)+a},easeInOutQuart:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f+a}return -h/2*((f-=2)*f*f*f-2)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInSine:function(e,f,a,h,g){return -h*Math.cos(f/g*(Math.PI/2))+h+a},easeOutSine:function(e,f,a,h,g){return h*Math.sin(f/g*(Math.PI/2))+a},easeInOutSine:function(e,f,a,h,g){return -h/2*(Math.cos(Math.PI*f/g)-1)+a},easeInExpo:function(e,f,a,h,g){return(f==0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f==0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInCirc:function(e,f,a,h,g){return -h*(Math.sqrt(1-(f/=g)*f)-1)+a},easeOutCirc:function(e,f,a,h,g){return h*Math.sqrt(1-(f=f/g-1)*f)+a},easeInOutCirc:function(e,f,a,h,g){if((f/=g/2)<1){return -h/2*(Math.sqrt(1-f*f)-1)+a}return h/2*(Math.sqrt(1-(f-=2)*f)+1)+a},easeInElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return -(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e},easeOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k)==1){return e+l}if(!j){j=k*0.3}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}return g*Math.pow(2,-10*h)*Math.sin((h*k-i)*(2*Math.PI)/j)+l+e},easeInOutElastic:function(f,h,e,l,k){var i=1.70158;var j=0;var g=l;if(h==0){return e}if((h/=k/2)==2){return e+l}if(!j){j=k*(0.3*1.5)}if(g<Math.abs(l)){g=l;var i=j/4}else{var i=j/(2*Math.PI)*Math.asin(l/g)}if(h<1){return -0.5*(g*Math.pow(2,10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j))+e}return g*Math.pow(2,-10*(h-=1))*Math.sin((h*k-i)*(2*Math.PI)/j)*0.5+l+e},easeInBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*(f/=h)*f*((g+1)*f-g)+a},easeOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}return i*((f=f/h-1)*f*((g+1)*f+g)+1)+a},easeInOutBack:function(e,f,a,i,h,g){if(g==undefined){g=1.70158}if((f/=h/2)<1){return i/2*(f*f*(((g*=(1.525))+1)*f-g))+a}return i/2*((f-=2)*f*(((g*=(1.525))+1)*f+g)+2)+a},easeInBounce:function(e,f,a,h,g){return h-jQuery.easing.easeOutBounce(e,g-f,0,h,g)+a},easeOutBounce:function(e,f,a,h,g){if((f/=g)<(1/2.75)){return h*(7.5625*f*f)+a}else{if(f<(2/2.75)){return h*(7.5625*(f-=(1.5/2.75))*f+0.75)+a}else{if(f<(2.5/2.75)){return h*(7.5625*(f-=(2.25/2.75))*f+0.9375)+a}else{return h*(7.5625*(f-=(2.625/2.75))*f+0.984375)+a}}}},easeInOutBounce:function(e,f,a,h,g){if(f<g/2){return jQuery.easing.easeInBounce(e,f*2,0,h,g)*0.5+a}return jQuery.easing.easeOutBounce(e,f*2-g,0,h,g)*0.5+h*0.5+a}});

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};

/*  SWFObject v2.2 <http://code.google.com/p/swfobject/> 
    is released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/
var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="ShockwaveFlash.ShockwaveFlash",q="application/x-shockwave-flash",R="SWFObjectExprInst",x="onreadystatechange",O=window,j=document,t=navigator,T=false,U=[h],o=[],N=[],I=[],l,Q,E,B,J=false,a=false,n,G,m=true,M=function(){var aa=typeof j.getElementById!=D&&typeof j.getElementsByTagName!=D&&typeof j.createElement!=D,ah=t.userAgent.toLowerCase(),Y=t.platform.toLowerCase(),ae=Y?/win/.test(Y):/win/.test(ah),ac=Y?/mac/.test(Y):/mac/.test(ah),af=/webkit/.test(ah)?parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):false,X=!+"\v1",ag=[0,0,0],ab=null;if(typeof t.plugins!=D&&typeof t.plugins[S]==r){ab=t.plugins[S].description;if(ab&&!(typeof t.mimeTypes!=D&&t.mimeTypes[q]&&!t.mimeTypes[q].enabledPlugin)){T=true;X=false;ab=ab.replace(/^.*\s+(\S+\s+\S+$)/,"$1");ag[0]=parseInt(ab.replace(/^(.*)\..*$/,"$1"),10);ag[1]=parseInt(ab.replace(/^.*\.(.*)\s.*$/,"$1"),10);ag[2]=/[a-zA-Z]/.test(ab)?parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0}}else{if(typeof O.ActiveXObject!=D){try{var ad=new ActiveXObject(W);if(ad){ab=ad.GetVariable("$version");if(ab){X=true;ab=ab.split(" ")[1].split(",");ag=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}}catch(Z){}}}return{w3:aa,pv:ag,wk:af,ie:X,win:ae,mac:ac}}(),k=function(){if(!M.w3){return}if((typeof j.readyState!=D&&j.readyState=="complete")||(typeof j.readyState==D&&(j.getElementsByTagName("body")[0]||j.body))){f()}if(!J){if(typeof j.addEventListener!=D){j.addEventListener("DOMContentLoaded",f,false)}if(M.ie&&M.win){j.attachEvent(x,function(){if(j.readyState=="complete"){j.detachEvent(x,arguments.callee);f()}});if(O==top){(function(){if(J){return}try{j.documentElement.doScroll("left")}catch(X){setTimeout(arguments.callee,0);return}f()})()}}if(M.wk){(function(){if(J){return}if(!/loaded|complete/.test(j.readyState)){setTimeout(arguments.callee,0);return}f()})()}s(f)}}();function f(){if(J){return}try{var Z=j.getElementsByTagName("body")[0].appendChild(C("span"));Z.parentNode.removeChild(Z)}catch(aa){return}J=true;var X=U.length;for(var Y=0;Y<X;Y++){U[Y]()}}function K(X){if(J){X()}else{U[U.length]=X}}function s(Y){if(typeof O.addEventListener!=D){O.addEventListener("load",Y,false)}else{if(typeof j.addEventListener!=D){j.addEventListener("load",Y,false)}else{if(typeof O.attachEvent!=D){i(O,"onload",Y)}else{if(typeof O.onload=="function"){var X=O.onload;O.onload=function(){X();Y()}}else{O.onload=Y}}}}}function h(){if(T){V()}else{H()}}function V(){var X=j.getElementsByTagName("body")[0];var aa=C(r);aa.setAttribute("type",q);var Z=X.appendChild(aa);if(Z){var Y=0;(function(){if(typeof Z.GetVariable!=D){var ab=Z.GetVariable("$version");if(ab){ab=ab.split(" ")[1].split(",");M.pv=[parseInt(ab[0],10),parseInt(ab[1],10),parseInt(ab[2],10)]}}else{if(Y<10){Y++;setTimeout(arguments.callee,10);return}}X.removeChild(aa);Z=null;H()})()}else{H()}}function H(){var ag=o.length;if(ag>0){for(var af=0;af<ag;af++){var Y=o[af].id;var ab=o[af].callbackFn;var aa={success:false,id:Y};if(M.pv[0]>0){var ae=c(Y);if(ae){if(F(o[af].swfVersion)&&!(M.wk&&M.wk<312)){w(Y,true);if(ab){aa.success=true;aa.ref=z(Y);ab(aa)}}else{if(o[af].expressInstall&&A()){var ai={};ai.data=o[af].expressInstall;ai.width=ae.getAttribute("width")||"0";ai.height=ae.getAttribute("height")||"0";if(ae.getAttribute("class")){ai.styleclass=ae.getAttribute("class")}if(ae.getAttribute("align")){ai.align=ae.getAttribute("align")}var ah={};var X=ae.getElementsByTagName("param");var ac=X.length;for(var ad=0;ad<ac;ad++){if(X[ad].getAttribute("name").toLowerCase()!="movie"){ah[X[ad].getAttribute("name")]=X[ad].getAttribute("value")}}P(ai,ah,Y,ab)}else{p(ae);if(ab){ab(aa)}}}}}else{w(Y,true);if(ab){var Z=z(Y);if(Z&&typeof Z.SetVariable!=D){aa.success=true;aa.ref=Z}ab(aa)}}}}}function z(aa){var X=null;var Y=c(aa);if(Y&&Y.nodeName=="OBJECT"){if(typeof Y.SetVariable!=D){X=Y}else{var Z=Y.getElementsByTagName(r)[0];if(Z){X=Z}}}return X}function A(){return !a&&F("6.0.65")&&(M.win||M.mac)&&!(M.wk&&M.wk<312)}function P(aa,ab,X,Z){a=true;E=Z||null;B={success:false,id:X};var ae=c(X);if(ae){if(ae.nodeName=="OBJECT"){l=g(ae);Q=null}else{l=ae;Q=X}aa.id=R;if(typeof aa.width==D||(!/%$/.test(aa.width)&&parseInt(aa.width,10)<310)){aa.width="310"}if(typeof aa.height==D||(!/%$/.test(aa.height)&&parseInt(aa.height,10)<137)){aa.height="137"}j.title=j.title.slice(0,47)+" - Flash Player Installation";var ad=M.ie&&M.win?"ActiveX":"PlugIn",ac="MMredirectURL="+O.location.toString().replace(/&/g,"%26")+"&MMplayerType="+ad+"&MMdoctitle="+j.title;if(typeof ab.flashvars!=D){ab.flashvars+="&"+ac}else{ab.flashvars=ac}if(M.ie&&M.win&&ae.readyState!=4){var Y=C("div");X+="SWFObjectNew";Y.setAttribute("id",X);ae.parentNode.insertBefore(Y,ae);ae.style.display="none";(function(){if(ae.readyState==4){ae.parentNode.removeChild(ae)}else{setTimeout(arguments.callee,10)}})()}u(aa,ab,X)}}function p(Y){if(M.ie&&M.win&&Y.readyState!=4){var X=C("div");Y.parentNode.insertBefore(X,Y);X.parentNode.replaceChild(g(Y),X);Y.style.display="none";(function(){if(Y.readyState==4){Y.parentNode.removeChild(Y)}else{setTimeout(arguments.callee,10)}})()}else{Y.parentNode.replaceChild(g(Y),Y)}}function g(ab){var aa=C("div");if(M.win&&M.ie){aa.innerHTML=ab.innerHTML}else{var Y=ab.getElementsByTagName(r)[0];if(Y){var ad=Y.childNodes;if(ad){var X=ad.length;for(var Z=0;Z<X;Z++){if(!(ad[Z].nodeType==1&&ad[Z].nodeName=="PARAM")&&!(ad[Z].nodeType==8)){aa.appendChild(ad[Z].cloneNode(true))}}}}}return aa}function u(ai,ag,Y){var X,aa=c(Y);if(M.wk&&M.wk<312){return X}if(aa){if(typeof ai.id==D){ai.id=Y}if(M.ie&&M.win){var ah="";for(var ae in ai){if(ai[ae]!=Object.prototype[ae]){if(ae.toLowerCase()=="data"){ag.movie=ai[ae]}else{if(ae.toLowerCase()=="styleclass"){ah+=' class="'+ai[ae]+'"'}else{if(ae.toLowerCase()!="classid"){ah+=" "+ae+'="'+ai[ae]+'"'}}}}}var af="";for(var ad in ag){if(ag[ad]!=Object.prototype[ad]){af+='<param name="'+ad+'" value="'+ag[ad]+'" />'}}aa.outerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+ah+">"+af+"</object>";N[N.length]=ai.id;X=c(ai.id)}else{var Z=C(r);Z.setAttribute("type",q);for(var ac in ai){if(ai[ac]!=Object.prototype[ac]){if(ac.toLowerCase()=="styleclass"){Z.setAttribute("class",ai[ac])}else{if(ac.toLowerCase()!="classid"){Z.setAttribute(ac,ai[ac])}}}}for(var ab in ag){if(ag[ab]!=Object.prototype[ab]&&ab.toLowerCase()!="movie"){e(Z,ab,ag[ab])}}aa.parentNode.replaceChild(Z,aa);X=Z}}return X}function e(Z,X,Y){var aa=C("param");aa.setAttribute("name",X);aa.setAttribute("value",Y);Z.appendChild(aa)}function y(Y){var X=c(Y);if(X&&X.nodeName=="OBJECT"){if(M.ie&&M.win){X.style.display="none";(function(){if(X.readyState==4){b(Y)}else{setTimeout(arguments.callee,10)}})()}else{X.parentNode.removeChild(X)}}}function b(Z){var Y=c(Z);if(Y){for(var X in Y){if(typeof Y[X]=="function"){Y[X]=null}}Y.parentNode.removeChild(Y)}}function c(Z){var X=null;try{X=j.getElementById(Z)}catch(Y){}return X}function C(X){return j.createElement(X)}function i(Z,X,Y){Z.attachEvent(X,Y);I[I.length]=[Z,X,Y]}function F(Z){var Y=M.pv,X=Z.split(".");X[0]=parseInt(X[0],10);X[1]=parseInt(X[1],10)||0;X[2]=parseInt(X[2],10)||0;return(Y[0]>X[0]||(Y[0]==X[0]&&Y[1]>X[1])||(Y[0]==X[0]&&Y[1]==X[1]&&Y[2]>=X[2]))?true:false}function v(ac,Y,ad,ab){if(M.ie&&M.mac){return}var aa=j.getElementsByTagName("head")[0];if(!aa){return}var X=(ad&&typeof ad=="string")?ad:"screen";if(ab){n=null;G=null}if(!n||G!=X){var Z=C("style");Z.setAttribute("type","text/css");Z.setAttribute("media",X);n=aa.appendChild(Z);if(M.ie&&M.win&&typeof j.styleSheets!=D&&j.styleSheets.length>0){n=j.styleSheets[j.styleSheets.length-1]}G=X}if(M.ie&&M.win){if(n&&typeof n.addRule==r){n.addRule(ac,Y)}}else{if(n&&typeof j.createTextNode!=D){n.appendChild(j.createTextNode(ac+" {"+Y+"}"))}}}function w(Z,X){if(!m){return}var Y=X?"visible":"hidden";if(J&&c(Z)){c(Z).style.visibility=Y}else{v("#"+Z,"visibility:"+Y)}}function L(Y){var Z=/[\\\"<>\.;]/;var X=Z.exec(Y)!=null;return X&&typeof encodeURIComponent!=D?encodeURIComponent(Y):Y}var d=function(){if(M.ie&&M.win){window.attachEvent("onunload",function(){var ac=I.length;for(var ab=0;ab<ac;ab++){I[ab][0].detachEvent(I[ab][1],I[ab][2])}var Z=N.length;for(var aa=0;aa<Z;aa++){y(N[aa])}for(var Y in M){M[Y]=null}M=null;for(var X in swfobject){swfobject[X]=null}swfobject=null})}}();return{registerObject:function(ab,X,aa,Z){if(M.w3&&ab&&X){var Y={};Y.id=ab;Y.swfVersion=X;Y.expressInstall=aa;Y.callbackFn=Z;o[o.length]=Y;w(ab,false)}else{if(Z){Z({success:false,id:ab})}}},getObjectById:function(X){if(M.w3){return z(X)}},embedSWF:function(ab,ah,ae,ag,Y,aa,Z,ad,af,ac){var X={success:false,id:ah};if(M.w3&&!(M.wk&&M.wk<312)&&ab&&ah&&ae&&ag&&Y){w(ah,false);K(function(){ae+="";ag+="";var aj={};if(af&&typeof af===r){for(var al in af){aj[al]=af[al]}}aj.data=ab;aj.width=ae;aj.height=ag;var am={};if(ad&&typeof ad===r){for(var ak in ad){am[ak]=ad[ak]}}if(Z&&typeof Z===r){for(var ai in Z){if(typeof am.flashvars!=D){am.flashvars+="&"+ai+"="+Z[ai]}else{am.flashvars=ai+"="+Z[ai]}}}if(F(Y)){var an=u(aj,am,ah);if(aj.id==ah){w(ah,true)}X.success=true;X.ref=an}else{if(aa&&A()){aj.data=aa;P(aj,am,ah,ac);return}else{w(ah,true)}}if(ac){ac(X)}})}else{if(ac){ac(X)}}},switchOffAutoHideShow:function(){m=false},ua:M,getFlashPlayerVersion:function(){return{major:M.pv[0],minor:M.pv[1],release:M.pv[2]}},hasFlashPlayerVersion:F,createSWF:function(Z,Y,X){if(M.w3){return u(Z,Y,X)}else{return undefined}},showExpressInstall:function(Z,aa,X,Y){if(M.w3&&A()){P(Z,aa,X,Y)}},removeSWF:function(X){if(M.w3){y(X)}},createCSS:function(aa,Z,Y,X){if(M.w3){v(aa,Z,Y,X)}},addDomLoadEvent:K,addLoadEvent:s,getQueryParamValue:function(aa){var Z=j.location.search||j.location.hash;if(Z){if(/\?/.test(Z)){Z=Z.split("?")[1]}if(aa==null){return L(Z)}var Y=Z.split("&");for(var X=0;X<Y.length;X++){if(Y[X].substring(0,Y[X].indexOf("="))==aa){return L(Y[X].substring((Y[X].indexOf("=")+1)))}}}return""},expressInstallCallback:function(){if(a){var X=c(R);if(X&&l){X.parentNode.replaceChild(l,X);if(Q){w(Q,true);if(M.ie&&M.win){l.style.display="block"}}if(E){E(B)}}a=false}}}}();

/*
 * jQuery UI 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */
jQuery.ui||(function(c){var i=c.fn.remove,d=c.browser.mozilla&&(parseFloat(c.browser.version)<1.9);c.ui={version:"1.7.2",plugin:{add:function(k,l,n){var m=c.ui[k].prototype;for(var j in n){m.plugins[j]=m.plugins[j]||[];m.plugins[j].push([l,n[j]])}},call:function(j,l,k){var n=j.plugins[l];if(!n||!j.element[0].parentNode){return}for(var m=0;m<n.length;m++){if(j.options[n[m][0]]){n[m][1].apply(j.element,k)}}}},contains:function(k,j){return document.compareDocumentPosition?k.compareDocumentPosition(j)&16:k!==j&&k.contains(j)},hasScroll:function(m,k){if(c(m).css("overflow")=="hidden"){return false}var j=(k&&k=="left")?"scrollLeft":"scrollTop",l=false;if(m[j]>0){return true}m[j]=1;l=(m[j]>0);m[j]=0;return l},isOverAxis:function(k,j,l){return(k>j)&&(k<(j+l))},isOver:function(o,k,n,m,j,l){return c.ui.isOverAxis(o,n,j)&&c.ui.isOverAxis(k,m,l)},keyCode:{BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38}};if(d){var f=c.attr,e=c.fn.removeAttr,h="http://www.w3.org/2005/07/aaa",a=/^aria-/,b=/^wairole:/;c.attr=function(k,j,l){var m=l!==undefined;return(j=="role"?(m?f.call(this,k,j,"wairole:"+l):(f.apply(this,arguments)||"").replace(b,"")):(a.test(j)?(m?k.setAttributeNS(h,j.replace(a,"aaa:"),l):f.call(this,k,j.replace(a,"aaa:"))):f.apply(this,arguments)))};c.fn.removeAttr=function(j){return(a.test(j)?this.each(function(){this.removeAttributeNS(h,j.replace(a,""))}):e.call(this,j))}}c.fn.extend({remove:function(){c("*",this).add(this).each(function(){c(this).triggerHandler("remove")});return i.apply(this,arguments)},enableSelection:function(){return this.attr("unselectable","off").css("MozUserSelect","").unbind("selectstart.ui")},disableSelection:function(){return this.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return false})},scrollParent:function(){var j;if((c.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){j=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(c.curCSS(this,"position",1))&&(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}else{j=this.parents().filter(function(){return(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!j.length?c(document):j}});c.extend(c.expr[":"],{data:function(l,k,j){return !!c.data(l,j[3])},focusable:function(k){var l=k.nodeName.toLowerCase(),j=c.attr(k,"tabindex");return(/input|select|textarea|button|object/.test(l)?!k.disabled:"a"==l||"area"==l?k.href||!isNaN(j):!isNaN(j))&&!c(k)["area"==l?"parents":"closest"](":hidden").length},tabbable:function(k){var j=c.attr(k,"tabindex");return(isNaN(j)||j>=0)&&c(k).is(":focusable")}});function g(m,n,o,l){function k(q){var p=c[m][n][q]||[];return(typeof p=="string"?p.split(/,?\s+/):p)}var j=k("getter");if(l.length==1&&typeof l[0]=="string"){j=j.concat(k("getterSetter"))}return(c.inArray(o,j)!=-1)}c.widget=function(k,j){var l=k.split(".")[0];k=k.split(".")[1];c.fn[k]=function(p){var n=(typeof p=="string"),o=Array.prototype.slice.call(arguments,1);if(n&&p.substring(0,1)=="_"){return this}if(n&&g(l,k,p,o)){var m=c.data(this[0],k);return(m?m[p].apply(m,o):undefined)}return this.each(function(){var q=c.data(this,k);(!q&&!n&&c.data(this,k,new c[l][k](this,p))._init());(q&&n&&c.isFunction(q[p])&&q[p].apply(q,o))})};c[l]=c[l]||{};c[l][k]=function(o,n){var m=this;this.namespace=l;this.widgetName=k;this.widgetEventPrefix=c[l][k].eventPrefix||k;this.widgetBaseClass=l+"-"+k;this.options=c.extend({},c.widget.defaults,c[l][k].defaults,c.metadata&&c.metadata.get(o)[k],n);this.element=c(o).bind("setData."+k,function(q,p,r){if(q.target==o){return m._setData(p,r)}}).bind("getData."+k,function(q,p){if(q.target==o){return m._getData(p)}}).bind("remove",function(){return m.destroy()})};c[l][k].prototype=c.extend({},c.widget.prototype,j);c[l][k].getterSetter="option"};c.widget.prototype={_init:function(){},destroy:function(){this.element.removeData(this.widgetName).removeClass(this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").removeAttr("aria-disabled")},option:function(l,m){var k=l,j=this;if(typeof l=="string"){if(m===undefined){return this._getData(l)}k={};k[l]=m}c.each(k,function(n,o){j._setData(n,o)})},_getData:function(j){return this.options[j]},_setData:function(j,k){this.options[j]=k;if(j=="disabled"){this.element[k?"addClass":"removeClass"](this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").attr("aria-disabled",k)}},enable:function(){this._setData("disabled",false)},disable:function(){this._setData("disabled",true)},_trigger:function(l,m,n){var p=this.options[l],j=(l==this.widgetEventPrefix?l:this.widgetEventPrefix+l);m=c.Event(m);m.type=j;if(m.originalEvent){for(var k=c.event.props.length,o;k;){o=c.event.props[--k];m[o]=m.originalEvent[o]}}this.element.trigger(m,n);return !(c.isFunction(p)&&p.call(this.element[0],m,n)===false||m.isDefaultPrevented())}};c.widget.defaults={disabled:false};c.ui.mouse={_mouseInit:function(){var j=this;this.element.bind("mousedown."+this.widgetName,function(k){return j._mouseDown(k)}).bind("click."+this.widgetName,function(k){if(j._preventClickEvent){j._preventClickEvent=false;k.stopImmediatePropagation();return false}});if(c.browser.msie){this._mouseUnselectable=this.element.attr("unselectable");this.element.attr("unselectable","on")}this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName);(c.browser.msie&&this.element.attr("unselectable",this._mouseUnselectable))},_mouseDown:function(l){l.originalEvent=l.originalEvent||{};if(l.originalEvent.mouseHandled){return}(this._mouseStarted&&this._mouseUp(l));this._mouseDownEvent=l;var k=this,m=(l.which==1),j=(typeof this.options.cancel=="string"?c(l.target).parents().add(l.target).filter(this.options.cancel).length:false);if(!m||j||!this._mouseCapture(l)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){k.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(l)&&this._mouseDelayMet(l)){this._mouseStarted=(this._mouseStart(l)!==false);if(!this._mouseStarted){l.preventDefault();return true}}this._mouseMoveDelegate=function(n){return k._mouseMove(n)};this._mouseUpDelegate=function(n){return k._mouseUp(n)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);(c.browser.safari||l.preventDefault());l.originalEvent.mouseHandled=true;return true},_mouseMove:function(j){if(c.browser.msie&&!j.button){return this._mouseUp(j)}if(this._mouseStarted){this._mouseDrag(j);return j.preventDefault()}if(this._mouseDistanceMet(j)&&this._mouseDelayMet(j)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,j)!==false);(this._mouseStarted?this._mouseDrag(j):this._mouseUp(j))}return !this._mouseStarted},_mouseUp:function(j){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=(j.target==this._mouseDownEvent.target);this._mouseStop(j)}return false},_mouseDistanceMet:function(j){return(Math.max(Math.abs(this._mouseDownEvent.pageX-j.pageX),Math.abs(this._mouseDownEvent.pageY-j.pageY))>=this.options.distance)},_mouseDelayMet:function(j){return this.mouseDelayMet},_mouseStart:function(j){},_mouseDrag:function(j){},_mouseStop:function(j){},_mouseCapture:function(j){return true}};c.ui.mouse.defaults={cancel:null,distance:1,delay:0}})(jQuery);;/*
 
 * jQuery UI Dialog 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Dialog
 *
 * Depends:
 *	ui.core.js
 *	ui.draggable.js
 *	ui.resizable.js
 */

(function(c){var b={dragStart:"start.draggable",drag:"drag.draggable",dragStop:"stop.draggable",maxHeight:"maxHeight.resizable",minHeight:"minHeight.resizable",maxWidth:"maxWidth.resizable",minWidth:"minWidth.resizable",resizeStart:"start.resizable",resize:"drag.resizable",resizeStop:"stop.resizable"},a="ui-dialog ui-widget ui-widget-content ui-corner-all ";c.widget("ui.dialog",{_init:function(){this.originalTitle=this.element.attr("title");var l=this,m=this.options,j=m.title||this.originalTitle||"&nbsp;",e=c.ui.dialog.getTitleId(this.element),k=(this.uiDialog=c("<div/>")).appendTo(document.body).hide().addClass(a+m.dialogClass).css({position:"absolute",overflow:"hidden",zIndex:m.zIndex}).attr("tabIndex",-1).css("outline",0).keydown(function(n){(m.closeOnEscape&&n.keyCode&&n.keyCode==c.ui.keyCode.ESCAPE&&l.close(n))}).attr({role:"dialog","aria-labelledby":e}).mousedown(function(n){l.moveToTop(false,n)}),g=this.element.show().removeAttr("title").addClass("ui-dialog-content ui-widget-content").appendTo(k),f=(this.uiDialogTitlebar=c("<div></div>")).addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix").prependTo(k),i=c('<a href="#"/>').addClass("ui-dialog-titlebar-close ui-corner-all").attr("role","button").hover(function(){i.addClass("ui-state-hover")},function(){i.removeClass("ui-state-hover")}).focus(function(){i.addClass("ui-state-focus")}).blur(function(){i.removeClass("ui-state-focus")}).mousedown(function(n){n.stopPropagation()}).click(function(n){l.close(n);return false}).appendTo(f),h=(this.uiDialogTitlebarCloseText=c("<span/>")).addClass("ui-icon ui-icon-closethick").text(m.closeText).appendTo(i),d=c("<span/>").addClass("ui-dialog-title").attr("id",e).html(j).prependTo(f);f.find("*").add(f).disableSelection();(m.draggable&&c.fn.draggable&&this._makeDraggable());(m.resizable&&c.fn.resizable&&this._makeResizable());this._createButtons(m.buttons);this._isOpen=false;(m.bgiframe&&c.fn.bgiframe&&k.bgiframe());(m.autoOpen&&this.open())},destroy:function(){(this.overlay&&this.overlay.destroy());this.uiDialog.hide();this.element.unbind(".dialog").removeData("dialog").removeClass("ui-dialog-content ui-widget-content").hide().appendTo("body");this.uiDialog.remove();(this.originalTitle&&this.element.attr("title",this.originalTitle))},close:function(f){var d=this;if(false===d._trigger("beforeclose",f)){return}(d.overlay&&d.overlay.destroy());d.uiDialog.unbind("keypress.ui-dialog");(d.options.hide?d.uiDialog.hide(d.options.hide,function(){d._trigger("close",f)}):d.uiDialog.hide()&&d._trigger("close",f));c.ui.dialog.overlay.resize();d._isOpen=false;if(d.options.modal){var e=0;c(".ui-dialog").each(function(){if(this!=d.uiDialog[0]){e=Math.max(e,c(this).css("z-index"))}});c.ui.dialog.maxZ=e}},isOpen:function(){return this._isOpen},moveToTop:function(f,e){if((this.options.modal&&!f)||(!this.options.stack&&!this.options.modal)){return this._trigger("focus",e)}if(this.options.zIndex>c.ui.dialog.maxZ){c.ui.dialog.maxZ=this.options.zIndex}(this.overlay&&this.overlay.$el.css("z-index",c.ui.dialog.overlay.maxZ=++c.ui.dialog.maxZ));var d={scrollTop:this.element.attr("scrollTop"),scrollLeft:this.element.attr("scrollLeft")};this.uiDialog.css("z-index",++c.ui.dialog.maxZ);this.element.attr(d);this._trigger("focus",e)},open:function(){if(this._isOpen){return}var e=this.options,d=this.uiDialog;this.overlay=e.modal?new c.ui.dialog.overlay(this):null;(d.next().length&&d.appendTo("body"));this._size();this._position(e.position);d.show(e.show);this.moveToTop(true);(e.modal&&d.bind("keypress.ui-dialog",function(h){if(h.keyCode!=c.ui.keyCode.TAB){return}var g=c(":tabbable",this),i=g.filter(":first")[0],f=g.filter(":last")[0];if(h.target==f&&!h.shiftKey){setTimeout(function(){i.focus()},1)}else{if(h.target==i&&h.shiftKey){setTimeout(function(){f.focus()},1)}}}));c([]).add(d.find(".ui-dialog-content :tabbable:first")).add(d.find(".ui-dialog-buttonpane :tabbable:first")).add(d).filter(":first").focus();this._trigger("open");this._isOpen=true},_createButtons:function(g){var f=this,d=false,e=c("<div></div>").addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix");this.uiDialog.find(".ui-dialog-buttonpane").remove();(typeof g=="object"&&g!==null&&c.each(g,function(){return !(d=true)}));if(d){c.each(g,function(h,i){c('<button type="button"></button>').addClass("ui-state-default ui-corner-all").text(h).click(function(){i.apply(f.element[0],arguments)}).hover(function(){c(this).addClass("ui-state-hover")},function(){c(this).removeClass("ui-state-hover")}).focus(function(){c(this).addClass("ui-state-focus")}).blur(function(){c(this).removeClass("ui-state-focus")}).appendTo(e)});e.appendTo(this.uiDialog)}},_makeDraggable:function(){var d=this,f=this.options,e;this.uiDialog.draggable({cancel:".ui-dialog-content",handle:".ui-dialog-titlebar",containment:"document",start:function(){e=f.height;c(this).height(c(this).height()).addClass("ui-dialog-dragging");(f.dragStart&&f.dragStart.apply(d.element[0],arguments))},drag:function(){(f.drag&&f.drag.apply(d.element[0],arguments))},stop:function(){c(this).removeClass("ui-dialog-dragging").height(e);(f.dragStop&&f.dragStop.apply(d.element[0],arguments));c.ui.dialog.overlay.resize()}})},_makeResizable:function(g){g=(g===undefined?this.options.resizable:g);var d=this,f=this.options,e=typeof g=="string"?g:"n,e,s,w,se,sw,ne,nw";this.uiDialog.resizable({cancel:".ui-dialog-content",alsoResize:this.element,maxWidth:f.maxWidth,maxHeight:f.maxHeight,minWidth:f.minWidth,minHeight:f.minHeight,start:function(){c(this).addClass("ui-dialog-resizing");(f.resizeStart&&f.resizeStart.apply(d.element[0],arguments))},resize:function(){(f.resize&&f.resize.apply(d.element[0],arguments))},handles:e,stop:function(){c(this).removeClass("ui-dialog-resizing");f.height=c(this).height();f.width=c(this).width();(f.resizeStop&&f.resizeStop.apply(d.element[0],arguments));c.ui.dialog.overlay.resize()}}).find(".ui-resizable-se").addClass("ui-icon ui-icon-grip-diagonal-se")},_position:function(i){var e=c(window),f=c(document),g=f.scrollTop(),d=f.scrollLeft(),h=g;if(c.inArray(i,["center","top","right","bottom","left"])>=0){i=[i=="right"||i=="left"?i:"center",i=="top"||i=="bottom"?i:"middle"]}if(i.constructor!=Array){i=["center","middle"]}if(i[0].constructor==Number){d+=i[0]}else{switch(i[0]){case"left":d+=0;break;case"right":d+=e.width()-this.uiDialog.outerWidth();break;default:case"center":d+=(e.width()-this.uiDialog.outerWidth())/2}}if(i[1].constructor==Number){g+=i[1]}else{switch(i[1]){case"top":g+=0;break;case"bottom":g+=e.height()-this.uiDialog.outerHeight();break;default:case"middle":g+=(e.height()-this.uiDialog.outerHeight())/2}}g=Math.max(g,h);this.uiDialog.css({top:g,left:d})},_setData:function(e,f){(b[e]&&this.uiDialog.data(b[e],f));switch(e){case"buttons":this._createButtons(f);break;case"closeText":this.uiDialogTitlebarCloseText.text(f);break;case"dialogClass":this.uiDialog.removeClass(this.options.dialogClass).addClass(a+f);break;case"draggable":(f?this._makeDraggable():this.uiDialog.draggable("destroy"));break;case"height":this.uiDialog.height(f);break;case"position":this._position(f);break;case"resizable":var d=this.uiDialog,g=this.uiDialog.is(":data(resizable)");(g&&!f&&d.resizable("destroy"));(g&&typeof f=="string"&&d.resizable("option","handles",f));(g||this._makeResizable(f));break;case"title":c(".ui-dialog-title",this.uiDialogTitlebar).html(f||"&nbsp;");break;case"width":this.uiDialog.width(f);break}c.widget.prototype._setData.apply(this,arguments)},_size:function(){var e=this.options;this.element.css({height:0,minHeight:0,width:"auto"});var d=this.uiDialog.css({height:"auto",width:e.width}).height();this.element.css({minHeight:Math.max(e.minHeight-d,0),height:e.height=="auto"?"auto":Math.max(e.height-d,0)})}});c.extend(c.ui.dialog,{version:"1.7.2",defaults:{autoOpen:true,bgiframe:false,buttons:{},closeOnEscape:true,closeText:"close",dialogClass:"",draggable:true,hide:null,height:"auto",maxHeight:false,maxWidth:false,minHeight:150,minWidth:150,modal:false,position:"center",resizable:true,show:null,stack:true,title:"",width:300,zIndex:1000},getter:"isOpen",uuid:0,maxZ:0,getTitleId:function(d){return"ui-dialog-title-"+(d.attr("id")||++this.uuid)},overlay:function(d){this.$el=c.ui.dialog.overlay.create(d)}});c.extend(c.ui.dialog.overlay,{instances:[],maxZ:0,events:c.map("focus,mousedown,mouseup,keydown,keypress,click".split(","),function(d){return d+".dialog-overlay"}).join(" "),create:function(e){if(this.instances.length===0){setTimeout(function(){if(c.ui.dialog.overlay.instances.length){c(document).bind(c.ui.dialog.overlay.events,function(f){var g=c(f.target).parents(".ui-dialog").css("zIndex")||0;return(g>c.ui.dialog.overlay.maxZ)})}},1);c(document).bind("keydown.dialog-overlay",function(f){(e.options.closeOnEscape&&f.keyCode&&f.keyCode==c.ui.keyCode.ESCAPE&&e.close(f))});c(window).bind("resize.dialog-overlay",c.ui.dialog.overlay.resize)}var d=c("<div></div>").appendTo(document.body).addClass("ui-widget-overlay").css({width:this.width(),height:this.height()});(e.options.bgiframe&&c.fn.bgiframe&&d.bgiframe());this.instances.push(d);return d},destroy:function(d){this.instances.splice(c.inArray(this.instances,d),1);if(this.instances.length===0){c([document,window]).unbind(".dialog-overlay")}d.remove();var e=0;c.each(this.instances,function(){e=Math.max(e,this.css("z-index"))});this.maxZ=e},height:function(){if(c.browser.msie&&c.browser.version<7){var e=Math.max(document.documentElement.scrollHeight,document.body.scrollHeight);var d=Math.max(document.documentElement.offsetHeight,document.body.offsetHeight);if(e<d){return c(window).height()+"px"}else{return e+"px"}}else{return c(document).height()+"px"}},width:function(){if(c.browser.msie&&c.browser.version<7){var d=Math.max(document.documentElement.scrollWidth,document.body.scrollWidth);var e=Math.max(document.documentElement.offsetWidth,document.body.offsetWidth);if(d<e){return c(window).width()+"px"}else{return d+"px"}}else{return c(document).width()+"px"}},resize:function(){var d=c([]);c.each(c.ui.dialog.overlay.instances,function(){d=d.add(this)});d.css({width:0,height:0}).css({width:c.ui.dialog.overlay.width(),height:c.ui.dialog.overlay.height()})}});c.extend(c.ui.dialog.overlay.prototype,{destroy:function(){c.ui.dialog.overlay.destroy(this.$el)}})})(jQuery);;
 /* Site specific functionality for 360innovate.co.uk
  * Copyright (c) 2010 360innovate
  * @author John McCollum
 */

(function($){
    
    $.settings = {
        media_url: 'http://media.360innovate.co.uk/',
        site_url: 'http://www.360innovate.co.uk/'
    };
    
    // functions dealing with the portfolio section
    $.portfolio = {
        counter: 1,
        
	init: function(){
	    var container = $('#filter-container');
	    container.hide();
	    
	    var divCSS = {width:'960px', margin: '0 auto', textAlign: 'right'};
	    var myDiv=$('<div/>', {
		css: divCSS
	    });
	    
	    var loaderImg = $('<img/>', {
		id: 'spinnerDiv',
		css: {display: 'none', position:'absolute', left:'47%', top:'140px'},
		src: $.settings.media_url + 'images/design/ajax-loader.gif',
		alt: 'loading...'
	    }).appendTo($('#portfolio-featured-container'));
	    
	    var myLink = $('<a/>', {
		href: '#'
	    }).toggle(
		function(event){
		    $.portfolio.showFilter(event, container);
		},
		function(event){
		    $.portfolio.hideFilter(event, container);
		}
	    ).appendTo(myDiv);
	    
	    var myImg = $('<img />', {
		alt: 'Filter Projects',
		id: 'filterToggle',
		src: $.settings.media_url + '/images/design/refine-show.png'
	    }).appendTo(myLink);
	    
	    myDiv.prependTo($('#portfolio-featured-container'));
	},
	
	showFilter: function(event, el){
	    event.preventDefault();
	    el.stop().slideDown('fast');
	    $('#filterToggle').attr('src', $.settings.media_url + '/images/design/refine-hide.png');
	},
	
	hideFilter: function(event, el){
	    event.preventDefault();
	    el.stop().slideUp('fast');
	    $('#filterToggle').attr('src', $.settings.media_url + '/images/design/refine-show.png');
	},
	
	setLinkClass: function(el){
	    $('.tagFilter').each(function(i, link){
		$(link).removeClass('tagFilter-selected');
	    });
	    
	    $(el).addClass('tagFilter-selected');
	    return true;
	},
	
        tagFilter: function(event, el){
	    $.portfolio.setLinkClass(el);
	    
            // x-browser workaround madness - todo - can be refactored with 2nd argument above now
            var href = $(event.target).attr('href') ? $(event.target).attr('href'):$(event.originalTarget).attr('href');

            // Ideally we would use the beforeSend property of the ajax object for this function, but it's throwing a
            // flakey because there's a race condition going on with the animation and the results data.
            // So, we'll call the ajax request as a callback function of the animation instead.
            
            $('div#footer').fadeOut('medium');
	    $('h1.projects').fadeOut('medium');
            $('.portfolioItem').fadeTo('medium', '0', function(){
                $(this).remove();
            });
            
            $('#portfolio-featured-large').fadeTo('medium', '0', function(){
                $(this).hide();
                $.portfolio.addFilterSpinner();
                
                $.ajax({
                    type: "GET",
                    url: href,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $('ajaxFail').dialog('open');
                    },
                    success: function(data){
                        $.portfolio.removeFilterSpinner();
                        
                        if(data.length)
                        {
                            // get Featured HTML + append
                            var featuredHtml = $.portfolio.getFeaturedHtml(data.shift());
                            
                            $('#portfolio-featured-large').html(featuredHtml).show().fadeTo('medium', '1');
                            
                            // make sure there are still items to work with after removing one earlier
                            if(data.length)
                            {
                                //get sub items + append. We only want to append once to minimise the cost of appending to the DOM
                                var html = '<h1 class="projects">Other Projects</h1>';
                                
                                $.each(data, function(i, item){
                                    html += $.portfolio.getItemHtml(item);
                                });
                                
                                html += '<div class="clearer"></div>';
                                $('#portfolio-items').html(html).hide().fadeIn('slow');
                            }
                        }else{
                            $('#noItems').dialog('open');
                        }

						$('div#footer').fadeIn('medium');

                    }
                });
            });
        },
        
        getItemHtml: function(item){
            var html = '<div class="portfolioItem" id="portfolio' + $.portfolio.counter + '"><div class="folio-pic">';
            html += '<a href="' + $.settings.site_url + 'portfolio/' + item.fields.url + '/">';
            html += '<img src="' + $.settings.media_url + item.fields.teaser_thumbnail + '"/></a></div>';
            
            html += '<div class="teaser"><h3><a href="' + item.fields.url + '/">' + item.fields.company_name + '</a></h3>';
            html += '<p>' + item.fields.teaser + '</p></div>';
                        
            html += '</p></div></div>';
            
            $.portfolio.counter++;
            
            return html;
        },
        
        getFeaturedHtml: function(item){
            var html = '<div id="portfolio-featured-pic">';
            html += '<a href="/portfolio/' + item.fields.url + '/">';
            html += '<img src="' + $.settings.media_url + '/' + item.fields.featured_photo + '"/></a></div>';
            html += '<div id="featured-portfolio-content"><div id="featured-portfolio-text">';
            html += '<h1><a href="' + $.settings.site_url + 'portfolio/' + item.fields.url + '/">' + item.fields.company_name + '</a></h1>';
            html += '<p>' + item.fields.project_summary + '.</p>';
            html += '<div id="click-more"><a href="' + $.settings.site_url + 'portfolio/' + item.fields.url + '/">Click for more</a></div></div>';
            html += '<div id="featured-portfolio-tags" class="filter-item"><h2>Services:</h2><p>';
            
            $.each(item.fields.service_tags, function(i, tag){
                html += '<a href="' + tag.fields.content_page.fields.url + '">' + tag.fields.tagname + '</a><br/>';
            });
            
            html += '</p></div></div><div class="clearer"></div>';
            return html;
        },
        
        addFilterSpinner: function(){
            $('#spinnerDiv').show();
        },
        
        removeFilterSpinner: function(){
            $('#spinnerDiv').hide();
        },
        
        go: function(div){            
            var link = $(div).children('.teaser').children('h3').children('a');
            window.location.href = link.attr('href');
        }
    };
    
    $.contact = {
        submit: function(event){
            event.preventDefault();
            if($.contact.check()){
                $.contact.send();
            }
        },
        
        check: function(){
            var fields = $('form#contact input');
            var validated = Boolean(true);
            
            if($('#id_cust_name').val() == ''){
                $('#noName').dialog('open');
                validated = false;
                
            }else if(!$.contact.validateEmail($('#id_email_address').val())){
                $('#emailFail').dialog('open');
                validated = false;
            
            }else if($('#id_message').val() == ''){
                $('#noMessage').dialog('open');
                validated = false;
            }
            
            return validated;
        },
        
        validateEmail: function(addr){
            var filter = /^([a-zA-Z0-9_.\-])+@(([a-zA-Z0-9\-])+.)+([a-zA-Z0-9]{2,4})+$/;
            return (filter.test(addr));
        },
        
        send: function(){
	    $.ajax({
		type: "GET",
		url: '/contact/thanks/'
	    });
	    
            $.ajax({
                type: "POST",
                url: "/contact/",
                data: ({
                    cust_name: $('#id_cust_name').val(),
                    company: $('#id_company').val(),
                    telephone: $('#id_telephone').val(),
                    message: $('#id_message').val(),
		    subscribe: $('#id_subscribe').is(':checked') ? '1':'0',
                    email_address: $('#id_email_address').val()
                }),
                beforeSend: function(){
                    $('p#msg').remove();
                    var img = '<p><img id="loading" src="' + $.settings.media_url + 'images/design/ajax-loader.gif" alt="loading..." /></p>';
                    $('form#contact').append(img);
                },
                success: function(response){
                    if(response == 'ok'){
                        $('img#loading').remove();
                        var msg = '<p id="msg" style="display:none">Your message has been sent - we will be in touch shortly.</p>';
                        $('form#contact').append(msg);
                        $('p#msg').slideDown('slow');
                        
                        // we only want to clear fields if the message was sent
                        $.contact.clearFields();
                    }else{
                        alert('there was a problem sending your message at this time. please try again later.');
                    }
                },
                complete: function(){
                    $('img#loading').remove();
                }
            });
        },
        
        clearFields: function(){
            $('#id_cust_name').val('');
            $('#id_company').val('');
            $('#id_telephone').val('');
            $('#id_email_address').val('');
            $('#id_message').val('');
        }
    };
    
        
    $.uberfeed = {
        
        hoverTimer: undefined,
        
        show: function(event, items){
            try{
                event.preventDefault();
            }catch(error){}
            
            this.removeActiveClass();
            
            $('#uberfeed>li').hide();
            
            var listItems = [];
            
            if(items == 'uberTwitter'){
                listItems = $('#uberfeed>li.uberTwitter');
                
            }else if(items == 'uberBlog'){
                listItems = $('#uberfeed>li.uberBlog');

            }else{
                // all items
                listItems = $('#uberfeed>li');
            }
            
            var newItems = listItems.slice(0, 3);
            $(newItems).fadeIn(1000);
            
            this.setActiveLink(items);
        },
        
        removeActiveClass: function(){
            $.each($('.uberlink'), function(i, item){
                $(item).removeClass('uberHover');
                $(item).removeClass('uberBlogHover');
            });
        },
        
        setActiveLink: function(target){
            var myClass = target == 'uberBlog' ? 'uberBlogHover':'uberHover';
            var link = $('a#' + target);
            link.addClass(myClass);
        },
        
        hoverOn: function(){
            clearTimeout($.uberfeed.hoverTimer);
            var items = $('ul#uberfeed li').not(':hidden').not(this);
            $(this).stop().fadeTo(250, 1);
            items.stop().fadeTo(250, 0.3);
        },
        
        hoverOff: function(){
            $.uberfeed.hoverTimer = setTimeout(
            function(){
                var items = $('ul#uberfeed li').not(':hidden');
                items.stop().fadeTo(250, 1);
            }, 250);
        },
	
	handleFFClick: function(event){
	    // check to make sure it is a left click
	    if(event.which == 1){
		var loc = $(this).find('h3>a').attr('href');
		window.location.href = loc;
	    }
	}
    };
    
    $.slider = {
	squareOffSrc: $.settings.media_url + 'images/design/square-off.png',
	squareOnSrc: $.settings.media_url + 'images/design/square-on.png',
	
	hideInitial: function(){
	    var lis = $('div#slider').find('li').not(':first');
	    lis.css({'opacity': '0'}).hide();
	    
	    var myHeight = $('img.switcheroo:first').height() + 'px';
	    $('#slider').height(myHeight);
	    
	    $('#slider>ul').css('position', 'relative');
	    $('#slider>ul').children('li').css('position', 'absolute').css('top', '0');
	    
	    this.displayLinks(lis.length);
	    $('a.switcherLink:first>img').attr('src', $.slider.squareOnSrc);
	},
	
	
	displayLinks: function(count){
	    if(count>0){
		var slider = $('div#slider');
		
		var html = '<div class="switcher-links">';
		for(var i=0; i<count+1; ++i){
		    html += '<a class="switcherLink" rel="' + i + '" href="#"><img class="square" src="' + $.slider.squareOffSrc + '" alt="image '+parseInt(i+1,10)+'" /></a>';
		}
		html += '</div>';
		$(slider).before(html);
		
		$('a.switcherLink:first').addClass('current');
		
		$('a.switcherLink').click(function(event){
		    $.slider.handleClick(event);
		});
		
		var prevButton = $('<a/>', {
		    html: $('<img />', {
			src: $.settings.media_url + 'images/design/go_left.png',
			alt: 'Previous Image',
			title: 'Previous Image'
		    }),
		    href: '#',
		    id: 'prevButton'
		})
		.bind('click', function(event){
		    event.preventDefault();
		    $.slider.handleDirectionClick('prev');
		})
		.prependTo($('div.switcher-links'));
		
		var nextButton = $('<a/>', {
		    html: $('<img />', {
			src: $.settings.media_url + 'images/design/go_right.png',
			alt: 'Next Image',
			title: 'Next Image'
		    }),
		    href: '#',
		    id: 'nextButton'
		})
		.bind('click', function(event){
		    event.preventDefault();
		    $.slider.handleDirectionClick('next');
		})
		.appendTo($('div.switcher-links'));
	    }
	},
	
	handleDirectionClick: function(dir){
	    var links = $('a.switcherLink');
	    var currentIndex = links.index($('a.current'));
	    var newIndex = dir == 'next' ? currentIndex+1:currentIndex-1;
	    
	    if(newIndex == -1){
		newIndex = links.length - 1;
	    }else if(newIndex == links.length){
		newIndex = 0;
	    }
	    
	    var link = links[newIndex];
	    $(link).click();
	},
	
	resetSquares: function(){
	    $.each($('img.square'), function(i, item){
		$(this).attr('src', $.slider.squareOffSrc);
	    });
	    
	    $.each($('a.switcherLink'), function(i, item){
		$(this).removeClass('current');
	    });
	},
	
	handleClick: function(event){
	    event.preventDefault();
	    $.slider.resetSquares();
	    
	    var a = event.currentTarget;
	    var img = $(a).find('img');
	    var rel = $(a).attr('rel');
	    $(a).addClass('current');
	    
	    $(img).attr('src', $.slider.squareOnSrc);
	    
	    var lis = $('#slider > ul').children('li').not(':hidden');
	    $.each(lis, function(i, li){
		$(li).animate({'opacity': "0"}, 300).hide();
	    });
	    
	    var toShow = $('#slider > ul').children('li')[rel];
	    $('#slider').height($(toShow).height());
	    $(toShow).show().animate({'opacity': '1'}, 500);
	}
    };
    
    $.myAccordion = {
	init: function(){
	    $('ul.servicesList').hide();
	    $.myAccordion.preloadImages();
	    $.myAccordion.openPrevious();
	    
	    $('h3.services').css('cursor', 'pointer')
			    .toggle(
				function(event){
				    event.preventDefault();
				    $(this).next('ul').animate({height: 'toggle'}, 'fast', function(){
					$.myAccordion.applyBG(this);
					$.myAccordion.saveMenuState();
				    });
				    
				},
				function(event){
				    event.preventDefault();
				    $(this).next('ul').animate({height: 'toggle'}, 'fast', function(){
					$.myAccordion.applyBG(this);
					$.myAccordion.saveMenuState();
				    });
				}
			    );
	},
	
	preloadImages: function(){
	    var images = [$.settings.media_url + 'images/design/retract.png', $.settings.media_url + 'images/design/retract.png'];
	    $.each(images, function(i, imageSrc){
		var img = $('<img />', { src: imageSrc });
	    });
	},
	
	applyBG: function(ul){
	    if($(ul).is(":hidden")){
		$(ul).prev('h3').css('background', "url(" + $.settings.media_url + "images/design/expand.png)");
	    }else{
		$(ul).prev('h3').css('background', "url(" + $.settings.media_url + "images/design/retract.png)");
	    }
	},
	
	openPrevious: function(){
	    try{
		// I haz a cookie! Om nom nom...
		var openMenus = $.cookie('openMenus');
		openMenusList = openMenus.split(',');
		
		var allMenus = $('ul.servicesList');
		
		$.each(openMenusList, function(i, index){
		    $(allMenus[index]).show();
		    $.myAccordion.applyBG(allMenus[index]);
		});
	    }catch(e){
		// I can haz cookie pls?
		var heading = $('h1').text();
		var a = $('a[text='+heading+']');
		var menu = $(a).parent('li').parent('ul');
		menu.show();
		$.myAccordion.applyBG(menu);
		$.myAccordion.saveMenuState();
	    }
	},
	
	saveMenuState: function(){
	    var openMenus = [];
	    var menus = $('ul.servicesList');
	    
	    $.each(menus, function(i, menu){
		if($(menu).is(":visible")){
		    var index = menus.index(menu);
		    openMenus.push(index);
		}
	    });
	    $.cookie('openMenus', openMenus.join(','), { path: '/' });
	}
    };
    
    $.topclick = {
	go: function(el){
	    var distance = $('body').height();
	    var speed = 3;
	    var time = distance / speed;
	    $('html,body').stop().animate({ scrollTop:0 }, time, 'easeOutCubic');
	}
    };
    
    $.dialog = {
	init: function(){
	    // initialise dialogue boxes
	    var dOptions = { modal: true, draggable: false, autoOpen: false, width: '400px', buttons: { "Close": function(){ $(this).dialog("close");}}};
	    
	    // This allows the user to click on the overlay to dismiss the dialogue box. Warning: not officially supported. OMGHAX!!!1!
	    $('.ui-widget-overlay').live("click", function(){ $('.ui-dialog-buttonpane>button').click(); });
	    
	    $('#noName').dialog(dOptions);
	    $('#emailFail').dialog(dOptions);
	    $('#noMessage').dialog(dOptions);
	    $('#noItems').dialog(dOptions);
	    $('#ajaxFail').dialog(dOptions);
	}
    };
    
    $.flash = {
	embed: function(){
	    var flashvars = {menu: 'false'};
	    var params = {
		allowScriptAccess:'always',
		allowFullScreen:'false',
		quality: 'high',
		wmode: 'transparent',
		bgcolor: '#ffffff'
	    };
	    var attributes = {};
	    
	    swfobject.embedSWF($.settings.media_url + 'flash/banner.swf', 'header-area', '960', '363', "10.0.0","expressInstall.swf", flashvars, params, attributes);
	}
    };
    
    $.social = {
	init: function(){
	    $('#social-left').children('a').css('opacity', '0.5');
	},
	
	hoverOn: function(el){
	    $(el).stop().fadeTo(400, 1);
	},
	
	hoverOff: function(el){
	    $(el).stop().fadeTo(400, 0.5);
	}
    };
        
}(jQuery));

// attach functions to event handlers
$(function(event){
    
    $.flash.embed();
    
    if($('#uberfeed').length){
        $.uberfeed.show(event, 'uberBlog');
        
        $('.uberlink').click(function(event){
                $.uberfeed.show(event, $(this).attr('id'));
            }
        );
        
        $('ul#uberfeed li').hover($.uberfeed.hoverOn, $.uberfeed.hoverOff);
	
	$('li.uberFriendFeed').bind('click', $.uberfeed.handleFFClick);
    }
    
    // Portfolio functions
    if($('#portfolio-filter').length){
	$.portfolio.init();
    }
    
    $('a.tagFilter').live("click", function(event){
        if(event.button !== 0){
            return true;
        }else{
            event.preventDefault();
            $.portfolio.tagFilter(event, this);
        }
    });
    
    $('div.portfolioItem').live('click', function(event){
        if (event.button !== 0 || event.target.tagName == 'A') {
            // wasn't the left button, or the user clicked on a link - possibly a service tag - perform default action
            return true;
        }else{	    
            $.portfolio.go(this);
        }
    });
    
    if($('div#slider').length){
	$.slider.hideInitial();
    }
    
    // Contact functions
    $('form#contact').submit($.contact.submit);
    
    // dialog stuff
    $.dialog.init();
    
    // services slideroo
    if($('ul.servicesList').length)
    {
	$.myAccordion.init();
    }
    
    $('a#scrollToTop').click(function(event){
	event.preventDefault();
	$.topclick.go(this);
    });
    
    // the social left, comrade
    $.social.init();
    $('#social-left a').hover(function(){ $.social.hoverOn(this); }, function(){ $.social.hoverOff(this); } );
    
    // Hack to get real image height of slider after the page has loaded.
    if($('#slider').length){
	$(window).bind('load', function(){
	    var max = $('img.switcheroo:first').height() + 'px';
	    $('#slider').height(max);
	});
    }

});
