
/**
 * Twit
 *  jQuery Plugin to Display Twitter Tweets on a Blog.
 *  http://code.google.com/p/jquery-twit/
 *
 * Copyright (c) 2009 Yusuke Horie
 *
 * Released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since  : 0.1.0 - 08/26/2009
 * Version: 0.1.0 - 08/26/2009
 */
(function(jQuery){var _i=0;jQuery.fn.twit=function(user,options){if(typeof user!='string')return this;var opts=jQuery.extend({},jQuery.fn.twit.defaults,options),c=jQuery.isFunction(opts.callback)?opts.callback:_callback,url='',params={};opts.user=user;url='http://twitter.com/statuses/user_timeline/'+opts.user+'.json';params.count=opts.count;return this.each(function(i,e){var $e=$(e);if(!$e.hasClass('twit'))$e.addClass('twit');jQuery.ajax({url:url,data:params,dataType:'jsonp',success:function(o){c.apply(this,[(o.results)?o.results:o,e,opts])}})})};jQuery.fn.twit.defaults={user:null,callback:null,icon:true,username:true,text:true,count:200,limit:7,label:'Twitter',title:''};var _callback=function(o,e,opts){var $this=$(e);if(!o||o.length==0||$this.length==0)return false;$this.data('_inc',1);_i++;var username=o[0].user.screen_name,icon=o[0].user.profile_image_url;var h='<div class="twitHeader">'+' <span class="twitLabel">'+opts.label+'</span>&nbsp;&nbsp;'+' <span class="twitTitle">'+opts.title+'</span>'+'</div>';if(opts.icon||opts.username){h+='<div class="twitUser">';if(opts.icon)h+=' <a href="http://twitter.com/'+username+'/">'+'  <img src="'+icon+'" alt="'+username+'" title="'+username+'" style="vertical-align:middle;" />'+' </a>&nbsp;&nbsp;';if(opts.username)h+='<a href="http://twitter.com/'+username+'/">'+username+'</a>';h+='</div>'}h+='<ul class="twitBody" id="twitList'+_i+'">'+_build(o,$this,opts)+'</ul>';$this.html(h);$('#twitList'+_i+' a.twitEntryShow').live('click.twitEntryShow'+_i,function(event){event.preventDefault();var $t=$(this);$t.parent().fadeOut(400,function(){var i=$this.data('_inc');i++;$this.data('_inc',i);if($t.hasClass('twitEntryAll')){$t.die('click.twitEntryShow'+_i);var start=(i*opts.limit)-opts.limit;$(this).after(_build(o,$this,opts,start,o.length)).remove()}else{$(this).after(_build(o,$this,opts)).remove()}})})};var _build=function(o,$t,opts,s,e){var h='',inc=$t.data('_inc'),start=s||(inc*opts.limit)-opts.limit,end=e||((o.length>start+opts.limit)?start+opts.limit:o.length);for(var i=start;i<end;i++){var t=o[i],username=t.user.screen_name,icon=t.user.profile_image_url;h+='<li class="twitEntry">';if(opts.text){var text=t.text.replace(/(https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/,function(u){var shortUrl=(u.length>30)?u.substr(0,30)+'...':u;return'<a href="'+u+'">'+shortUrl+'</a>'}).replace(/@([a-zA-Z_]+)/g,'@<a href="http://twitter.com/$1">$1</a>').replace(/(?:^|\s)#([^\s\.\+:!]+)/g,function(a,u){return' <a href="http://twitter.com/search?q='+encodeURIComponent(u)+'">#'+u+'</a>'});h+=' <span>'+text+'</span>'}h+='</li>'}if(o.length>end){h+='<li class="twitNavi">'+'<a href="#" class="twitEntryShow">more</a> &nbsp;/&nbsp;';if(o.length>opts.limit)h+='<a href="#" class="twitEntryShow twitEntryAll">all</a>';h+='</li>'}return h}})(jQuery);




/*!
 * (v) Compact labels plugin
 * Takes one option: labelOpacity [default: true] set to false to disable label opacity change on empty input focus
 */
(function($){$.fn.compactize=function(options){var defaults={labelOpacity:true};options=$.extend(defaults,options);return this.each(function(){var label=$(this),input=$('#'+label.attr('for'));input.focus(function(){if(options.labelOpacity){if(input.val()===''){label.css('opacity','0.5');}}else{label.hide();}});if(options.labelOpacity){input.keydown(function(){label.hide();label.css('opacity',1);});} input.blur(function(){if(input.val()===''){label.show();} if(options.labelOpacity){label.css('opacity',1);}});window.setTimeout(function(){label.toggle(input.val()==='');},50);});};})(jQuery);


/*!
 * (v) hrefID jQuery extention
 * returns a valid #hash string from link href attribute in Internet Explorer
 */
(function($){$.fn.extend({hrefId:function(){return $(this).attr('href').substr($(this).attr('href').indexOf('#'));}});})(jQuery);

/*
 * jQuery UI Effects 1.8.4
 *
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Effects/
 */
jQuery.effects||function(f,j){function l(c){var a;if(c&&c.constructor==Array&&c.length==3)return c;if(a=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(c))return[parseInt(a[1],10),parseInt(a[2],10),parseInt(a[3],10)];if(a=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(c))return[parseFloat(a[1])*2.55,parseFloat(a[2])*2.55,parseFloat(a[3])*2.55];if(a=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(c))return[parseInt(a[1],
16),parseInt(a[2],16),parseInt(a[3],16)];if(a=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(c))return[parseInt(a[1]+a[1],16),parseInt(a[2]+a[2],16),parseInt(a[3]+a[3],16)];if(/rgba\(0, 0, 0, 0\)/.exec(c))return m.transparent;return m[f.trim(c).toLowerCase()]}function r(c,a){var b;do{b=f.curCSS(c,a);if(b!=""&&b!="transparent"||f.nodeName(c,"body"))break;a="backgroundColor"}while(c=c.parentNode);return l(b)}function n(){var c=document.defaultView?document.defaultView.getComputedStyle(this,null):this.currentStyle,
a={},b,d;if(c&&c.length&&c[0]&&c[c[0]])for(var e=c.length;e--;){b=c[e];if(typeof c[b]=="string"){d=b.replace(/\-(\w)/g,function(g,h){return h.toUpperCase()});a[d]=c[b]}}else for(b in c)if(typeof c[b]==="string")a[b]=c[b];return a}function o(c){var a,b;for(a in c){b=c[a];if(b==null||f.isFunction(b)||a in s||/scrollbar/.test(a)||!/color/i.test(a)&&isNaN(parseFloat(b)))delete c[a]}return c}function t(c,a){var b={_:0},d;for(d in a)if(c[d]!=a[d])b[d]=a[d];return b}function k(c,a,b,d){if(typeof c=="object"){d=
a;b=null;a=c;c=a.effect}if(f.isFunction(a)){d=a;b=null;a={}}if(typeof a=="number"||f.fx.speeds[a]){d=b;b=a;a={}}if(f.isFunction(b)){d=b;b=null}a=a||{};b=b||a.duration;b=f.fx.off?0:typeof b=="number"?b:f.fx.speeds[b]||f.fx.speeds._default;d=d||a.complete;return[c,a,b,d]}f.effects={};f.each(["backgroundColor","borderBottomColor","borderLeftColor","borderRightColor","borderTopColor","color","outlineColor"],function(c,a){f.fx.step[a]=function(b){if(!b.colorInit){b.start=r(b.elem,a);b.end=l(b.end);b.colorInit=
true}b.elem.style[a]="rgb("+Math.max(Math.min(parseInt(b.pos*(b.end[0]-b.start[0])+b.start[0],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[1]-b.start[1])+b.start[1],10),255),0)+","+Math.max(Math.min(parseInt(b.pos*(b.end[2]-b.start[2])+b.start[2],10),255),0)+")"}});var m={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,
183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,
165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0],transparent:[255,255,255]},p=["add","remove","toggle"],s={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};f.effects.animateClass=function(c,a,b,d){if(f.isFunction(b)){d=b;b=null}return this.each(function(){var e=f(this),g=e.attr("style")||" ",h=o(n.call(this)),q,u=e.attr("className");f.each(p,function(v,
i){c[i]&&e[i+"Class"](c[i])});q=o(n.call(this));e.attr("className",u);e.animate(t(h,q),a,b,function(){f.each(p,function(v,i){c[i]&&e[i+"Class"](c[i])});if(typeof e.attr("style")=="object"){e.attr("style").cssText="";e.attr("style").cssText=g}else e.attr("style",g);d&&d.apply(this,arguments)})})};f.fn.extend({_addClass:f.fn.addClass,addClass:function(c,a,b,d){return a?f.effects.animateClass.apply(this,[{add:c},a,b,d]):this._addClass(c)},_removeClass:f.fn.removeClass,removeClass:function(c,a,b,d){return a?
f.effects.animateClass.apply(this,[{remove:c},a,b,d]):this._removeClass(c)},_toggleClass:f.fn.toggleClass,toggleClass:function(c,a,b,d,e){return typeof a=="boolean"||a===j?b?f.effects.animateClass.apply(this,[a?{add:c}:{remove:c},b,d,e]):this._toggleClass(c,a):f.effects.animateClass.apply(this,[{toggle:c},a,b,d])},switchClass:function(c,a,b,d,e){return f.effects.animateClass.apply(this,[{add:a,remove:c},b,d,e])}});f.extend(f.effects,{version:"1.8.4",save:function(c,a){for(var b=0;b<a.length;b++)a[b]!==
null&&c.data("ec.storage."+a[b],c[0].style[a[b]])},restore:function(c,a){for(var b=0;b<a.length;b++)a[b]!==null&&c.css(a[b],c.data("ec.storage."+a[b]))},setMode:function(c,a){if(a=="toggle")a=c.is(":hidden")?"show":"hide";return a},getBaseline:function(c,a){var b;switch(c[0]){case "top":b=0;break;case "middle":b=0.5;break;case "bottom":b=1;break;default:b=c[0]/a.height}switch(c[1]){case "left":c=0;break;case "center":c=0.5;break;case "right":c=1;break;default:c=c[1]/a.width}return{x:c,y:b}},createWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent();
var a={width:c.outerWidth(true),height:c.outerHeight(true),"float":c.css("float")},b=f("<div></div>").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0});c.wrap(b);b=c.parent();if(c.css("position")=="static"){b.css({position:"relative"});c.css({position:"relative"})}else{f.extend(a,{position:c.css("position"),zIndex:c.css("z-index")});f.each(["top","left","bottom","right"],function(d,e){a[e]=c.css(e);if(isNaN(parseInt(a[e],10)))a[e]="auto"});
c.css({position:"relative",top:0,left:0})}return b.css(a).show()},removeWrapper:function(c){if(c.parent().is(".ui-effects-wrapper"))return c.parent().replaceWith(c);return c},setTransition:function(c,a,b,d){d=d||{};f.each(a,function(e,g){unit=c.cssUnit(g);if(unit[0]>0)d[g]=unit[0]*b+unit[1]});return d}});f.fn.extend({effect:function(c){var a=k.apply(this,arguments);a={options:a[1],duration:a[2],callback:a[3]};var b=f.effects[c];return b&&!f.fx.off?b.call(this,a):this},_show:f.fn.show,show:function(c){if(!c||
typeof c=="number"||f.fx.speeds[c])return this._show.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="show";return this.effect.apply(this,a)}},_hide:f.fn.hide,hide:function(c){if(!c||typeof c=="number"||f.fx.speeds[c])return this._hide.apply(this,arguments);else{var a=k.apply(this,arguments);a[1].mode="hide";return this.effect.apply(this,a)}},__toggle:f.fn.toggle,toggle:function(c){if(!c||typeof c=="number"||f.fx.speeds[c]||typeof c=="boolean"||f.isFunction(c))return this.__toggle.apply(this,
arguments);else{var a=k.apply(this,arguments);a[1].mode="toggle";return this.effect.apply(this,a)}},cssUnit:function(c){var a=this.css(c),b=[];f.each(["em","px","%","pt"],function(d,e){if(a.indexOf(e)>0)b=[parseFloat(a),e]});return b}});f.easing.jswing=f.easing.swing;f.extend(f.easing,{def:"easeOutQuad",swing:function(c,a,b,d,e){return f.easing[f.easing.def](c,a,b,d,e)},easeInQuad:function(c,a,b,d,e){return d*(a/=e)*a+b},easeOutQuad:function(c,a,b,d,e){return-d*(a/=e)*(a-2)+b},easeInOutQuad:function(c,
a,b,d,e){if((a/=e/2)<1)return d/2*a*a+b;return-d/2*(--a*(a-2)-1)+b},easeInCubic:function(c,a,b,d,e){return d*(a/=e)*a*a+b},easeOutCubic:function(c,a,b,d,e){return d*((a=a/e-1)*a*a+1)+b},easeInOutCubic:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a+b;return d/2*((a-=2)*a*a+2)+b},easeInQuart:function(c,a,b,d,e){return d*(a/=e)*a*a*a+b},easeOutQuart:function(c,a,b,d,e){return-d*((a=a/e-1)*a*a*a-1)+b},easeInOutQuart:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a+b;return-d/2*((a-=2)*a*a*a-2)+
b},easeInQuint:function(c,a,b,d,e){return d*(a/=e)*a*a*a*a+b},easeOutQuint:function(c,a,b,d,e){return d*((a=a/e-1)*a*a*a*a+1)+b},easeInOutQuint:function(c,a,b,d,e){if((a/=e/2)<1)return d/2*a*a*a*a*a+b;return d/2*((a-=2)*a*a*a*a+2)+b},easeInSine:function(c,a,b,d,e){return-d*Math.cos(a/e*(Math.PI/2))+d+b},easeOutSine:function(c,a,b,d,e){return d*Math.sin(a/e*(Math.PI/2))+b},easeInOutSine:function(c,a,b,d,e){return-d/2*(Math.cos(Math.PI*a/e)-1)+b},easeInExpo:function(c,a,b,d,e){return a==0?b:d*Math.pow(2,
10*(a/e-1))+b},easeOutExpo:function(c,a,b,d,e){return a==e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b},easeInOutExpo:function(c,a,b,d,e){if(a==0)return b;if(a==e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b},easeInCirc:function(c,a,b,d,e){return-d*(Math.sqrt(1-(a/=e)*a)-1)+b},easeOutCirc:function(c,a,b,d,e){return d*Math.sqrt(1-(a=a/e-1)*a)+b},easeInOutCirc:function(c,a,b,d,e){if((a/=e/2)<1)return-d/2*(Math.sqrt(1-a*a)-1)+b;return d/2*(Math.sqrt(1-(a-=2)*
a)+1)+b},easeInElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return-(h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g))+b},easeOutElastic:function(c,a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e)==1)return b+d;g||(g=e*0.3);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);return h*Math.pow(2,-10*a)*Math.sin((a*e-c)*2*Math.PI/g)+d+b},easeInOutElastic:function(c,
a,b,d,e){c=1.70158;var g=0,h=d;if(a==0)return b;if((a/=e/2)==2)return b+d;g||(g=e*0.3*1.5);if(h<Math.abs(d)){h=d;c=g/4}else c=g/(2*Math.PI)*Math.asin(d/h);if(a<1)return-0.5*h*Math.pow(2,10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)+b;return h*Math.pow(2,-10*(a-=1))*Math.sin((a*e-c)*2*Math.PI/g)*0.5+d+b},easeInBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;return d*(a/=e)*a*((g+1)*a-g)+b},easeOutBack:function(c,a,b,d,e,g){if(g==j)g=1.70158;return d*((a=a/e-1)*a*((g+1)*a+g)+1)+b},easeInOutBack:function(c,
a,b,d,e,g){if(g==j)g=1.70158;if((a/=e/2)<1)return d/2*a*a*(((g*=1.525)+1)*a-g)+b;return d/2*((a-=2)*a*(((g*=1.525)+1)*a+g)+2)+b},easeInBounce:function(c,a,b,d,e){return d-f.easing.easeOutBounce(c,e-a,0,d,e)+b},easeOutBounce:function(c,a,b,d,e){return(a/=e)<1/2.75?d*7.5625*a*a+b:a<2/2.75?d*(7.5625*(a-=1.5/2.75)*a+0.75)+b:a<2.5/2.75?d*(7.5625*(a-=2.25/2.75)*a+0.9375)+b:d*(7.5625*(a-=2.625/2.75)*a+0.984375)+b},easeInOutBounce:function(c,a,b,d,e){if(a<e/2)return f.easing.easeInBounce(c,a*2,0,d,e)*0.5+
b;return f.easing.easeOutBounce(c,a*2-e,0,d,e)*0.5+d*0.5+b}})}(jQuery);
;/*
 * jQuery UI Effects Blind 1.8.4
 *
 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * http://docs.jquery.com/UI/Effects/Blind
 *
 * Depends:
 *	jquery.effects.core.js
 */
(function(b){b.effects.blind=function(c){return this.queue(function(){var a=b(this),g=["position","top","left"],f=b.effects.setMode(a,c.options.mode||"hide"),d=c.options.direction||"vertical";b.effects.save(a,g);a.show();var e=b.effects.createWrapper(a).css({overflow:"hidden"}),h=d=="vertical"?"height":"width";d=d=="vertical"?e.height():e.width();f=="show"&&e.css(h,0);var i={};i[h]=f=="show"?d:0;e.animate(i,c.duration,c.options.easing,function(){f=="hide"&&a.hide();b.effects.restore(a,g);b.effects.removeWrapper(a);
c.callback&&c.callback.apply(a[0],arguments);a.dequeue()})})}})(jQuery);
;



/*!
 * SimpleFlame Content rotator
 * Version 1.0
 */
(function($){function fisherYates(myArray){var i=myArray.length;if(i===0){return false;}while(--i){var j=Math.floor(Math.random()*(i+1));var tempi=myArray[i];var tempj=myArray[j];myArray[i]=tempj;myArray[j]=tempi;}}var sfRotator=function(el,options){this.settings={'item':'li','activeClass':'active','duration':5000,'autorotate':true,'effectIn':'fadeIn','optionsIn':{},'speedIn':'normal','effectOut':'fadeOut','optionsOut':{},'speedOut':'normal','random':false};$.extend(this.settings,options);this.$container=$(el);this.build();};sfRotator.prototype.build=function(){this.$container.addClass('sf-items');this.$wrapper=$('<div class="sf-rotator" />');this.$container.before(this.$wrapper);this.$wrapper.append(this.$container);this.$controls=$('<ul class="sf-controls" />');this.$wrapper.append(this.$controls);this.$items=this.$container.children(this.settings.item);if(this.settings.random===true){this.$items=this.$items.detach();fisherYates(this.$items);this.$container.append(this.$items);}this.$current=this.$items.index(this.$items.filter('.'+this.settings.activeClass));if(this.$current<0){this.$current=0;}var self=this;this.$items.addClass('sf-item').each(function(index,item){var trigger=$('<li><a href="#">'+parseInt(index+1,10)+'</a></li>');self.$controls.append(trigger);trigger.find('a').data('item',item).bind('click',{self:self},self.trigger);});this.activate(this.$current,true);if(this.settings.autorotate){this.autorotate();}};sfRotator.prototype.trigger=function(event){event.preventDefault();var self=event.data.self;self.stopAutorotate();self.$rotationTerminated=true;var position=self.$items.index($(this).data('item'));self.activate(position);};sfRotator.prototype.activate=function(position){var instant=arguments[1]||false;var activeClass=this.settings.activeClass;var oldItem=this.$items.eq(this.$current);var newItem=this.$items.eq(position);var onHide=function(){oldItem.removeClass(activeClass);};var onShow=function(){newItem.addClass(activeClass).css('zIndex',10);};var effects=['blind','bounce','clip','drop','explode','fold','highlight','puff','pulsate','scale','shake','size','slide','transfer'];if(instant===true){oldItem.removeClass(activeClass).hide();newItem.addClass(activeClass).show();}else{if($.inArray(this.settings.effectOut,effects)>-1){oldItem.hide(this.settings.effectOut,this.settings.optionsOut,this.settings.speedOut,onHide);}else if($.isFunction(oldItem[this.settings.effectOut])){oldItem[this.settings.effectOut](this.settings.speedOut,onHide);}else{throw"Unsupported hide transition";}newItem.css('zIndex',100);if($.inArray(this.settings.effectIn,effects)>-1){newItem.show(this.settings.effectIn,this.settings.optionsIn,this.settings.speedIn,onShow);}else if($.isFunction(newItem[this.settings.effectIn])){newItem[this.settings.effectIn](this.settings.speedIn,onShow);}else{throw"Unsupported show transition";}}this.$controls.find('a').removeClass('active').eq(position).addClass('active');this.$current=position;};sfRotator.prototype.autorotate=function(){this.$rotationTerminated=false;var self=this;this.$container.mouseenter(function(){self.stopAutorotate();});this.$container.mouseleave(function(){self.startAutorotate();});this.startAutorotate();};sfRotator.prototype.startAutorotate=function(){if(this.$rotationTerminated===true){return;}var self=this;this.$rotationInterval=window.setInterval(function(){var next=self.$current+1;if(next===self.$items.length){next=0;}self.activate(next);},this.settings.duration);};sfRotator.prototype.stopAutorotate=function(){if(this.settings.autorotate){window.clearInterval(this.$rotationInterval);}};$.fn.sfRotator=function(options){options=options||{};return this.each(function(){var r=new sfRotator(this,options);});};})(jQuery);

/*!

/*!
 * Scripts
 *
 */
jQuery(function($) {
 
	var Engine = {
		utils : {
			links : function(){
				$('a[rel*=external]').click(function(e){
					e.preventDefault();
					window.open($(this).attr('href'));						  
				});
			},
			mails : function(){
				$('a[href^=mailto:]').each(function(){
					var mail = $(this).attr('href').replace('mailto:','');
					var replaced = mail.replace('/at/','@');
					$(this).attr('href','mailto:'+replaced);
					if($(this).text() == mail) {
						$(this).text(replaced);
					}
				});
			}
		},
		enhancements : {
			labels : function() {
				$('.newsletter-a label').compactize();
				$('form.a label').compactize();
			},
			homeRotator : function() {
				var 
					$rotator = $('#rotator ul'),
					$items = $rotator.find('li'),
					interval,
					current = 0;
				
				$items.filter(':first').addClass('active');
				
				$items.each(function(){
					var img = $(this).find('img');
					$(this).css('backgroundImage','url('+img.attr('src')+')');
					img.remove();
				});
				
				function rotate() {
					var active = $items.eq(current);
					
					current = current + 1;
					if (current === $items.length) {
						current = 0;
					}
					next = $items.eq(current).addClass('nextItem');
					
					next.appendTo($rotator).show();
												
					active.hide('blind', { direction: 'horizontal' }, 500, function() {
						active.removeClass('active');
						next.removeClass('nextItem').addClass('active');
					}, 'easeOutExpo');
				}
				
				$items.click(function(e){
					e.preventDefault();
					
					clearInterval(interval);
					rotate();
					interval = setInterval(rotate, 6000);
				});
				
				interval = setInterval(rotate, 6000);
			},
			gallery : function() {
				if(!$('#gallery').length) {
					return;
				}
				
				var $gallery = $('#gallery'),
					$dataList = $('#gallery .data'),
					$photoContainer = $('<div id="main-photo" />').prependTo($gallery),
					$items = $dataList.clone(),

					$prevPhotoButton = $('<button />', {
						'class' : 'prev',
						text : 'Previous photo',
						click : function(){
							rotatePrev();
							resetInterval();
							return false;
						}
					}).appendTo($photoContainer),
					
					$nextPhotoButton = $('<button />', {
						'class' : 'next',
						text : 'Next photo',
						click : function(){
							rotateNext();
							resetInterval();
							return false;
						}
					}).appendTo($photoContainer),
					
					/* Create gallery navigation */
					$galleryNav = $('<div class="gallery-nav" />');
					
					/* Slideshow view navigation */
					$galleryNav
						.html(
							'<p class="slideshow-nav">' + 
							'<span class="category"></span> | ' +
							'<button class="prev">Previous Photo</button> ' +
							'<span class="current">1</span> of <span class="max"></span> ' +
							'<button class="next">Next Photo</button>' +
							'| <a href="#" class="info">Info</a></p>'
						)
						.appendTo($gallery)
						.find('.prev').click(function(){
							$prevPhotoButton.click();

							return false;
						}).end()
						.find('.next').click(function(){
							$nextPhotoButton.click();
						 
							return false;
						 }).end()
						.find('a.info').click(function(){
							if($gallery.is('.slideshow')) {
								$('.active .description', $photoContainer).toggle();
							}
						 
							return false;
						});
					
				var slideshowNavCurrent = $('.slideshow-nav .current', $galleryNav),
					slideshowCategory = $('.category', $galleryNav).text($('li:first', $items).find('.category').text()),
					
					$toggleView = $(
						'<p class="toggle-gallery-view">' + 
							'<button class="slideshow"><span>Slideshow</span></button>' + 
							'<button class="thumbnails"><span>Thumbnails</span></button>' + 
						'</p>'
					).insertAfter('.gallery-nav'),
					
					$thumbnailsNav = $('<div class="thumbnails-nav"><ul></ul></div>'),
					
					carouselButtonNext = '',
					carouselButtonPrev = '',
					slideshowButtonPrev = '',
					slideshowButtonNext = '',
					
					runGallery = '';
					
				slideshowButtonPrev = $('.slideshow-nav .prev');
				slideshowButtonNext = $('.slideshow-nav .next');
				
				/* Show next photo */
				function rotateNext() {
					var $active = $items.find('.active'),
						$next = '';

					if(!$active.is(':last-child')) {
						$next = $active.next();
						$next.addClass('nextItem');
						
						$active
							.hide('blind', { direction: 'horizontal' }, 300, function() {
								$next.removeClass('nextItem').addClass('active');
								$(this)
									.removeClass('active')
										.find('.description').hide().end()
									.show();
									
								togglePrevNextButtons();
								updateStatus($('.active', $items).attr('id').replace(/item-/, ''));
							}, 'easeOutExpo');
					}
				}
				
				/* Show previous photo */
				function rotatePrev() {
					var $active = $items.find('.active'),
						$prev = '';
					
					if(!$active.is(':first-child')) {
						$prev = $active.prev();
						$active.addClass('nextItem').find('.description').hide();
						
						$prev
							.addClass('active')
							.hide()
							.show('blind', { direction: 'horizontal' }, 300, function() {
								$active.removeClass('active nextItem');
	
								togglePrevNextButtons();
								updateStatus(this.id.replace(/item-/, ''));
							}, 'easeOutExpo');
					}
				}
				
				/* Update gallery navigation */
				function updateStatus(index) {
					slideshowNavCurrent.text(index);
					
					$('.active', $thumbnailsNav).removeClass('active');
					$thumbnailsNav.find('a[href$=#item-' + index + ']').parent().addClass('active');
					slideshowCategory.text($('.active', $items).find('.category').text());
					checkCarouselPosition();
				}
				
				/* Show/hide prev/next photo buttons */
				function togglePrevNextButtons() {
					if($('.active', $items).is(':last-child')) {
						$nextPhotoButton.hide();
						slideshowButtonNext.hide();
					} else {
						$nextPhotoButton.show();
						slideshowButtonNext.show();
					}
					
					if($('.active', $items).is(':first-child')) {
						$prevPhotoButton.hide();
						slideshowButtonPrev.hide();
					} else {
						$prevPhotoButton.show();
						slideshowButtonPrev.show();
					}
				}
				
				$('li', $items).each(function(idx){
					this.id = 'item-' + ++idx;
				});
				
				/* Switch between slideshow and thumbnails gallery view */
				$('button', $toggleView).click(function(){
					if(!$('span', this).is('.active')) {
						$gallery.removeClass().addClass(this.className);
						$('span', $toggleView).toggleClass('active');
						resetInterval();
					}
					return false;
				});
					
				/* Slideshow */
				
				$('.slideshow span', $toggleView).addClass('active');
				
				if(!$.browser.msie) {
					$prevPhotoButton.add($nextPhotoButton).hover(
						function(){ $(this).stop().animate({ opacity: 1 }, 300); },
						function(){	$(this).stop().animate({ opacity: 0.4 }, 300); }
					);
				}
				
				$items
					.find('.thumb').remove().end()
					.find('li:first').addClass('active').end()
					.removeClass('data').prependTo($photoContainer);

				/* Thumbnails */

				$('li', $items).each(function(index){
					$('<li><a href="#item-' + ++index + '">' + index + '</a></li>').appendTo($('ul', $thumbnailsNav));
				});
				
				$photoContainer.hover(
					function(){
						if($gallery.is('.thumbnails')) {
							$('.description', this).show();
						}
					},
					function(){
						if($gallery.is('.thumbnails')) {
							$('.description', this).hide();
						}
					}
				);
				
				$('li a', $dataList).each(function(index){
					$('li:eq(' + index + ') .thumb', $dataList).appendTo(this);
				});
								
				$thumbnailsNav
					.appendTo('<div class="carousel-wrap"></div>')
					.parent()
						.prepend('<button class="carousel-prev button-disabled">&larr;</button>')
						.append('<button class="carousel-next">&rarr;</button>')
						.find('li:first')
							.addClass('active')
						.end()
						.append($('li .thumb', $dataList))
						.find('.thumb')
							.wrapAll('<div class="thumbs"></div>')
							.end()
					.appendTo($galleryNav);
				
				$('.thumb', $galleryNav).each(function(){
					$(this).css('marginLeft', -parseInt($(this).width()/2, 10));
				});
			
				var carouselOffset = $('.carousel-wrap').offset().left,
					$thumbs = $('.thumbs', $gallery),
					itemOffset = parseInt($('li:first a', $thumbnailsNav).width()/2, 10),
					currentThumb = '';
				
				$(window).bind('resize', function(){
					carouselOffset = $('.carousel-wrap').offset().left;
				});
				
				/* Popup thumbnail */

				$('li a', $thumbnailsNav)
					.hover(
						function(){
							currentThumb = $thumbs.find('.thumb:eq(' + $(this).parent().index() + ')').show();
							currentThumb.css('left', $(this).offset().left + itemOffset - carouselOffset);
						},
						function(){
							currentThumb.hide();
						}
					)
					.click(function(){
						if($(this).parent().is('.active')) {
							return false;
						}
						
						resetInterval();
						
						var oldActive = $('.active', $items),
							newActive = $($(this).hrefId(), $items).addClass('nextItem');
						
						$('.active', $items)
							.hide('blind', { direction: 'horizontal' }, 300, function() {
								$(this)
									.removeClass('active')
									.show();
									
								newActive.removeClass('nextItem').addClass('active');
									
								$('.description', oldActive).hide();

								updateStatus(newActive.attr('id').replace(/item-/, ''));
							}, 'easeOutExpo');

						return false;
					});
				
				$thumbnailsNav.jCarouselLite({
					afterEnd: function() {				
						checkCarouselPosition();
					},
					btnNext: '.carousel-next',
					btnPrev: '.carousel-prev',
					circular: false,
					scroll: 10,
					speed: 350,
					visible: 10
				});
				
				carouselButtonNext = $('button.carousel-next');
				carouselButtonPrev = $('button.carousel-prev');
								
				var carouselLeft = $('.thumbnails-nav', $galleryNav).offset().left - carouselOffset,
					carouselRight = $('.thumbnails-nav', $galleryNav).width();
				
				function checkCarouselPosition() {
					if(parseInt($('.thumbnails-nav li.active').offset().left - carouselOffset) >= carouselRight) {
						if(!$('button.carousel-next').is('.button-disabled')) {
							carouselButtonNext.click();	
						}
						
					} else if(parseInt($('.thumbnails-nav li.active').offset().left - carouselOffset) < carouselLeft) {
						carouselButtonPrev.click();
					}
				}
				
				/* Run Gallery */
				$gallery.addClass('slideshow');
				$('.slideshow-nav .max', $galleryNav).text($('> li', $items).length);
				
				togglePrevNextButtons();
				
				function resetInterval() {
					clearInterval(runGallery);
					
					if($gallery.is('.slideshow')) {
						runGallery = setInterval(rotateNext, 7000);
					}
				}
				
				$('#main-photo ul li').each(function(){
					var img = $(this).find('img');
					$(this).find('span.full').css('backgroundImage','url('+img.attr('src')+')');
					img.remove();
				});
								
				resetInterval();
				
				// ADDON BC fix for link
				jQuery("div#gallery li").each(function(){
					// <span class="galleryLinkHolder">{tag_gallery link}</span>
					var link = jQuery(this).find(".galleryLinkHolder").html()
					jQuery(this).find("a.galleryLink").attr("href",link);
				
				});
				
				/* list view
				<li>	
					<span class="description">
					Caption: <em>{tag_caption}</em><br />
					Category: <em class="category">{tag_category}</em><br />
					<a href="{tag_gallery link}">{tag_gallery link text}</a>
					<span class="galleryLinkHolder">{tag_gallery link}</span>
					</span>
					<span class="thumb"><img alt="" src="{tag_image_value}?action=thumbnail&amp;width=85&amp;height=61" /></span>
					<span class="full"><img alt="" width="850" height="607" src="{tag_image_value}" /></span>
				</li>
					
				*/
				
				
				
				
			}
		},
		fixes : {
			ie6 : function() {
				if(!$.browser.msie || $.browser.version !== '6.0') {
					return; 
				}
				
				$('#nav li')
					.hover(
						function(){ $(this).addClass('hover'); },
						function(){ $(this).removeClass('hover'); }
					)
					.filter(':has(ul)')
						.addClass('dropdown');
				
				$('#footer .nav li:first-child').addClass('first');
			},
			lastChild : function() {
				$('.comments-a .comment:last-child').addClass('comment-last');
			}
		},
		
		tweaks : {
			homeBlogPosts : function(){
				$("ol.blogsitesummary li").addClass("news-a");
			}, // homeBlogPosts
			
			tweets : function(){
			  if ($('#tweets').size() === 0) { return;}
			
				$('#tweets').twit('Tribevita', {
				  limit: 5
				});
			},// tweets
			
			myAccount : function(){
				jQuery("dl.sneak-peek-list").each(function(){ // add link to thumb from button list view
					link = jQuery(this).find("dd a:last").attr("href");
					jQuery(this).find("dd.image-a img").wrap("<a href='"+link+"'></a>")
				});	
				
				if(window.location.href.indexOf("_webapp_") != -1){ // hide info on gallery
					jQuery("p.slideshow-nav a.info").hide();
					//jQuery("button.carousel-next, button.carousel-prev").hide();
				}
				
				if(jQuery("div#isLoggedIn").text() == "1"){ // is logged in
					jQuery("p.client-logged").show();
					jQuery("p.client-login").hide();
				}
				
				// order page
				$("div.invoices-a li").each(function(){
				var total = $(this).find("span.invoiceTotal").text();
				var total = total.substring(1);
				
				var actualPaid = $(this).find("span.actualPaid").text();
				var actualPaid = actualPaid.substring(1);
				
				var invoice = $(this).find("span.first").text();
				
				if(actualPaid < total ){
				
					var remainingBalance = total - actualPaid;
					$(this).find("span.actionItem").html("<a href='/my-account/pay-invoice?invoice="+invoice+"&total="+remainingBalance+"'>Pay Invoice</a>");
					}
				
				});	

				
				
			},//myAccount
			
			faq : function(){
				jQuery("div.frequently-asked-questions div.faq-item").each(function(){
					// this controls the sliding faqs on product pages.
					jQuery(this).find("a").click(function(){
					   jQuery(this).closest("div.frequently-asked-questions div.faq-item").find("p.faq-a").slideToggle(100);
						return false;
					})
				});
	
			},// faq
			
			products : function(){
				if(jQuery("div.service-detail-intro").length > 0) {
					jQuery("div.cat-description").hide();	   
				}
				
				// output related products - snag markup
				jQuery("div.relatedProdz table.productTable td.productItem").each(function(){
					var html = jQuery(this).html();
					jQuery("div.relatedProdzContainer").append(html);
					Cufon.replace('.service-a dt a', { fontFamily: 'Museo 300', hover: true });
					
				});

	
			},
			
			
			navClassHack : function(){
				// BC has an issue with classes and hovers in navs
				// but not any more ;)
				$('#nav li').each(function() {
					$(this).get(0).onmouseout = function() {};
					$(this).get(0).onmouseover = function() {};
				});
	
			},
			
			lastClass : function(){
				// so we can kill the border on last li items
				if(jQuery(".list-d ul").length > 0){
					jQuery(".list-d ul").each(function(){
						jQuery(this).find("li:last").css("border-bottom","0px");
					});
				}
			},
			
			homepageSlider : function(){
				
				if(jQuery("div.slideshow").size() === 0){ return; }
				jQuery('.slideshow').after('<div id="slidenav">')
				jQuery(".loader  img").css("display", "none");
				
				jQuery(document).ready(function() {
					jQuery('#slideshow').css("display", "block");		
					jQuery('.slideshow').cycle({
						fx: 'fade',
						timeout: 8000,
						pager: '#slidenav',
						speed: 500,
						pagerEvent: 'click',
						pauseOnPagerHover: true,
						cleartypeNoBg: true,
						pause: 1 });
					jQuery('.slideshow').css("display", "block");
					jQuery('#slidenav').css("display", "block");
				 });
					
			},
			
			blogPaginationHide : function(){
                    //kills silly 1 on blog pagination
                    if(jQuery("span#pagination").length > 0){
                         if(jQuery("span#pagination").text() == " 1 "){
                              jQuery("span#pagination").hide();
                         }
                    }
               }

			
		}
	};

	Engine.utils.links();
	Engine.utils.mails();
	Engine.fixes.ie6();
	Engine.fixes.lastChild();
	Engine.enhancements.labels();
	Engine.enhancements.gallery();
	Engine.enhancements.homeRotator();
	
	Engine.tweaks.homeBlogPosts();
	Engine.tweaks.tweets();
	Engine.tweaks.myAccount();
	Engine.tweaks.faq();
	Engine.tweaks.products();
	Engine.tweaks.navClassHack();
	Engine.tweaks.homepageSlider();
	Engine.tweaks.lastClass();

	
});
