/*
 * Modernizr JavaScript library 1.1
 * http://modernizr.com/
 *
 * Copyright (c) 2009 Faruk Ates - http://farukat.es/
 * Licensed under the MIT license.
 * http://modernizr.com/license/
 *
 * Featuring major contributions by
 * Paul Irish  - http://paulirish.com
 * Ben Alman   - http://benalman.com/
 */
 window.Modernizr=(function(P,l){var _='1.1', J={},T=true,ab=true,M=100,ad=l.documentElement,U=l.createElement("modernizr"),k=U.style,Z=l.createElement("input"),o="canvas",Y="canvastext",V="rgba",g="hsla",Q="multiplebgs",x="borderimage",D="borderradius",v="boxshadow",X="opacity",B="cssanimations",R="csscolumns",a="cssgradients",p="cssreflections",h="csstransforms",w="csstransforms3d",aa="csstransitions",F="fontface",K="geolocation",e="video",A="audio",d="input",u=d+"types",N="background",b=N+"Color",G="canPlayType",H="localstorage",j="sessionstorage",C="webworkers",O="applicationcache",c=" -o- -moz- -ms- -webkit- ".split(" "),s={},z={},r={},q,S,W,L,n=[];function y(f){k.cssText=f}function E(i,f){return y(c.join(i+";")+(f||""))}function I(i,f){return i.indexOf(f)!==-1}function ac(m,ae){for(var f in m){if(k[m[f]]!==undefined&&(!ae||ae(m[f]))){return true}}}function t(ae,m){var i=ae.charAt(0).toUpperCase()+ae.substr(1),f=[ae,"webkit"+i,"Moz"+i,"moz"+i,"o"+i,"ms"+i];return !!ac(f,m)}s[o]=function(){return !!l.createElement(o).getContext};s[Y]=function(){return !!(s[o]()&&typeof l.createElement(o).getContext("2d").fillText=="function")};s[K]=function(){return !!navigator.geolocation};s[V]=function(){y(N+"-color:rgba(150,255,150,.5)");return I(k[b],V)};s[g]=function(){y(N+"-color:hsla(120,40%,100%,.5)");return I(k[b],V)};s[Q]=function(){y(N+":url(m.png),url(a.png),#f99 url(m.png)");return/(url\s*\(.*?){3}/.test(k[N])};s[x]=function(){return t("borderImage")};s[D]=function(){return t("borderRadius","",function(f){return I(f,"orderRadius")})};s[v]=function(){return t("boxShadow")};s[X]=function(){y("opacity:.5");return I(k[X],"0.5")};s[B]=function(){return t("animationName")};s[R]=function(){return t("columnCount")};s[a]=function(){var m=N+"-image:",i="gradient(linear,left top,right bottom,from(#9f9),to(white));",f="linear-gradient(left top,#9f9, white);";y(m+i+m+"-webkit-"+i+m+"-moz-"+i+m+"-o-"+i+m+"-ms-"+i+m+f+m+"-webkit-"+f+m+"-moz-"+f+m+"-o-"+f+m+"-ms-"+f);return I(k.backgroundImage,"gradient")};s[p]=function(){return t("boxReflect")};s[h]=function(){return !!ac(["transformProperty","webkitTransform","MozTransform","mozTransform","oTransform","msTransform"])};s[w]=function(){return !!ac(["perspectiveProperty","webkitPerspective","MozPerspective","mozPerspective","oPerspective","msPerspective"])};s[aa]=function(){return t("transitionProperty")};s[F]=(function(){var i;if(!(!/*@cc_on@if(@_jscript_version>=5)!@end@*/0)){i=true}else{var aj=l.createElement("style"),ae=l.createElement("span"),ak,af,ah=false,ag=l.body,ai,m;aj.textContent="@font-face{font-family:testfont;src:url('data:font/ttf;base64,AAEAAAAMAIAAAwBAT1MvMliohmwAAADMAAAAVmNtYXCp5qrBAAABJAAAANhjdnQgACICiAAAAfwAAAAEZ2FzcP//AAMAAAIAAAAACGdseWYv5OZoAAACCAAAANxoZWFk69bnvwAAAuQAAAA2aGhlYQUJAt8AAAMcAAAAJGhtdHgGDgC4AAADQAAAABRsb2NhAIQAwgAAA1QAAAAMbWF4cABVANgAAANgAAAAIG5hbWUgXduAAAADgAAABPVwb3N03NkzmgAACHgAAAA4AAECBAEsAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAACAAMDAAAAAAAAgAACbwAAAAoAAAAAAAAAAFBmRWQAAAAgqS8DM/8zAFwDMwDNAAAABQAAAAAAAAAAAAMAAAADAAAAHAABAAAAAABGAAMAAQAAAK4ABAAqAAAABgAEAAEAAgAuqQD//wAAAC6pAP///9ZXAwAAAAAAAAACAAAABgBoAAAAAAAvAAEAAAAAAAAAAAAAAAAAAAABAAIAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AGYAZgBlADUAMAAzADIAIAAtACAAcwB1AGIAcwBlAHQAIABvAGYAIABKAHUAcgBhAEwAaQBnAGgAdABoAHQAdABwADoALwAvAHMAYwByAGkAcAB0AHMALgBzAGkAbAAuAG8AcgBnAC8ATwBGAEwAAAAAAgAAAAAAAP+BADMAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAQACAQIAEQt6ZXJva2F5YWhsaQ==')}";l.getElementsByTagName("head")[0].appendChild(aj);ae.setAttribute("style","font:99px _,serif;position:absolute;visibility:hidden");if(!ag){ag=ad.appendChild(l.createElement(F));ah=true}ae.innerHTML="........";ae.id="fonttest";ag.appendChild(ae);ak=ae.offsetWidth;ae.style.font="99px testfont,_,serif";i=ak!==ae.offsetWidth;var f=function(){i=J[F]=ak!==ae.offsetWidth;ad.className=ad.className.replace(/(no-)?font.*?\b/,"")+(i?" ":" no-")+F;ai&&(m=true)&&ai(i);ah&&setTimeout(function(){ag.parentNode.removeChild(ag)},50)};setTimeout(f,M)}J._fontfaceready=function(al){(m||i)?al(i):(ai=al)};return function(){return i||ak!==ae.offsetWidth}})();s[e]=function(){var i=l.createElement(e),f=!!i[G];if(f){f=new Boolean(f);f.ogg=i[G]('video/ogg; codecs="theora, vorbis"');f.h264=i[G]('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')}return f};s[A]=function(){var i=l.createElement(A),f=!!i[G];if(f){f=new Boolean(f);f.ogg=i[G]('audio/ogg; codecs="vorbis"');f.mp3=i[G]("audio/mpeg3;");f.wav=i[G]('audio/wav; codecs="1"');f.m4a=i[G]("audio/x-m4a;")}return f};s[H]=function(){return"localStorage" in P};s[j]=function(){return"sessionStorage" in P};s[C]=function(){return !!P.Worker};s[O]=function(){return !!P.applicationCache};for(L in s){if(s.hasOwnProperty(L)){n.push((!(J[L]=s[L]())&&ab?"no-":"")+L)}}J.addTest=function(f,i){if(this.hasOwnProperty(f)){}i=!!(i());ad.className+=" "+(!i&&ab?"no-":"")+f;J[f]=i};J[d]=(function(m){for(var f in m){r[m[f]]=!!(m[f] in Z)}return r})("autocomplete autofocus list placeholder max min multiple pattern required step".split(" "));J[u]=(function(m){for(var f in m){Z.setAttribute("type",m[f]);z[m[f]]=!!(Z.type!=="text")}return z})("search tel url email datetime date month week time datetime-local number range color".split(" "));y("");U=Z=null;if(T&&!(!/*@cc_on!@*/0)){q="abbr article aside audio canvas datalist details eventsource figure footer header hgroup mark menu meter nav output progress section time video".split(" ");W=q.length+1;while(--W){S=l.createElement(q[W])}S=null}J._enableHTML5=T;J._enableNoClasses=ab;J._version=_;(function(f,i){f[i]=f[i].replace(/\bno-js\b/,"js")})(ad,"className");ad.className+=" "+n.join(" ");return J})(this,this.document);


/// Background-position extension
/**
 * @author Alexander Farkas
 * v. 1.21
 */

if (navigator.userAgent.indexOf("MSIE") == -1) {
	(function($) {
		if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
			var oldCurCSS = jQuery.curCSS;
			jQuery.curCSS = function(elem, name, force){
				if(name === 'background-position'){
					name = 'backgroundPosition';
				}
				if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
					return oldCurCSS.apply(this, arguments);
				}
				var style = elem.style;
				if ( !force && style && style[ name ] ){
					return style[ name ];
				}
				return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
			};
		}
		
		var oldAnim = $.fn.animate;
		$.fn.animate = function(prop){
			if('background-position' in prop){
				prop.backgroundPosition = prop['background-position'];
				delete prop['background-position'];
			}
			if('backgroundPosition' in prop){
				prop.backgroundPosition = '('+ prop.backgroundPosition;
			}
			return oldAnim.apply(this, arguments);
		};
		
		function toArray(strg){
			strg = strg.replace(/left|top/g,'0px');
			strg = strg.replace(/right|bottom/g,'100%');
			strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
			var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
			return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
		}
		
		$.fx.step. backgroundPosition = function(fx) {
			if (!fx.bgPosReady) {
				var start = $.curCSS(fx.elem,'backgroundPosition');
				
				if(!start){//FF2 no inline-style fallback
					start = '0px 0px';
				}
				
				start = toArray(start);
				
				fx.start = [start[0],start[2]];
				
				var end = toArray(fx.options.curAnim.backgroundPosition);
				fx.end = [end[0],end[2]];
				
				fx.unit = [end[1],end[3]];
				fx.bgPosReady = true;
			}
			//return;
			var nowPosX = [];
			nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
			fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	
		};
	})(jQuery);
}


/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}
			
			// IE being IE, randomly decides whether this is going to work or not.
			try {
				fx.elem.style[attr] = "rgb(" + [
					Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
					Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
					Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
				].join(",") + ")";
				
			} catch(error) {}
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		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]
	};
	
})(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);

// END SUPPORT LIBRARIES






























//// Animation --------------------------------------------------------------------

var MaxImageID = 77;
var ImagePreloadArray = Array();
var ImagesLoaded = Array()
var CurrentSequentialImageID = 1;

// Create loading bar
$(".pagebanner").append("<div class='bannerloader'>0% Loaded</div>");

$(".bannerloader").css("opacity",0.7);

if (navigator.userAgent.indexOf("MSIE") != -1) {
	if (navigator.userAgent.indexOf("MSIE 7") != -1 || navigator.userAgent.indexOf("MSIE 6") != -1) {
		$(".bannerloader")
			.css("marginLeft","-512px")
			.css("marginTop","0px");
		
		$(".tile").hover(function(eventData) {
			$(this).css("opacity","1");
		},
		function(eventData) {
			$(this).css("opacity",null);
		});
	}
	
	// bootstrap missing CSS3 selector support in IE
	$("ul .tile").each(function(itemCount, DOMNode) {
		if (!((itemCount + 1) % 4)) {
			$(DOMNode).css("marginRight","0px");
		}
	});
}

window.setInterval(swapImages,350);

//for (var ImagePreloadID = 1; ImagePreloadID <= MaxImageID; ImagePreloadID ++) {
//	var ImageID = ImagePreloadID;
//	if (ImageID < 10) {
//		ImageID = "0" + ImageID.toString();
//	}
//	
//	ImagePreloadArray[ImagePreloadArray.length] = new Image();
//	ImagePreloadArray[ImagePreloadArray.length - 1].ImageID = ImageID;
//	ImagePreloadArray[ImagePreloadArray.length - 1].src = "./images/animation/" + ImageID + ".jpg";
//	
//	ImagePreloadArray[ImagePreloadArray.length - 1].onload = function(eventData) {
//		ImagesLoaded.push(this.src);
//		updateLoadProgress();
//	}
//}

function updateLoadProgress() {
	PercentageComplete = ImagesLoaded.length / ImagePreloadArray.length;
	TotalLoaderWidth = Math.round(510 * PercentageComplete);
	
	if (Modernizr.csstransitions) {
		$(".bannerloader").css("width",TotalLoaderWidth+"px").html(Math.round(PercentageComplete*100) + "% Loaded");
	} else {
		$(".bannerloader").stop().animate({"width":TotalLoaderWidth+"px"},50).html(Math.round(PercentageComplete*100) + "% Loaded");
	}
	
	if (PercentageComplete > 0.98) {
		$(".bannerloader").fadeOut("slow",function(eventData) {
			$(this).remove();
		});
	}
}

function swapImages() {
	if (window.location.toString().split(".com")[1] == "/" || window.location.hash.replace(/\#/,"") == "/") {
		if (ImagesLoaded.length > 0) {
			if (ImagesLoaded.length < ImagePreloadArray.length) {
				ImageNumber = Math.floor(Math.random() * (ImagesLoaded.length - 2)) + 1;
			} else {
				
				if (CurrentSequentialImageID <= ImagesLoaded.length) {
					ImageNumber = CurrentSequentialImageID;
					CurrentSequentialImageID ++;
				} else {
					CurrentSequentialImageID = 1;
					ImageNumber = 1;
				}
			}
			
			$(".pagebanner img").eq(0).attr("src",ImagesLoaded[ImageNumber]);
		}
	}
}

// Load in tile elements
$(".tile").css("opacity",0);
$(window).load(function(eventData) {
	$(".tile").each(function(Count,DOMElement) {
		$(this).animate({"opacity":0},Count*250).animate({"opacity":1},500);
	});
});

// Animate in Tagline
$(".tagline img").css("opacity",0).css("bottom",(210-$(".tagline img").height()) + "px").addClass("unfaded");
$(window).load(function(eventData) {
	$(".tagline img").animate({opacity:1,bottom:"22px"},2500).removeClass("unfaded");
});

$(".header > ul > li").hover(function(eventData) {
	$(this).find(".level2 li").each(function(Count,DOMObject) {
		$(DOMObject).stop().css("marginLeft",(Count*10) + "px").css("opacity",0).animate({marginLeft:"0px",opacity:1},250);
	});
},function(eventData) {
	$(this).children("ul").addClass("hoveredlevel2");
	$(this).find(".level2 li").each(function(Count,DOMObject) {
		$(DOMObject).stop().animate({marginLeft:"-"+(Count*10)+"px",opacity:0},500);
		window.setTimeout(function() {
			$(".hoveredlevel2").removeClass("hoveredlevel2");
		},300);
	});
});



// Ready to show the document main area?
$(document).ready(function(eventData) {
	window.setTimeout(function(eventData) {
		$("#container").fadeIn(1500);
	},1000);
	
	$(document.body).animate({"backgroundPosition":"50% 0px"},1000);
});

// Are we an iPhone or iPod touch?
if (window.navigator.userAgent.indexOf("iPhone") != -1) {
	// Biggify the phone number
	$(".footer").css({
		"width"				: "900px",
		"paddingLeft"		: "15px",
		"textAlign"			: "center",
		"overflow"			: "visible",
		"marginTop"			: "100px"
	})
	
	$(".footer a").prepend("<p>Tap Here To Call Us Now!</p>").addClass("iphonebutton");
	//$(".footer a").css("-webkit-transform","scale(4)");
} else {
	// Remove tel: link for non-phones
	$(".footer a.tel").attr("href","#");
}



$(document).ready(function(eventData) {
	// Tile animate-out event
	$(".tile:not(.halfwidth) a").live("click",function(eventData) {
//		eventData.preventDefault();
		window.linkTo = $(this).attr("href");
		
		if (this.className.indexOf("clicked") == -1) {
			$(".clicked").removeClass("clicked");
			$(this).parents(".tile").addClass("clicked");
			$(this).parents(".tiles").find(".tile:not(.clicked)").each(function(itemCount, DOMNode) {
				Brightness = Math.floor(256 * Math.random());
				
				DOMNode.Brightness = Brightness;
				$(DOMNode).find("img").animate({
					opacity: "0"
				},Brightness/2);
				$(DOMNode).css("backgroundColor","white").animate({
					backgroundColor : "white"
				},Brightness,function() {
					$(this).animate({
						backgroundColor : "rgb(255," + this.Brightness + "," + this.Brightness + ")"
					},250,function() {
						$(this).animate({
							opacity: "0"
						},250);
					});
				});
			});
			
			window.setTimeout(function() {
				window.tileOriginalPosition = $(".clicked").position();
				
				$(".clicked").css({
					"position"			:	"absolute",
					"left"				:	$(".clicked").position().left + "px",
					"top"				:	$(".clicked").position().top  + "px",
					"backgroundColor"	:	"white"
				});
				
				$(".clicked img").animate({
					"opacity"	: 0
				},500, function(eventData) {
					$(".clicked").animate({
						"left"		:	$(".clicked").parents("ul").position().left + "px",
						"top"		:	$(".clicked").parents("ul").position().top + "px",
						"width"		:	"510px",
						"height"	:	"440px"
					},500, function(eventData) {
//						loadTile(window.linkTo);
					});
				});
			},1255);
		}
	});

	
	// set up carouselles
	generateCarouselle();
	
	// Fix homepage tiles
//	$("div.home").click(function(eventData) {
//		if (eventData.target.tagName != "a") {
//			goToLink($(this).find("a").attr("href"));
//		}
//	});
	
	// Setup buttons for homepage
	generateBackButton();
	
//	$("a").live("click",function(eventData) {
//		var URLParts = $(this).attr("href").split("/");
//		
//		if (URLParts[0] == "http:" && !URLParts[2].match(/lovedesigngroup\.com/)) {
//			eventData.preventDefault();
//			window.open($(this).attr("href"));
//		} else {
//			if (!(this.parentNode.tagName.match(/li/i) && this.parentNode.className.indexOf("tile") > -1 && this.parentNode.className.indexOf("halfwidth") == -1)) {
//				if (!$(this).attr("href").match(/^mailto\:/)) {
//					eventData.preventDefault();
//					goToLink($(this).attr("href"));
//				}
//			} else {
//				eventData.preventDefault();
//				return false;
//			}
//		}
//	});
});


function generateCarouselle() {
	$("carouselleToolbar").remove();
	$(".imagecarouselle").each(function(Count,DOMNode) {
		$(DOMNode).parents(".tiles").addClass("carouselleContainer");
		$(DOMNode).css({
			height:		"440px",
			width:		($(DOMNode).find("img").length * 510) + "px"
		});
		
		// Build toolbar
		DOMNode.Controller = document.createElement("ul");
		DOMNode.Controller.Carouselle = DOMNode;
		DOMNode.CurrentImage = 0;
		
		// Numbers calculated by rough offset position of image carouselle
		// They could do with some tweaking
		$(DOMNode.Controller).addClass("carouselleToolbar").css({
			postion:	"absolute",
			left:		410	+ ((510 - 60)/2),
			top: 		240	+ ((440 - 30)*0.9)
		});
		
		$(DOMNode.Controller).append("<li class='prev'><img src='/system/resources/icons/arrow-180-medium.png' class='icon' width='16' height='16' alt='Previous'/></li>");
		$(DOMNode.Controller).append("<li class='next'><img src='/system/resources/icons/arrow-000-medium.png' class='icon' width='16' height='16' alt='Next'/></li>");
//		$(DOMNode.Controller).append("<li class='quit'><img src='/system/resources/icons/cross.png' class='icon' width='16' height='16' alt='Return to Portfolio' /></li>");
		
		
		
		$(".secondrow").append(DOMNode.Controller);
		
		$("li.next").click(function(eventData) {
			Toolbar = this.parentNode;
			Carouselle = Toolbar.Carouselle;
			
			if (Carouselle.CurrentImage < ($(Carouselle).find("img").length - 1)) {
				Carouselle.CurrentImage ++;
			} else {
				Carouselle.CurrentImage = 0;
			}
			
			$(Carouselle).parents(".tiles").scrollTo(Carouselle.CurrentImage * 510,500,{axis:'x'});
		});
		
		$("li.prev").click(function(eventData) {
			Toolbar = this.parentNode;
			Carouselle = Toolbar.Carouselle;
			
			if (Carouselle.CurrentImage > 0) {
				Carouselle.CurrentImage --;
			} else {
				Carouselle.CurrentImage = ($(Carouselle).find("img").length - 1);
			}
			
			$(Carouselle).parents(".tiles").scrollTo(Carouselle.CurrentImage * 510,500,{axis:'x'});
		});
		
		$("li.quit").click(function(eventData) {
			CurrentLocation =	window.location.href.toString();
			CurrentLocation =	CurrentLocation.split(/\//ig);
								CurrentLocation.pop();
								CurrentLocation.pop();
								
			CurrentLocation =	CurrentLocation.join("/");
			closeTile();
		});
	});
}

function generateBackButton() {
	$(".singleteammember").each(function(Count,DOMNode) {
		// Build toolbar
		DOMNode.Controller = document.createElement("ul");
		DOMNode.Controller.Carouselle = DOMNode;
		DOMNode.CurrentImage = 0;
		
		// Numbers calculated by rough offset position of image carouselle
		// They could do with some tweaking
		$(DOMNode.Controller).addClass("carouselleToolbar").css({
			postion:	"absolute",
			left:		410	+ ((510 - 60)/2),
			top: 		240	+ ((440 - 30)*0.9)
		});
		
		/*
		$(DOMNode.Controller).append("<li class='prev'><img src='/system/resources/icons/arrow-180-medium.png' class='icon' width='16' height='16' alt='Previous'/></li>");
		$(DOMNode.Controller).append("<li class='next'><img src='/system/resources/icons/arrow-000-medium.png' class='icon' width='16' height='16' alt='Next'/></li>");
		*/
		$(DOMNode.Controller).append("<li class='quit'><img src='/system/resources/icons/cross.png' class='icon' width='16' height='16' alt='Return to Team' /></li>");
		$(".secondrow").append(DOMNode.Controller);
		
		/*
		$("li.next").click(function(eventData) {
			Toolbar = this.parentNode;
			Carouselle = Toolbar.Carouselle;
			
			if (Carouselle.CurrentImage < ($(Carouselle).find("img").length - 1)) {
				Carouselle.CurrentImage ++;
			} else {
				Carouselle.CurrentImage = 0;
			}
			
			$(Carouselle).parents(".tiles").scrollTo(Carouselle.CurrentImage * 510,250);
		});
		
		$("li.prev").click(function(eventData) {
			Toolbar = this.parentNode;
			Carouselle = Toolbar.Carouselle;
			
			if (Carouselle.CurrentImage > 0) {
				Carouselle.CurrentImage --;
			} else {
				Carouselle.CurrentImage = ($(Carouselle).find("img").length - 1);
			}
			
			$(Carouselle).parents(".tiles").scrollTo(Carouselle.CurrentImage * 510,250);
		});
		*/
		
		$("li.quit").css("width","100%");
		$("li.quit").click(function(eventData) {
			CurrentLocation =	window.location.href.toString();
			CurrentLocation =	CurrentLocation.split(/\//ig);
								CurrentLocation.pop();
								
			CurrentLocation =	CurrentLocation.join("/");
			
			closeTile();
		});
	});
}



function goToLink(URL) {
	try {
		if (pageTracker._trackPageview) {
			pageTracker._trackPageview(URL);
		}
	} catch(Error) {}
	
	$(".carouselleToolbar").remove();
	
	$(".pagebanner img").stop().animate({
		"opacity":	1
	},500);
	
	window.location.hash = URL;
	$.ajax({
		url:		URL,
		success:	function(returnedData,textStatus) {
			// Destroy carouselle toolbars
			$("carouselleToolbar").remove();
			
			// Exctact Data
			var DocumentTitle	= $(returnedData).find("h2").html();
			var TaglineHTML		= $(returnedData).find(".tagline").html();
			var BannerSource	= $(returnedData).find(".pagebanner img").attr("src");
			var TextContent		= $(returnedData).find(".secondrow").children(".text").html();
			var TileContent		= $(returnedData).find(".secondrow").children(".tiles").html();
			
			// change document over
			document.title = DocumentTitle
			
			// Text
			if (TileContent != $(".secondrow").children(".text").html()) {
				$(".secondrow").children(".text").fadeOut("slow",function(eventData) {
					$(this).html(TextContent).fadeIn("slow");
				});
			}
			
			// Tiles
			if (TileContent != $(".secondrow").children(".tiles").html()) {
				$(".secondrow").children(".tiles").fadeOut("slow",function(eventData) {
					$(this).html(TileContent);
					
					if (window.navigator.userAgent.indexOf("MSIE") != -1) {
						// bootstrap missing CSS3 selector support in IE
						$("ul .tile").each(function(itemCount, DOMNode) {
							if (!((itemCount + 1) % 4)) {
								$(DOMNode).css("marginRight","0px");
							}
						});
					}
					
					// set up carouselles
					generateCarouselle();
					
					$(".tile").css("opacity",0);
					$(this).show();
					$(".tile").each(function(Count,DOMElement) {
						$(this)
							.css({
								"opacity": 0,
								"-webkit-transition": "none"
							})
							.animate({
								"opacity": 0
							},Count*250)
							.animate({
								"opacity": 1
							},500,function() {
								$(this).css("-webkit-transition","opacity 250ms linear");
							});
					});
				});
			}
			
			// Tagline
			if ($(returnedData).find(".tagline img").attr("src") != $(".tagline img").attr("src")) {
				$(".tagline").fadeOut("slow",function(eventData) {
					$(this).html(TaglineHTML).fadeIn("slow");
				});
			}
			
			// Main Image
			$(".pagebanner img").attr("src",BannerSource);
		}
	});
}

function loadTile(URL) {
	try {
		if (pageTracker._trackPageview) {
			pageTracker._trackPageview(URL);
		}
	} catch(Error) {}
	
	window.tileCarouselleImages = [];
	window.location.hash = URL;
	$.ajax({
		url:		URL,
		success:	function(returnedData,textStatus) {
			// Destroy carouselle toolbars
			$(".carouselleToolbar").remove();
			
			// Exctact Data
			var DocumentTitle	= $(returnedData).find("h2").html();
			var TextContent		= $(returnedData).find(".secondrow").children(".text").html();
			var TileContent		= $(returnedData).find(".secondrow").children(".tiles").html();
			
			// change document over
			document.title = DocumentTitle
			
			// Text
			if (TileContent != $(".secondrow").children(".text").html()) {
				window.categoryOriginalText = $(".secondrow").children(".text").html();
				$(".secondrow").children(".text").fadeOut("slow",function(eventData) {
					$(this).html(TextContent).fadeIn("slow");
				});
			}
			
			// Load in carouselle images
			$(".tiles").css({
				width: 		"510px",
				overflow:	"hidden"
			});
			$(".tiles").append("<div class='imagecarouselle'>").find(".imagecarouselle").css({
				position:	"relative",
				left:		"0px",
				top: 		"-480px",
				width:		($(returnedData).find(".secondrow .tiles img").length * 510) + "px",
				height:		"440px",
				overflow:	"hidden"
			});
			
			window.imagesLoaded = 0;
			window.totalImages = $(returnedData).find(".secondrow .tiles img").length;
			
			$(returnedData).find(".secondrow .tiles img").each(function(itemCount,DOMNode) {
				window.tileCarouselleImages.push(new Image());
				window.tileCarouselleImages[window.tileCarouselleImages.length-1].src = $(DOMNode).attr("src");
				window.tileCarouselleImages[window.tileCarouselleImages.length-1].onload = function(eventData) {
					$(".tiles .imagecarouselle").append(this);
					$(this).css({
						float: 		"left",
						opacity:	0,
						width:		"0px"
					}).animate({
						opacity:	1,
						width:		"510px"
					},500);
					
					window.imagesLoaded ++;
					if (window.imagesLoaded == window.totalImages) {
						generateCarouselle();
					}
				}
			});
			
			$(".pagebanner img").animate({
				"opacity":	0.3
			},1000);
		}
	});
}

function closeTile() {
	// Reset temporary variables
	window.imagesLoaded = 0;
	window.totalImages = 0;
	
	$(".pagebanner img").stop().animate({
		"opacity":	1
	},500);
	
	$(".carouselleToolbar").remove();
	
	$(".tile:hidden").css("display","block");
	$(".imagecarouselle").fadeOut("slow",function() {
		$(this).remove();
		$(".tiles").scrollTo({top: 0, left: 0},0);
		
		$(".clicked").animate({
			"left"		:	window.tileOriginalPosition.left + "px",
			"top"		:	window.tileOriginalPosition.top + "px",
			"width"		:	"120px",
			"height"	:	"105px"
		},500, function() {
			if (window.navigator.userAgent.indexOf("MSIE") == -1) {
				$(".clicked").css("position",null);
			} else {
				$(".clicked").css("position","static");
			}
			
			$(".tile:not(.clicked)").css("backgroundColor","transparent");
			$(".tile, .tile img").animate({
				"opacity": 1
			},500,function() {
				$(".clicked")
					.css("backgroundColor","transparent")
					.removeClass("clicked");
			});
		});
	});
	
	$(".secondrow").children(".text").fadeOut("slow",function(eventData) {
		$(".secondrow").children(".text").html(window.categoryOriginalText);
		$(".secondrow").children(".text").fadeIn("slow");
	});
}
