// TipTip / Copyright 2010 Drew Wilson / www.drewwilson.com / code.drewwilson.com/entry/tiptip-jquery-plugin / Version 1.3 - Updated: Mar. 23, 2010 / Dual licensed under the MIT and GPL licenses
(function($){$.fn.tipTip=function(options){var defaults={activation:"hover",keepAlive:false,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:false,enter:function(){},exit:function(){}};var opts=$.extend(defaults,options);if($("#tiptip_holder").length<=0){var tiptip_holder=$('<div id="tiptip_holder" style="max-width:'+opts.maxWidth+';"></div>');var tiptip_content=$('<div id="tiptip_content"></div>');var tiptip_arrow=$('<div id="tiptip_arrow"></div>');$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')))}else{var tiptip_holder=$("#tiptip_holder");var tiptip_content=$("#tiptip_content");var tiptip_arrow=$("#tiptip_arrow")}return this.each(function(){var org_elem=$(this);if(opts.content){var org_title=opts.content}else{var org_title=org_elem.attr(opts.attribute)}if(org_title!=""){if(!opts.content){org_elem.removeAttr(opts.attribute)}var timeout=false;if(opts.activation=="hover"){org_elem.hover(function(){active_tiptip()},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}else if(opts.activation=="focus"){org_elem.focus(function(){active_tiptip()}).blur(function(){deactive_tiptip()})}else if(opts.activation=="click"){org_elem.click(function(){active_tiptip();return false}).hover(function(){},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}function active_tiptip(){opts.enter.call(this);tiptip_content.html(org_title);tiptip_holder.hide().removeAttr("class").css("margin","0");tiptip_arrow.removeAttr("style");var top=parseInt(org_elem.offset()['top']);var left=parseInt(org_elem.offset()['left']);var org_width=parseInt(org_elem.outerWidth());var org_height=parseInt(org_elem.outerHeight());var tip_w=tiptip_holder.outerWidth();var tip_h=tiptip_holder.outerHeight();var w_compare=Math.round((org_width-tip_w)/2);var h_compare=Math.round((org_height-tip_h)/2);var marg_left=Math.round(left+w_compare);var marg_top=Math.round(top+org_height+opts.edgeOffset);var t_class="";var arrow_top="";var arrow_left=Math.round(tip_w-12)/2;if(opts.defaultPosition=="bottom"){t_class="_bottom"}else if(opts.defaultPosition=="top"){t_class="_top"}else if(opts.defaultPosition=="left"){t_class="_left"}else if(opts.defaultPosition=="right"){t_class="_right"}var right_compare=(w_compare+left)<parseInt($(window).scrollLeft());var left_compare=(tip_w+left)>parseInt($(window).width());if((right_compare&&w_compare<0)||(t_class=="_right"&&!left_compare)||(t_class=="_left"&&left<(tip_w+opts.edgeOffset+5))){t_class="_right";arrow_top=Math.round(tip_h-13)/2;arrow_left=-12;marg_left=Math.round(left+org_width+opts.edgeOffset);marg_top=Math.round(top+h_compare)}else if((left_compare&&w_compare<0)||(t_class=="_left"&&!right_compare)){t_class="_left";arrow_top=Math.round(tip_h-13)/2;arrow_left=Math.round(tip_w);marg_left=Math.round(left-(tip_w+opts.edgeOffset+5));marg_top=Math.round(top+h_compare)}var top_compare=(top+org_height+opts.edgeOffset+tip_h+8)>parseInt($(window).height()+$(window).scrollTop());var bottom_compare=((top+org_height)-(opts.edgeOffset+tip_h+8))<0;if(top_compare||(t_class=="_bottom"&&top_compare)||(t_class=="_top"&&!bottom_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_top"}else{t_class=t_class+"_top"}arrow_top=tip_h;marg_top=Math.round(top-(tip_h+5+opts.edgeOffset))}else if(bottom_compare|(t_class=="_top"&&bottom_compare)||(t_class=="_bottom"&&!top_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_bottom"}else{t_class=t_class+"_bottom"}arrow_top=-12;marg_top=Math.round(top+org_height+opts.edgeOffset)}if(t_class=="_right_top"||t_class=="_left_top"){marg_top=marg_top+5}else if(t_class=="_right_bottom"||t_class=="_left_bottom"){marg_top=marg_top-5}if(t_class=="_left_top"||t_class=="_left_bottom"){marg_left=marg_left+5}tiptip_arrow.css({"margin-left":arrow_left+"px","margin-top":arrow_top+"px"});tiptip_holder.css({"margin-left":marg_left+"px","margin-top":marg_top+"px"}).attr("class","tip"+t_class);if(timeout){clearTimeout(timeout)}timeout=setTimeout(function(){tiptip_holder.stop(true,true).fadeIn(opts.fadeIn)},opts.delay)}function deactive_tiptip(){opts.exit.call(this);if(timeout){clearTimeout(timeout)}tiptip_holder.fadeOut(opts.fadeOut)}}})}})(jQuery);

// jQuery Tools 1.2.5 / [tabs, toolbox.history] / Generated: Mon Oct 25 03:51:29 GMT 2010
(function(c){function p(d,b,a){var e=this,l=d.add(this),h=d.find(a.tabs),i=b.jquery?b:d.children(b),j;h.length||(h=d.children());i.length||(i=d.parent().find(b));i.length||(i=c(b));c.extend(this,{click:function(f,g){var k=h.eq(f);if(typeof f=="string"&&f.replace("#","")){k=h.filter("[href*="+f.replace("#","")+"]");f=Math.max(h.index(k),0)}if(a.rotate){var n=h.length-1;if(f<0)return e.click(n,g);if(f>n)return e.click(0,g)}if(!k.length){if(j>=0)return e;f=a.initialIndex;k=h.eq(f)}if(f===j)return e;
g=g||c.Event();g.type="onBeforeClick";l.trigger(g,[f]);if(!g.isDefaultPrevented()){o[a.effect].call(e,f,function(){g.type="onClick";l.trigger(g,[f])});j=f;h.removeClass(a.current);k.addClass(a.current);return e}},getConf:function(){return a},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return e.click(j+1)},prev:function(){return e.click(j-1)},destroy:function(){h.unbind(a.event).removeClass(a.current);
i.find("a[href^=#]").unbind("click.T");return e}});c.each("onBeforeClick,onClick".split(","),function(f,g){c.isFunction(a[g])&&c(e).bind(g,a[g]);e[g]=function(k){k&&c(e).bind(g,k);return e}});if(a.history&&c.fn.history){c.tools.history.init(h);a.event="history"}h.each(function(f){c(this).bind(a.event,function(g){e.click(f,g);return g.preventDefault()})});i.find("a[href^=#]").bind("click.T",function(f){e.click(c(this).attr("href"),f)});if(location.hash&&a.tabs=="a"&&d.find("[href="+location.hash+"]").length)e.click(location.hash);
else if(a.initialIndex===0||a.initialIndex>0)e.click(a.initialIndex)}c.tools=c.tools||{version:"1.2.5"};c.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:false,history:false},addEffect:function(d,b){o[d]=b}};var o={"default":function(d,b){this.getPanes().hide().eq(d).show();b.call()},fade:function(d,b){var a=this.getConf(),e=a.fadeOutSpeed,l=this.getPanes();e?l.fadeOut(e):l.hide();l.eq(d).fadeIn(a.fadeInSpeed,b)},slide:function(d,
b){this.getPanes().slideUp(200);this.getPanes().eq(d).slideDown(400,b)},ajax:function(d,b){this.getPanes().eq(0).load(this.getTabs().eq(d).attr("href"),b)}},m;c.tools.tabs.addEffect("horizontal",function(d,b){m||(m=this.getPanes().eq(0).width());this.getCurrentPane().animate({width:0},function(){c(this).hide()});this.getPanes().eq(d).animate({width:m},function(){c(this).show();b.call()})});c.fn.tabs=function(d,b){var a=this.data("tabs");if(a){a.destroy();this.removeData("tabs")}if(c.isFunction(b))b=
{onBeforeClick:b};b=c.extend({},c.tools.tabs.conf,b);this.each(function(){a=new p(c(this),d,b);c(this).data("tabs",a)});return b.api?a:this}})(jQuery);
(function(b){function h(c){if(c){var a=d.contentWindow.document;a.open().close();a.location.hash=c}}var g,d,f,i;b.tools=b.tools||{version:"1.2.5"};b.tools.history={init:function(c){if(!i){if(b.browser.msie&&b.browser.version<"8"){if(!d){d=b("<iframe/>").attr("src","javascript:false;").hide().get(0);b("body").append(d);setInterval(function(){var a=d.contentWindow.document;a=a.location.hash;g!==a&&b.event.trigger("hash",a)},100);h(location.hash||"#")}}else setInterval(function(){var a=location.hash;
a!==g&&b.event.trigger("hash",a)},100);f=!f?c:f.add(c);c.click(function(a){var e=b(this).attr("href");d&&h(e);if(e.slice(0,1)!="#"){location.href="#"+e;return a.preventDefault()}});i=true}}};b(window).bind("hash",function(c,a){a?f.filter(function(){var e=b(this).attr("href");return e==a||e==a.replace("#","")}).trigger("history",[a]):f.eq(0).trigger("history",[a]);g=a});b.fn.history=function(c){b.tools.history.init(this);return this.bind("history",c)}})(jQuery);

// jQuery Tools 1.2.5 - [tooltip, tooltip.slide, tooltip.dynamic] / Generated: Wed Sep 22 07:14:08 GMT 2010
// Warning, hardcoded: else{e.addClass('tip_top')}
(function(f){function p(a,b,c){var h=c.relative?a.position().top:a.offset().top,d=c.relative?a.position().left:a.offset().left,i=c.position[0];h-=b.outerHeight()-c.offset[0];d+=a.outerWidth()+c.offset[1];if(/iPad/i.test(navigator.userAgent))h-=f(window).scrollTop();var j=b.outerHeight()+a.outerHeight();if(i=="center")h+=j/2;if(i=="bottom")h+=j;i=c.position[1];a=b.outerWidth()+a.outerWidth();if(i=="center")d-=a/2;if(i=="left")d-=a;return{top:h,left:d}}function u(a,b){var c=this,h=a.add(c),d,i=0,j=
0,m=a.attr("title"),q=a.attr("data-tooltip"),r=o[b.effect],l,s=a.is(":input"),v=s&&a.is(":checkbox, :radio, select, :button, :submit"),t=a.attr("type"),k=b.events[t]||b.events[s?v?"widget":"input":"def"];if(!r)throw'Nonexistent effect "'+b.effect+'"';k=k.split(/,\s*/);if(k.length!=2)throw"Tooltip: bad events configuration for "+t;a.bind(k[0],function(e){clearTimeout(i);if(b.predelay)j=setTimeout(function(){c.show(e)},b.predelay);else c.show(e)}).bind(k[1],function(e){clearTimeout(j);if(b.delay)i=
setTimeout(function(){c.hide(e)},b.delay);else c.hide(e)});if(m&&b.cancelDefault){a.removeAttr("title");a.data("title",m)}f.extend(c,{show:function(e){if(!d){if(q)d=f(q);else if(b.tip)d=f(b.tip).eq(0);else if(m)d=f(b.layout).addClass(b.tipClass).appendTo(document.body).hide().append(m);else{d=a.next();d.length||(d=a.parent().next())}if(!d.length)throw"Cannot find tooltip for "+a;}if(c.isShown())return c;d.stop(true,true);var g=p(a,d,b);b.tip&&d.html(a.data("title"));e=e||f.Event();e.type="onBeforeShow";
h.trigger(e,[g]);if(e.isDefaultPrevented())return c;g=p(a,d,b);d.css({position:"absolute",top:g.top,left:g.left});l=true;r[0].call(c,function(){e.type="onShow";l="full";h.trigger(e)});g=b.events.tooltip.split(/,\s*/);if(!d.data("__set")){d.bind(g[0],function(){clearTimeout(i);clearTimeout(j)});g[1]&&!a.is("input:not(:checkbox, :radio), textarea")&&d.bind(g[1],function(n){n.relatedTarget!=a[0]&&a.trigger(k[1].split(" ")[0])});d.data("__set",true)}return c},hide:function(e){if(!d||!c.isShown())return c;
e=e||f.Event();e.type="onBeforeHide";h.trigger(e);if(!e.isDefaultPrevented()){l=false;o[b.effect][1].call(c,function(){e.type="onHide";h.trigger(e)});return c}},isShown:function(e){return e?l=="full":l},getConf:function(){return b},getTip:function(){return d},getTrigger:function(){return a}});f.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(e,g){f.isFunction(b[g])&&f(c).bind(g,b[g]);c[g]=function(n){n&&f(c).bind(g,n);return c}})}f.tools=f.tools||{version:"1.2.5"};f.tools.tooltip=
{conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,b,c){o[a]=[b,c]}};var o={toggle:[function(a){var b=this.getConf(),c=this.getTip();b=b.opacity;b<1&&c.css({opacity:b});c.show();a.call()},function(a){this.getTip().hide();
a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};f.fn.tooltip=function(a){var b=this.data("tooltip");if(b)return b;a=f.extend(true,{},f.tools.tooltip.conf,a);if(typeof a.position=="string")a.position=a.position.split(/,?\s/);this.each(function(){b=new u(f(this),a);f(this).data("tooltip",b)});return a.api?b:this}})(jQuery);
(function(d){var i=d.tools.tooltip;d.extend(i.conf,{direction:"up",bounce:false,slideOffset:10,slideInSpeed:200,slideOutSpeed:200,slideFade:!d.browser.msie});var e={up:["-","top"],down:["+","top"],left:["-","left"],right:["+","left"]};i.addEffect("slide",function(g){var a=this.getConf(),f=this.getTip(),b=a.slideFade?{opacity:a.opacity}:{},c=e[a.direction]||e.up;b[c[1]]=c[0]+"="+a.slideOffset;a.slideFade&&f.css({opacity:0});f.show().animate(b,a.slideInSpeed,g)},function(g){var a=this.getConf(),f=a.slideOffset,
b=a.slideFade?{opacity:0}:{},c=e[a.direction]||e.up,h=""+c[0];if(a.bounce)h=h=="+"?"-":"+";b[c[1]]=h+"="+f;this.getTip().animate(b,a.slideOutSpeed,function(){d(this).hide();g.call()})})})(jQuery);
(function(g){function j(a){var c=g(window),d=c.width()+c.scrollLeft(),h=c.height()+c.scrollTop();return[a.offset().top<=c.scrollTop(),d<=a.offset().left+a.width(),h<=a.offset().top+a.height(),c.scrollLeft()>=a.offset().left]}function k(a){for(var c=a.length;c--;)if(a[c])return false;return true}var i=g.tools.tooltip;i.dynamic={conf:{classNames:"top right bottom left"}};g.fn.dynamic=function(a){if(typeof a=="number")a={speed:a};a=g.extend({},i.dynamic.conf,a);var c=a.classNames.split(/\s/),d;this.each(function(){var h=
g(this).tooltip().onBeforeShow(function(e,f){e=this.getTip();var b=this.getConf();d||(d=[b.position[0],b.position[1],b.offset[0],b.offset[1],g.extend({},b)]);g.extend(b,d[4]);b.position=[d[0],d[1]];b.offset=[d[2],d[3]];e.css({visibility:"hidden",position:"absolute",top:f.top,left:f.left}).show();f=j(e);if(!k(f)){if(f[2]){g.extend(b,a.top);b.position[0]="top";e.addClass(c[0])}if(f[3]){g.extend(b,a.right);b.position[1]="right";e.addClass(c[1])}if(f[0]){g.extend(b,a.bottom);b.position[0]="bottom";e.addClass(c[2])}if(f[1]){g.extend(b,
a.left);b.position[1]="left";e.addClass(c[3])}if(f[0]||f[2])b.offset[0]*=-1;if(f[1]||f[3])b.offset[1]*=-1}else{e.addClass('tip_top')}e.css({visibility:"visible"}).hide()});h.onBeforeShow(function(){var e=this.getConf();this.getTip();setTimeout(function(){e.position=[d[0],d[1]];e.offset=[d[2],d[3]]},0)});h.onHide(function(){var e=this.getTip();e.removeClass(a.classNames)});ret=h});return a.api?ret:this}})(jQuery);

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

// externalise plugin / @author Shawn Drew / @copyright 2010 / @version 0.3 / @url http://shaztronics.com
(function($){$.fn.externalise=function(options){$.fn.externalise.defaults={target:'_blank',addClass:false,callback:false,onClick:false};var opts=$.extend({},$.fn.externalise.defaults,options);var inChain=!$.isFunction(this);var validCallback=$.isFunction(opts.callback);var validOnClick=$.isFunction(opts.onClick);var elements=inChain?this:$('a[href^="http://"]').filter('a:not([href*="'+window.location.href.split('/')[2]+'"])');$(elements).each(function(){$(this).attr('target',opts.target);if(opts.addClass!==false)$(this).addClass(opts.addClass);if(validCallback)opts.callback(this);if(validOnClick)$(this).click(function(e){return opts.onClick(this)})});if(inChain)return this};$.externalise=$.fn.externalise})(jQuery);

// simple fade plugin / @author Shawn Drew / @copyright 2010 / @version 0.1 / @url http://shaztronics.com / @credit http://snook.ca/archives/javascript/simplest-jquery-slideshow
(function($){$.fn.simpleFade=function(options){$.fn.simpleFade.defaults={interval:5000,fadeSpeed:'normal'};var opts=$.extend({},$.fn.simpleFade.defaults,options);return $(this).each(function(){var el=$(this);$(this).children(':gt(0)').hide();setInterval(function(){el.children().eq(0).fadeOut(opts.fadeSpeed).next().fadeIn(opts.fadeSpeed).end().appendTo(el)},opts.interval)})}})(jQuery);

/**
 * pager plugin
 *
 * @author Shawn Drew
 * @copyright 2010
 * @version 0.2
 * @url http://shaztronics.com
 */

(function($){

$.fn.pager = function(options){

    $.fn.pager.defaults = {
		pageSize: 10
    };
	
    var opts = $.extend({}, $.fn.pager.defaults, options);
	
	return $(this).each(function() {
	
		var container = $(this);
		var items = $(this).children();
		var pages = Math.ceil($(items).size()/opts.pageSize);
		
		if (pages > 1) {
		
			// Classify items
			$(items).each(function(index) {
			
				var page = Math.ceil((index+1)/opts.pageSize);
				
				$(this).addClass('pager-page-'+page);
			
			});
		
			// Generate navigation
		
			var nav = '<li><a href="#" class="prev">Prev</a></li>';
			var i = 0;
			
			while (i < pages) {
			
				i++;
				nav += '<li><a href="#" class="pager-link">'+i+'</a></li>';
			
			}

			$(container).after('<ul class="pager-nav">'+nav+'<li><a href="#" class="next">Next</a></li></ul>');
			$('#portfolio-pages').css('display', 'block').append('<ul class="pager-nav secondary clearfix">'+nav+'<li><a href="#" class="next">Next</a></li></ul>');
			
			
			// Highlight
			$('.pager-nav .pager-link:first').addClass('current');
			
			$('.pager-nav .pager-link').click(function(e) {
			
				e.preventDefault();
				
				$(items).addClass('hidden');
				
				$(container).find('.pager-page-'+$(this).text()).removeClass('hidden');
				
				$('.pager-nav .pager-link').removeClass('current');
				
				var currentPage = parseInt($(this).text());
				
				$('.pager-nav').each(function() {
				
					$(this).find('.pager-link:eq('+(currentPage-1)+')').addClass('current');
				
				});
				
				$('.pager-nav .disabled').removeClass('disabled');
				
				
				if (currentPage == 1) {
				
					$('.pager-nav .prev').addClass('disabled');
				
				}
				
				if (currentPage == pages) {
				
					$('.pager-nav .next').addClass('disabled');
				
				}
				
				$.scrollTo(0, 250);
			
			});
			
			$('.pager-nav .next').click(function(e) {
			
				e.preventDefault();
				
				var currentPage = parseInt($('.pager-nav:first .current').text());
				
				if (currentPage < pages) {
				
					$('.pager-nav .pager-link:eq('+currentPage+')').click();
				
				}
			
			});
			
			$('.pager-nav .prev').click(function(e) {
			
				e.preventDefault();
				
				var currentPage = parseInt($('.pager-nav:first .current').text());
				
				if (currentPage > 1) {
				
					//console.log();
					$('.pager-nav:first .pager-link:eq('+(currentPage-2)+')').click();
				
				}
			
			});
		
			// Start on the first page
			$('.pager-nav:first .pager-link:eq(0)').click();
		
		}
		
    });

  
};

})(jQuery);

(function($){

$.fn.cmgSlider = function(options) {

    $.fn.cmgSlider.defaults = {
		secondarySlides: '#secondary',
		prev: '#prev',
		next: '#next',
		autoPlay: true,
		interval: 5000
    };
	
    var opts = $.extend({}, $.fn.cmgSlider.defaults, options);
	var primary = $(this);
	var secondary = $(opts.secondarySlides);
	var prev = $(opts.prev);
	var next = $(opts.next);
	var msgQuote = $('#message-and-quote');
	var slideCount = $(primary).find('li').size();
	var currentSlide = 1;
	var timeOut = null;
	
	if (slideCount > 1) {
	
		var toSlide = function(index, isAuto) {
			
			if (!$(msgQuote).is(':animated')) {	
		
				if (index > slideCount) {
				
					index = 1;
				
				}
				
				if (index < 1) {
				
					index = slideCount;
				
				}
			
				$(primary).find('li:eq('+(currentSlide-1)+')').fadeOut(1250);
				$(primary).find('li:eq('+(index-1)+')').fadeIn(1250);
				
				$(msgQuote).animate({width: 652}, 550, function() {
										
					$(secondary).find('li').addClass('hidden');
					$(secondary).find('li:eq('+(index-1)+')').removeClass('hidden');
		
					$(msgQuote).animate({width: 942}, 550, function() {
										
						// Chirstmas Switcher
						/*
						var ani = $('#home-animation-container');						
						$(ani).find('img:first').addClass('hidden').appendTo(ani);
						$(ani).find('img:first').removeClass('hidden');
						*/
					
					});
				});
				
				currentSlide = index;
				
				if (opts.autoPlay && isAuto) {
				
					timeOut = setTimeout(function(){
						toSlide(currentSlide+1, true);
					}, opts.interval);
				
				
				} else {
				
					clearTimeout(timeOut);
					
					if (opts.autoPlay) {					
					
						timeOut = setTimeout(function(){
							toSlide(currentSlide+1, true);
						}, opts.interval);
					
					}
				
				}
				
			}
		
		}
		
		$(next).click(function(e) {
		
			e.preventDefault();
			
			toSlide(currentSlide+1);
		
		});
		
		$(prev).click(function(e) {
		
			e.preventDefault();
			
			toSlide(currentSlide-1);
		
		});
		
		if (opts.autoPlay) {
		
			timeOut = setTimeout(function(){
				toSlide(currentSlide+1, true);
			}, opts.interval);
		
		
		}
	
	}
  
};

})(jQuery);

String.prototype.endsWith = function(str) {
	var lastIndex = this.lastIndexOf(str);
	return (lastIndex != -1) && (lastIndex + str.length == this.length);
}

String.prototype.startsWith = function(str, strict) {
	var index = this.indexOf(str);
//console.log(index, strict, str.length <= this.length, this, str);
	return (index != -1) && (index === 0) && (strict ? str.length <= this.length : true);
}

 /*
 * Main JS Code
 * Copyright 2011, Shawn Drew
 */
$(document).ready(function() {

	// Highlight Current Nav Items
	var url = window.location+'';
	var specialSections = ['/_blog/Blog/', '/_blog/Articles/', '/_blog/News/', '/_webapp_'];
	
	$('#main-nav li a, #col-a .side-nav a').each(function() {
	
		var link = $(this);

		if (window.location.pathname === $(this).attr('href')) {

			$(this).parent().addClass("current");

		}

	});
	
	// Highlight special sections with sub pages like blogs
	$(specialSections).each(function(i, section) {
	
		if (url.indexOf(section) > 0) {
		
			$("#col-a .side-nav a[href='"+section+"']").parent().addClass('current');
			
			// Fix content headers for all blog based sections
			if (section.indexOf('/_blog/') === 0) {
			
				var filename = section.split('/')[2].toLowerCase()+'.jpg';
				$('.blog-container').prepend('<img width="702" height="210" class="content-banner" alt="welcome to the digital age" src="/img/media/header/'+filename+'" />');
			
				// Add success url to blog comment forms
				
				$('.blog-post-comment-form').each(function() {
				
					$(this).attr('action', $(this).attr('action')+'&PageID=/comment-thank-you-'+filename.replace('.jpg', ''));
				
				});
			
			}
			
			if (section == '/_webapp_') {
			
				highlightSideNav('/in-the-press');
			
			}
			
			return false; // break out early on success
		
		}
	
	});
	
	var moreInfoPages = {
		'seo': '/seo-explained',
		'consulting': '/consulting-explained',
		'branding': '/branding-and-positioning',
		'website-design': '/website-design-explained',
		'website-development': '/website-development-explained'
	};
	
	$.each(moreInfoPages, function(i, moreInfo) {
		
		if (window.location.pathname === moreInfo) {
		
			highlightSideNav('/'+i);
		
		}
	
	});
	
	removeBorderAboveCurrentLink();
	
	// Highlight main menu based on first sidenav menu
	$("#main-nav a[href='"+$('#col-a .side-nav a:first').attr('href')+"']").parent().addClass('current');
	
	// External Links
	$.externalise();
	
	// Homepage
	if ($('body').is('.home')) {
	
		// slider / quote switcher
		$(".tiptip").tipTip({defaultPosition: "top", delay: 150});
		
		$("#screenshot ul").cmgSlider({secondarySlides: "#quote ul", prev: '#showcase-back', next: '#showcase-forward'});
	
	}
	
	// This will eventually be removed as it is replaced with flash? Or will this be kept as a backup?
	$('a.fancy-button')
		.css( {backgroundPosition: "0 0"} )
	.mouseover(function(){
		$(this).find('.overlay').fadeOut(150);
		$(this).stop().animate({backgroundPosition: "-400px 0"}, 600)
	})
	.mouseout(function(){
		$(this).stop().animate({backgroundPosition: "-0px 0"}, 400, 'linear', function(){
			$(this).find('.overlay').fadeIn(450);
		})
	});

	var folio = $('#portfolio2');
	
	if (folio.size() === 1) {
	
		folio.pager({pageSize: 10});
	
	}
	
	portfolio();
	
	if ($('#client-list').size() === 1) {
	
		clients();
	
	}

	var formtabs = $('#form-tabs');
	
	if (formtabs.size() === 1) {
	
		formtabs.tabs("#contact-forms > li", { history: true, effect: 'fade'});
	
	}
	
	matchContentToSidebarIfSmaller();

	setTimeout('matchContentToSidebarIfSmaller()', 1000);


	// What type of page are we on?
	var readingtime = $('h1');
	var skipReadingCalculation = true;

	if ($(readingtime).size() === 1 && $(readingtime).next().is('.intro')) {

		skipReadingCalculation = false;

	} else {
		
		if (url.indexOf('/_webapp_') > 0) {
		
			// In the Press
			skipReadingCalculation = false;
		
		} else if (url.indexOf('/_blog/') > 0) {
		
			// Blog Posts
			$('.blog-post .post-title').each(function() {
			
				initReadingTimeCalculator($(this));
			
			});
		
		}
	
	}

	if (!skipReadingCalculation) {

		initReadingTimeCalculator($(readingtime));
		
	}

});

function initReadingTimeCalculator(readingtime) {

	var output = '';

	var wordCount = approximateWordCount($(readingtime).parent().text());
	var minutesToReadInDecimal = calculateMinutesToReadBasedOnWordCount(wordCount, 215);
	var readingTimeParts = String(minutesToReadInDecimal).split('.');

	var minutes = parseInt(readingTimeParts[0]);
	var seconds = Math.round(parseFloat('0.'+readingTimeParts[1])*60);
	
	var minuteLabel = 'mins';
	
	if (seconds > 0) {
	
		output += ' '+seconds+'sec';
	
	}
	
	if (minutes === 1) {
	
		minuteLabel = 'min';	
	
	}
	
	if (minutes > 0) {
	
		output = minutes+minuteLabel+output;
	
	}
	
	$(readingtime).addClass('reading-time').append('<span>Approx. reading time: '+output+' </span>');

}

function approximateWordCount(text) {

	return text.replace(/\s{2,}/g,' ').split(' ').length;

}

function calculateMinutesToReadBasedOnWordCount(wordCount, speedPerMin) {

	return wordCount/speedPerMin;

}

function matchContentToSidebarIfSmaller() {

	var mainContent = $('#col-b.sidebar');

	var sidebarHeight = $('#col-a.sidebar').outerHeight(true);
	var mainContentHeight = $(mainContent).outerHeight(true);

	if (sidebarHeight !== null && mainContentHeight !== null && mainContentHeight < sidebarHeight) {

		//var paddingMarginBorder = mainContentHeight - $('#col-b.sidebar').height();
		var contentArea = $(mainContent).find('.content:first');
		var newHeight = $(contentArea).height() + (sidebarHeight - mainContentHeight);

		$(contentArea).css('min-height', newHeight);

	}

}

function removeBorderAboveCurrentLink() {

	$('.side-nav li.current').prev().addClass('before-current');

}

function highlightSideNav(link) {

	$(".side-nav a[href='"+link+"']").parent().addClass('current');

	removeBorderAboveCurrentLink();

}

function formCheck(form) {

	var frm = $('#catwebformform'+form);
	var why = "";
	
	var fullname = $(frm).find('input[name=FullName]');
	var email = $(frm).find('input[name=EmailAddress]');
	var emailVal = $(email).val();
	var emailError = '- Please enter a valid email address';
	var emailPattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; // http://www.dustindiaz.com/update-your-email-regexp/
	
	if ($(fullname).size() === 1) why += isEmpty($(fullname).val(), "Name");
	
	if (!emailVal.length > 0 || !emailPattern.test(emailVal)) {
		why += emailError;
	}
	
	if (why != "") {
		alert(why);
		//return false;
	} else {
		$(frm).submit();
	}

}

function portfolio() {
	
	// check for hash	
	var category = $('#category');
	
	if (category.size() === 1) {
	
		// highlight current portfolio
		$(category).find('option[value="'+window.location.pathname+'"]').addClass('current').attr('selected', true);
		
		// go to another portfolio
		$(category).change(function() {
		
			window.location = $(category).find(':selected').eq(0).val();
		
		});
		
	}
	
	var defaultPortfolio = $(category).find('option:first').attr('value');
	
	if (window.location.pathname !== '/clients') {
	
		$('#main-nav a[href="'+defaultPortfolio+'"]').parent().addClass('current');
		
	}

}

function clients() {

	$(document).ready(function() {
	
		/* Tiptip Version
	
		$("#client-list li").each(function() {
	
			var info = $(this).find('.info');
	
			if (info.size() !== 1) {
				info = $(this).find('img').attr('alt');
			} else {
				info = info.html();
			}
	
			$(this).tipTip({defaultPosition: "top", delay: 150, content: info, fadeOut: 1200});
		
		});
		
		*/
		
		$("#client-list .info")
			.wrap('<div id="tiptip_holder"><div id="tiptip_content"></div></div>')
			.removeClass('hidden')
			.parent().prepend('<div id="tiptip_arrow"><div id="tiptip_arrow_inner"></div></div>');
		
		$("#client-list img").tooltip({
			effect: 'slide',
			position: 'top center'
		}).dynamic({
			classNames: 'tip_top tip_right tip_bottom tip_left',
			top: {position: ['top', 'center']},
			bottom: {position: ['bottom', 'center']},
			left: {position: ['center', 'left']},
			right: {position: ['center', 'right']}
		});
	}); //
	
}
