/**
 * Copyright (c) 2005 - 2010, James Auldridge
 * All rights reserved.
 *
 * Licensed under the BSD, MIT, and GPL (your choice!) Licenses:
 *  http://code.google.com/p/cookies/wiki/License
 *
 */
var jaaulde=window.jaaulde||{};jaaulde.utils=jaaulde.utils||{};jaaulde.utils.cookies=(function(){var resolveOptions,assembleOptionsString,parseCookies,constructor,defaultOptions={expiresAt:null,path:'/',domain:null,secure:false};resolveOptions=function(options){var returnValue,expireDate;if(typeof options!=='object'||options===null){returnValue=defaultOptions;}else
{returnValue={expiresAt:defaultOptions.expiresAt,path:defaultOptions.path,domain:defaultOptions.domain,secure:defaultOptions.secure};if(typeof options.expiresAt==='object'&&options.expiresAt instanceof Date){returnValue.expiresAt=options.expiresAt;}else if(typeof options.hoursToLive==='number'&&options.hoursToLive!==0){expireDate=new Date();expireDate.setTime(expireDate.getTime()+(options.hoursToLive*60*60*1000));returnValue.expiresAt=expireDate;}if(typeof options.path==='string'&&options.path!==''){returnValue.path=options.path;}if(typeof options.domain==='string'&&options.domain!==''){returnValue.domain=options.domain;}if(options.secure===true){returnValue.secure=options.secure;}}return returnValue;};assembleOptionsString=function(options){options=resolveOptions(options);return((typeof options.expiresAt==='object'&&options.expiresAt instanceof Date?'; expires='+options.expiresAt.toGMTString():'')+'; path='+options.path+(typeof options.domain==='string'?'; domain='+options.domain:'')+(options.secure===true?'; secure':''));};parseCookies=function(){var cookies={},i,pair,name,value,separated=document.cookie.split(';'),unparsedValue;for(i=0;i<separated.length;i=i+1){pair=separated[i].split('=');name=pair[0].replace(/^\s*/,'').replace(/\s*$/,'');try
{value=decodeURIComponent(pair[1]);}catch(e1){value=pair[1];}if(typeof JSON==='object'&&JSON!==null&&typeof JSON.parse==='function'){try
{unparsedValue=value;value=JSON.parse(value);}catch(e2){value=unparsedValue;}}cookies[name]=value;}return cookies;};constructor=function(){};constructor.prototype.get=function(cookieName){var returnValue,item,cookies=parseCookies();if(typeof cookieName==='string'){returnValue=(typeof cookies[cookieName]!=='undefined')?cookies[cookieName]:null;}else if(typeof cookieName==='object'&&cookieName!==null){returnValue={};for(item in cookieName){if(typeof cookies[cookieName[item]]!=='undefined'){returnValue[cookieName[item]]=cookies[cookieName[item]];}else
{returnValue[cookieName[item]]=null;}}}else
{returnValue=cookies;}return returnValue;};constructor.prototype.filter=function(cookieNameRegExp){var cookieName,returnValue={},cookies=parseCookies();if(typeof cookieNameRegExp==='string'){cookieNameRegExp=new RegExp(cookieNameRegExp);}for(cookieName in cookies){if(cookieName.match(cookieNameRegExp)){returnValue[cookieName]=cookies[cookieName];}}return returnValue;};constructor.prototype.set=function(cookieName,value,options){if(typeof options!=='object'||options===null){options={};}if(typeof value==='undefined'||value===null){value='';options.hoursToLive=-8760;}else if(typeof value!=='string'){if(typeof JSON==='object'&&JSON!==null&&typeof JSON.stringify==='function'){value=JSON.stringify(value);}else
{throw new Error('cookies.set() received non-string value and could not serialize.');}}var optionsString=assembleOptionsString(options);document.cookie=cookieName+'='+encodeURIComponent(value)+optionsString;};constructor.prototype.del=function(cookieName,options){var allCookies={},name;if(typeof options!=='object'||options===null){options={};}if(typeof cookieName==='boolean'&&cookieName===true){allCookies=this.get();}else if(typeof cookieName==='string'){allCookies[cookieName]=true;}for(name in allCookies){if(typeof name==='string'&&name!==''){this.set(name,null,options);}}};constructor.prototype.test=function(){var returnValue=false,testName='cT',testValue='data';this.set(testName,testValue);if(this.get(testName)===testValue){this.del(testName);returnValue=true;}return returnValue;};constructor.prototype.setOptions=function(options){if(typeof options!=='object'){options=null;}defaultOptions=resolveOptions(options);};return new constructor();})();(function(){if(window.jQuery){(function($){$.cookies=jaaulde.utils.cookies;var extensions={cookify:function(options){return this.each(function(){var i,nameAttrs=['name','id'],name,$this=$(this),value;for(i in nameAttrs){if(!isNaN(i)){name=$this.attr(nameAttrs[i]);if(typeof name==='string'&&name!==''){if($this.is(':checkbox, :radio')){if($this.attr('checked')){value=$this.val();}}else if($this.is(':input')){value=$this.val();}else
{value=$this.html();}if(typeof value!=='string'||value===''){value=null;}$.cookies.set(name,value,options);break;}}}});},cookieFill:function(){return this.each(function(){var n,getN,nameAttrs=['name','id'],name,$this=$(this),value;getN=function(){n=nameAttrs.pop();return!!n;};while(getN()){name=$this.attr(n);if(typeof name==='string'&&name!==''){value=$.cookies.get(name);if(value!==null){if($this.is(':checkbox, :radio')){if($this.val()===value){$this.attr('checked','checked');}else
{$this.removeAttr('checked');}}else if($this.is(':input')){$this.val(value);}else
{$this.html(value);}}break;}}});},cookieBind:function(options){return this.each(function(){var $this=$(this);$this.cookieFill().change(function(){$this.cookify(options);});});}};$.each(extensions,function(i){$.fn[i]=this;});})(window.jQuery);}})();;
/*
 Shadow animation jQuery-plugin 1.7
 http://www.bitstorm.org/jquery/shadow-animation/
 Copyright 2011 Edwin Martin <edwin@bitstorm.org>
 Contributors: Mark Carver, Xavier Lepretre
 Released under the MIT and GPL licenses.
*/
jQuery(function(e,i){function j(){var a=e("script:first"),b=a.css("color"),c=false;if(/^rgba/.test(b))c=true;else try{c=b!=a.css("color","rgba(0, 0, 0, 0.5)").css("color");a.css("color",b)}catch(d){}return c}function k(a,b,c){var d=[];a.c&&d.push("inset");typeof b.left!="undefined"&&d.push(parseInt(a.left+c*(b.left-a.left),10)+"px "+parseInt(a.top+c*(b.top-a.top),10)+"px");typeof b.blur!="undefined"&&d.push(parseInt(a.blur+c*(b.blur-a.blur),10)+"px");typeof b.a!="undefined"&&d.push(parseInt(a.a+c*
(b.a-a.a),10)+"px");if(typeof b.color!="undefined"){var g="rgb"+(e.support.rgba?"a":"")+"("+parseInt(a.color[0]+c*(b.color[0]-a.color[0]),10)+","+parseInt(a.color[1]+c*(b.color[1]-a.color[1]),10)+","+parseInt(a.color[2]+c*(b.color[2]-a.color[2]),10);if(e.support.rgba)g+=","+parseFloat(a.color[3]+c*(b.color[3]-a.color[3]));g+=")";d.push(g)}return d.join(" ")}function h(a){var b,c,d={};if(b=/#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/.exec(a))c=[parseInt(b[1],16),parseInt(b[2],16),parseInt(b[3],
16),1];else if(b=/#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])/.exec(a))c=[parseInt(b[1],16)*17,parseInt(b[2],16)*17,parseInt(b[3],16)*17,1];else if(b=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(a))c=[parseInt(b[1],10),parseInt(b[2],10),parseInt(b[3],10),1];else if(b=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9\.]*)\s*\)/.exec(a))c=[parseInt(b[1],10),parseInt(b[2],10),parseInt(b[3],10),parseFloat(b[4])];d=(b=/(-?[0-9]+)(?:px)?\s+(-?[0-9]+)(?:px)?(?:\s+(-?[0-9]+)(?:px)?)?(?:\s+(-?[0-9]+)(?:px)?)?/.exec(a))?
{left:parseInt(b[1],10),top:parseInt(b[2],10),blur:b[3]?parseInt(b[3],10):0,a:b[4]?parseInt(b[4],10):0}:{left:0,top:0,blur:0,a:0};d.c=/inset/.test(a);d.color=c;return d}e.extend(true,e,{support:{rgba:j()}});var f;e.each(["boxShadow","MozBoxShadow","WebkitBoxShadow"],function(a,b){a=e("html").css(b);if(typeof a=="string"&&a!=""){f=b;return false}});if(f)e.fx.step.boxShadow=function(a){if(!a.init){a.b=h(e(a.elem).get(0).style[f]||e(a.elem).css(f));a.end=e.extend({},a.b,h(a.end));if(a.b.color==i)a.b.color=
a.end.color||[0,0,0];a.init=true}a.elem.style[f]=k(a.b,a.end,a.pos)}});
;



/**
 * Add Galleries
 *
 */
 
(function($) {
	$.fn.extend( {
		textSize: function() {
			var html_org = $(this).html();
			var html_calc = '<span>' + html_org + '</span>'
			$(this).html(html_calc);
			var width = $(this).find('span:first').width();
			var height = $(this).find('span:first').height();
			$(this).html(html_org);
			return {width:width, height:height};
		}
	} );
})(jQuery);


(function($) {
	$.fn.extend( {
		homeBars: function(autoOpenBar) {
			
			var CONST = {
				imagePaddingLeft: 10,
				imagePaddingTop: 10,
				imageContentSpace:	20,
				contentWidth: 223,
				fullBarHeight: 960,
				fullBarPaddingLR: 20,
				fullBarStickup: 150,
				zoomUpTime: 400,
				zoomDownTime: 500,
				contentFadeUpTime: 200,
				autoOpenDelay: 2000
			};
			
			if ( $.cookies.get('_ao') == '1' )
				autoOpenBar = '';
			else
				$.cookies.set('_ao', '1');
			
			var openNow = '';
			if ( window.location.hash && window.location.hash.length > 0 ) {
				autoOpenBar = '';
				openNow = window.location.hash.substring( 1 );
			}
			
			var numBars = $(this).length;
			if ( numBars > 0 ) {
			
				var $content = $('#content');
				$content.css( {position:'relative', overflow:'visible'} );
				var $visbar = null;
				var autoOpenTimeoutId = null;
				
				/*
				var $chancellor = $( document.createElement('div') );
				$chancellor.css( { position:'absolute', zIndex:0, top:0, left:-138, width:975, height:450 } );		// need to tweak this for small screens
				//$chancellor.css( { position:'absolute', zIndex:0, top:0, left:-138, width:1308, height:660 } );
				$content.prepend( $chancellor );
				*/
				
				// main "hide me" function:
				var collapseFunction = function( $which ) {
					$which.data( 'content' ).hide();
					$which.data( 'bgimg' ).hide();
					$which.data( 'lgimg' ).animate( {width:$which.data('smw'), height:$which.data('smh'), marginLeft:0}, CONST.zoomDownTime, function() {
						//$which.data( 'lgimg' ).hide();
						//$which.data( 'header' ).show();
					} );
					$which
						.css( {zIndex:1} )
						.animate( {width:$which.data('origw'), height:$which.data('origh'),
									left:$which.data('origx'), top:$which.data('origy'),
									paddingLeft:10, paddingRight:5, boxShadow:'0px 0px 0px' }, CONST.zoomDownTime, function() {
							$which.css( {zIndex:0} );
						} )
						.bind( 'click', expandFunction )
						.css( {cursor:'pointer'} );
					$visbar = null;
				};
				
				// main "show me" function:
				var expandFunction = function(e) {
					if ( $visbar != null ) {
						collapseFunction( $visbar );
					}
					if ( autoOpenTimeoutId != null ) {
						window.clearTimeout( autoOpenTimeoutId );
						autoOpenTimeoutId = null;
					}
					$which = $(this);
					//$which.data( 'header' ).hide();
					
					$which.data( 'lgimg' )
						.show()
						.css( {display:'block', width:$which.data('smw'), height:$which.data('smh')} )
						.animate( {opacity:1, width:$which.data('lgw'), height:$which.data('lgh'), marginLeft:10}, CONST.zoomUpTime, function() {
							if ( $visbar != $which )
								return;
							$which.data('content')
								.css( {display:'block', opacity:0} )
								.animate( {opacity:1}, CONST.contentFadeUpTime, function() { if ($(this).length > 0 && $(this).get(0) && $(this).get(0).style && $(this).get(0).style.removeAttribute) $(this).get(0).style.removeAttribute('filter'); } )
								.find( '.accordion' ).accordion( true );
							$which.data('bgimg')
								.css( {display:'block', opacity:0} )
								.animate( {opacity:1}, CONST.contentFadeUpTime );
						});
					$which
						.css( {zIndex:2} )
						.animate( {width:CONST.contentWidth, height:CONST.fullBarHeight,
									paddingLeft:CONST.fullBarPaddingLR, paddingRight:CONST.fullBarPaddingLR,
									left:$which.data('zoomx'), top:$which.data('origy') - CONST.fullBarStickup,
									boxShadow:'-15px 10px 20px #ccc'}, CONST.zoomUpTime );
					$which.unbind( 'click' ).css( {cursor:'default'} );
					$visbar = $which;
				};
				
				var autoOpenFunction = function( $which ) {
					autoOpenTimeoutId = null;
					expandFunction.call( $which, null );
				};
				
				//$chancellor.bind( 'click', function() { if ($visbar != null) collapseFunction($visbar); } );
				$(document).click(function(event) {
					if ( $visbar != null ) {
						if ( !$(event.target).closest('#' + $visbar.attr('id')).length ) {
							collapseFunction($visbar);
						};
					}
				});
				
				$(this).each( function(idx) {
					var $bar = $(this);
					
					var pos = $bar.position();
					if ( $bar.css('marginLeft') == 'auto' )
						$bar.data( 'origx', pos.left );
					else
						$bar.data( 'origx', pos.left + parseInt($bar.css('marginLeft').replace('px','')) );
					if ( $bar.css('marginTop') == 'auto' )
						$bar.data( 'origy', pos.top );
					else
						$bar.data( 'origy', pos.top + parseInt($bar.css('marginTop').replace('px','')) );
					
					var w = parseInt($bar.css('width').replace('px',''));
					$bar.data( 'origh', parseInt($bar.css('height').replace('px','')) );
					$bar.data( 'origw', w );
					
					if ( idx == 0 )
						$bar.data( 'zoomx', $bar.data('origx') );
					else if ( idx == numBars - 1 )
						$bar.data( 'zoomx', $bar.data('origx') + (w + 20) - (CONST.contentWidth + CONST.fullBarPaddingLR * 2) );
					else
						$bar.data( 'zoomx', $bar.data('origx') - ((CONST.contentWidth + CONST.fullBarPaddingLR * 2) - (w + 20)) / 2 );
					
					var $header = $bar.children( 'h2:first' );
					var $lgimg = $bar.find( 'img.large' );
					var $bgimg = $bar.find( 'img.bg-logo' );
					var $content = $bar.children( '.bar-content' );
					$bar.data( 'lgimg', $lgimg );
					$bar.data( 'bgimg', $bgimg );
					$bar.data( 'content', $content );
					$bar.data( 'header', $header );
					var lgw = $lgimg.attr('width');
					var lgh = $lgimg.attr('height');
					$bar.data( 'lgw', lgw );
					$bar.data( 'lgh', lgh );
					
					var dim = $header.textSize();
					$bar.data( 'smw', dim.width );
					$bar.data( 'smh', Math.round(lgh * (dim.width / lgw)) );
					
					pos = $content.offset();
					var po = $content.parent().offset();
					$content.css( { position:'absolute', top:$lgimg.attr('height') + CONST.imageContentSpace, width:CONST.contentWidth} );
					
					// TODO: pre-hide stuff in css, not here:
					$lgimg.css( { position:'absolute', top:CONST.imagePaddingTop, left:CONST.imagePaddingLeft, marginLeft:0, width:$bar.data('smw'), height:$bar.data('smh')} );
					//$lgimg.hide();
					$header.hide();
					$bgimg.css( {display:'none', opacity:0} );
					$content.hide();
					
					$bar.bind( 'click', expandFunction ).css( {cursor:'pointer'} );
					
					if ( $bar.attr('id') == autoOpenBar ) {
						autoOpenTimeoutId = window.setTimeout( function() { autoOpenFunction($bar); }, CONST.autoOpenDelay );
					}
				} );
				
				$(this).each( function(idx) {
					var $bar = $(this);
					$bar.css( {position:'absolute', left:$bar.data('origx'), top:$bar.data('origy'), margin:0} );
				} );
				
				$(this).each( function(idx) {
					var $bar = $(this);
					if ( $bar.attr('id') == openNow ) {
						autoOpenTimeoutId = window.setTimeout( function() { autoOpenFunction($bar); }, 500 );
					}
				} );
			}
		}
	});
})(jQuery);


/**
 * Add generic accordion
 *
 */
(function($) {
	$.fn.extend( {
		accordion: function( singleton ) {
			/**
			 * Links:
			 * 	<h3>
			 * Content:
			 *	<div>
			 */
			if ( singleton !== true )
				singleton = false;
			
			$(this).each( function() {
				var $trunk = $(this);
				if ( $trunk.data('accordion') != 'true' ) {
					$trunk.data( 'accordion', 'true' );
					$trunk.data( 'singleton', singleton );
					$trunk.children( 'h3' ).each( function(idx) {
						var $term = $(this);
						var $a = $term.wrapInner( '<a href="javascript:void(0);" />' ).children( 'a:first' );
						var $content= $term.next();
						$content.data( 'h', 0 );
						var node = {
							open: function() {
								if ( $content.data('h') == 0 ) {
									$content.css( {display:'block'} );
									$content.data( 'h', $content.outerHeight() + 16 );
									$content.css( {height:0} );
								}
								$a.addClass( 'selected' );
								$content.animate( {height:$content.data('h')}, 250 );
							},
							close: function() {
								$a.removeClass( 'selected' );
								$content.animate( {height:0}, 250 );
							}
						}
						
						var clickFunction = function(evt) {
							if ( $a.hasClass('selected') ) {
								node.close();
								if ( $trunk.data('singleton') )
									$trunk.data( 'open', null );
							}
							else {
								node.open();
								if ( $trunk.data('singleton') ) {
									var last = $trunk.data( 'open' );
									if ( last )
										last.close();
									$trunk.data( 'open', node );
								}
							}
						};
						
						$a.bind( 'click', clickFunction );
						$content.css( {display:'none'} );
						$content.css( { /*paddingTop:0, paddingBottom:0, marginBottom:0, borderBottomWidth:0, borderTopWidth:0,*/ overflow:'hidden' } );
						
					} );
				}
			} );
		}
	});
})(jQuery);


/**
 * Add methodology diagram
 *
 */
(function($) {
	$.fn.extend( {
		methodology: function() {
			/**
			 * Links:
			 * 	<h4>
			 * Content:
			 *	<div>
			 */
			$(this).each( function() {
				var $trunk = $(this);
				if ( $trunk.data('accordion') != 'true' ) {
					$trunk.data( 'accordion', 'true' );
					$trunk.find( 'h4' ).each( function(idx) {
						var $term = $(this);
						var $a = $term.children( 'a:first' );
						$a.attr( 'href', 'javascript:void(0);' );
						var $content;
						if ( $a.hasClass('up') ) {
							$content = $term.prev();
						}
						else
							$content = $term.next();
						
						$content.data( 'mb', $content.css('margin-bottom') );
						$content.data( 'mt', $content.css('margin-top') );
						$content.data( 'h', 0 );
						$content.css( {display:'none'} );
						
						var node = {
							open: function() {
								$a.addClass( 'selected' );
								if ( $content.data('h') == 0 ) {
									$content.css( {display:'block'} );
									$content.data( 'h', $content.outerHeight() + 2 );
									$content.css( {height:0} );
								}
								var css = {height:$content.data('h'), marginTop:$content.data('mt'), marginBottom:$content.data('mb')};
								$content.animate( css, 250 );
							},
							close: function() {
								$a.removeClass( 'selected' );
								var css = {height:0, marginTop:0, marginBottom:0};
								$content.animate( css, 250 );
							}
						}
						
						var clickFunction = function(evt) {
							if ( $a.hasClass('selected') ) {
								node.close();
								//$trunk.data( 'open', null );
							}
							else {
								node.open();
								/*
								var last = $trunk.data( 'open' );
								if ( last )
									last.close();
								$trunk.data( 'open', node );
								*/
							}
						};
						
						$a.bind( 'click', clickFunction );
						var css = { overflow:'hidden', marginTop:0, marginBottom:0, paddingTop:0, paddingBottom:0 };
						$content.css( css );
						
					} );
				}
			} );
		}
	});
})(jQuery);



/**
 * Add philosophy diagram
 *
 */
(function($) {
	$.fn.extend( {
		philosophize: function() {
			/**
			 * Links:
			 * 	<h4>
			 * Content:
			 *	<div>
			 */
			$(this).each( function() {
				var $map = $(this);
				var $img = $( '#' + $map.attr( 'id' ) + '-img' );
				$img.parent().css( {position:'relative'} );
				var pos = $img.position();
				var $imgBase = $img.attr( 'src' ).replace( 'philosophy_base.png', '' );
				$img.css( { zIndex:3, opacity:0 } );
				var $last = null;
				$map.children( 'area' ).each( function(idx) {
					var $area = $(this);
					$area.attr( 'href', 'javascript:void(0);' );
					var $overlay = $( document.createElement('img') );
					$overlay.attr( 'width', $img.attr('width') );
					$overlay.attr( 'height', $img.attr('height') );
					$overlay.attr( 'src', $imgBase + 'philosophy_' + $area.attr('id') + '.png' );
					$overlay.css( {position:'absolute', display:'block', opacity:0, zIndex:-1, left:pos.left, top:pos.top, width:$img.attr('width'), height:$img.attr('height') } );
					$img.before( $overlay );
					var showFunc = function() {
						if ($last != $overlay) {
							if ( $last != null )
								$last.animate({opacity:0}, 250);
							$overlay.animate({opacity:1}, 250);
							$last = $overlay;
						}
					};
					var hideFunc = function() {
						$last = null;
						$overlay.animate({opacity:0}, 500);
					};
					$area.hover( showFunc, hideFunc ).bind( 'click', showFunc );
					
				} );
				var $underlay = $( document.createElement('img') );
				$underlay.attr( 'width', $img.attr('width') );
				$underlay.attr( 'height', $img.attr('height') );
				$underlay.attr( 'src', $img.attr('src') );
				$underlay.css( {position:'absolute', display:'block', zIndex:-2, left:pos.left, top:pos.top, width:$img.attr('width'), height:$img.attr('height') } );
				$img.before( $underlay );
			} );
		}
	});
})(jQuery);

/**
 * Add success stories gallery
 *
 */
(function($) {
	$.fn.extend( {
		successStories: function() {
			/**
			 * Links:
			 * 	<h4>
			 * Content:
			 *	<div>
			 */
			
			if ( $(this).length == 0 )
				return;
			
			var $overlay = $('#success-pop');
			var ow = $overlay.outerWidth();
			$overlay
				.css( { zIndex:99, position:'absolute', cursor:'pointer' } )
				.detach();
			$overlay.css( { display:'none', opacity:0 } );
			$( '#copy' )
				.append( $overlay )
				.css( {overflow:'visible'} );
			
			var copyOffset = $( '#copy' ).offset();
			
			$overlay.bind( 'click', function() {
				$overlay.animate( {opacity:0.0}, 250, function() { $overlay.css({display:'none'}); } );
			} );
			
			var cache = {};
			$(this).each( function() {
				var $trunk = $(this);
				$trunk.css( {position:'relative'} );
				$trunk.children( 'div' ).each( function(idx) {
					var $thumb = $(this);
					var $a = $thumb.children( 'a:first' );
					var href = $a.attr( 'href' ) + '?plain=1';
					$a.attr( 'href', 'javascript:void(0);' );
					$a.data( 'url', href );
					$a.data( 'node', $thumb.attr('id') );
					$a.bind( 'click', function() {
						var aOffset = $(this).children('img:first').offset();
						var $copy = $( '#copy' );
						var copyOffset = $copy.offset();
						var overlayWidth = $overlay.outerWidth() - 30; /* 30 is shadow size */
						var overlayHeight = $overlay.outerHeight() - 30; /* 30 is shadow size */
						var left = aOffset.left - copyOffset.left;
						var top = aOffset.top - copyOffset.top;
						if ( aOffset.left + overlayWidth > copyOffset.left + $copy.width() )
							left = ((copyOffset.left + $copy.width()) - overlayWidth) - copyOffset.left;
						if ( aOffset.top + overlayHeight > copyOffset.top + $copy.height() )
							top = ((copyOffset.top + $copy.height()) - overlayHeight) - copyOffset.top;
						$overlay
							.html( 'loading...' )
							.css( {display:'block', opacity:0.0, left:left, top:top} )
							.animate( {opacity:1.0}, 500, function() { if ($(this).length > 0 && $(this).get(0) && $(this).get(0).style && $(this).get(0).style.removeAttribute) $(this).get(0).style.removeAttribute('filter'); } );
						if ( cache[$(this).data('node')] != null ) {
							$overlay.html( cache[$(this).data('node')] );
							var $c = $overlay.find('.content');
							$c.css( {display:'block', opacity:1.0} );
							if ($c.length > 0 && $c.get(0) && $c.get(0).style && $c.get(0).style.removeAttribute)
								$c.get(0).style.removeAttribute('filter');
						}
						else {
							var node = $(this).data('node');
							$.ajax({
								url: $(this).data('url'),
								dataType: 'html',
								success: function(data, textStatus, jqXHR) {
									if ( textStatus == "error" ) {
										var msg = "Sorry but there was an error: ";
										$overlay.html(msg + xhr.status + " " + xhr.statusText);
									}
									else {
										var html = '';
										var h2 = '';
										var str = data.match( /<h2>([^\0]*?)<\/h2>/m );
										if ( str.length > 0 )
											h2 = str[ 1 ];
										str = data.match( /<div class="content">([^\0]*?)<\/div>/m );
										if ( str.length > 0 )
											html = str[ 1 ];
										
										$overlay.html( '<div class="content">' + html + '</div>' );
										if ( h2.length > 0 ) {
											var $cimg = $overlay.children( '.content' ).children( 'img:first' );
											if ( $cimg.length > 0 )
												$cimg.after( '<h2>' + h2 + '</h2>' );
										}
										/*
										if ( h2.length > 0 )
											$overlay.html( '<div class="content"><h2>' + h2 + '</h2>' + html + '</div>' );
										else
											$overlay.html( '<div class="content">' + html + '</div>' );
										*/
										$overlay.find('.content')
											.css( {display:'block', opacity:0.0} )
											.animate( {opacity:1.0}, 250, function() { if ($(this).length > 0 && $(this).get(0) && $(this).get(0).style && $(this).get(0).style.removeAttribute) $(this).get(0).style.removeAttribute('filter'); } );
										cache[node] = $overlay.html();
									}
								}
							});
						}
					} );
				} );
			} );
		}
	});
})(jQuery);


function buildImmersionMap() {

	var $map = jQuery( '#contact-map' );
	if ( $map.length == 0 )
		return;
	
	var $countryList = jQuery('#country-list');
	if ( $countryList.length == 0 )
		return;
	
	var countries = [];
	$countryList.find( 'li' ).each( function() {
		var c = jQuery(this).text().replace(/^\s+|\s+$/g, '');
		if ( c.length > 0 )
			countries.push( c );
	} );
	if ( countries.length > 0 ) {
		var data = new google.visualization.DataTable();
		data.addRows( countries.length );
		data.addColumn('string', 'Country');
		for ( var n = 0; n < countries.length; n++ ) {
			data.setValue( n, 0, countries[n] );
		}
		
		var geochart = new google.visualization.GeoChart( $map.get(0) );
		geochart.draw( data, {
			width: 480,
			height: 290,
			backgroundColor:'#bae3e6',
			colors: ['#2e8118','#2e8119']
		} );
	}
}

if ( window.location.pathname.indexOf('consumer-immersion') != -1 ) {
	google.load('visualization', '1', {'packages': ['geochart']});
	google.setOnLoadCallback( buildImmersionMap );
}

jQuery(document).ready( function() {
	//jQuery( '.accordion' ).accordion();
	jQuery( '.full-bar' ).homeBars();
	jQuery( '#methodology-diagram' ).methodology();
	jQuery( '#success-stories' ).successStories();
	jQuery( '#philosophy-map' ).philosophize();
} );
jQuery(window).load( function() {
	jQuery( '.copy-accordion' ).accordion( false );
} );;

