Cufon.replace('h1').replace('h2').replace('a.service-box div').replace('a.box-link div');

var bgImages = ["/img/content/CBD_Day_A.jpg","/img/content/CBD_Mall_A.jpg","/img/content/CBD_Night_A.jpg","/img/content/Claremont_A.jpg","/img/content/Swanbourne_A.jpg","/img/content/CP2.jpg","/img/content/Fremantle.jpg","/img/content/Kingspark.jpg","/img/content/Swanbourne2.jpg"];
var bgImagesNo = bgImages.length;
var randomNo = 1;
var divBub;
var divBubH;

$(document).ready(function() {	
	jQuery.preLoadImages("/img/load.gif","/img/content/CBD_Day.jpg","/img/content/CBD_Mall_A.jpg","/img/content/CBD_Night_A.jpg","/img/content/Claremont_A.jpg","/img/content/Swanbourne_A.jpg","/img/content/CP2.jpg","/img/content/Fremantle.jpg","/img/content/Kingspark.jpg","/img/content/Swanbourne2.jpg");
	
	$('#background').css('height','100%');
	
	if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		 $("footer").css({"position":"relative","z-index":999,"clear":"left"});
	};
	
	$(".service-box").live({
			mouseenter:
			   function()
			   {
					$(this).stop().find('div').animate({"width":'45%',"height":'35%',"bottom":40,"bottom":40}, 140, 'easeInOutQuint');
			   },
			mouseleave:
			   function()
			   {
				   	$(this).stop().find('div').animate({"width":'35%',"height":'25%',"bottom":30,"bottom":30}, 140, 'easeInOutQuint');
			   }
	});

	$("#subscribe, #client-login").live({
			mouseenter:
			   function()
			   {
					$(this).stop().find('div.ibox').css('display','block');
			   },
			mouseleave:
			   function()
			   {
				   	$(this).stop().find('div.ibox').fadeOut(300);
			   }
	});

	$(".box-link").live({
			mouseenter:
			   function()
			   {
				   	divBub = $(this).stop().find('div');
					divBubW = divBub.width();
					divBubH = divBub.height();
					divBubT = divBub.position().top;
					divBubL = divBub.position().left;
					$(this).stop().find('div').animate({"width":divBubW+10,"height":divBubH+10,"top":divBubT-10,"left":divBubL-10}, 140, 'easeInOutQuint');
			   },
			mouseleave:
			   function()
			   {
				   	$(this).find('div').animate({"width":divBubW,"height":divBubH,"top":divBubT,"left":divBubL}, 140, 'easeInOutQuint');
			   }
	});

	$("#logo").live({
			mouseenter:
			   function()
			   {
					$('#logo').animate({"width":300}, 140, 'easeInOutQuint');
			   },
			mouseleave:
			   function()
			   {
				   	$('#logo').animate({"width":256}, 140, 'easeInOutQuint');
			   }
	});

	$(".focus").live({
	  mouseenter: function() {
		var addElementID = $(this).attr('id');
		
		switch(addElementID) {
			case 'map':
				addElement = $('#contact');
				break;
			case 'contact':
				addElement = $('#map');
				break;
			case 'bottom-left-balloon':
				addElement = $('#bottom-left');
				break;
			case 'top-right-balloon':
				addElement = $('#top-right');				
				break;
			case 'top-right':
				addElement = $('#top-right-balloon');				
				break;				
			case 'bottom-right':
				addElement = $('#bottom-right-balloon');
				break;
			case 'bottom-right-balloon':
				addElement = $('#bottom-right');
				break;
			case 'top-right':
				addElement = $('#top-right-balloon');
				break;
			case 'top-right-balloon':
				addElement = $('#top-right');
				break;				
			default:
				addElement = '';
				break;
		}
		
		$('.focus, #background img').not(this).not(addElement).stop().fadeTo(1000,0.5);
		//$(this).find('div, aside').fadeTo(100,1);
		$(this).stop().fadeTo(100,1).find('aside, a div, aside#map').css('box-shadow','0px 0px 35px rgba(0,0,0,0.8)');
		
	  },
	  mouseleave: function () {
		$('.focus, #background img').stop().fadeTo(1000,0.9).find('aside,a div').css('box-shadow','none');
	  }
	});

	
	$("#logo a").live('click',function() {
		contentShift('home',null);
		return false;
	});	
	
	$(".service-box").live('click',function() {
		var section = $(this).attr('data-section');
		contentShift(section,"");
		return false;
	});

	$("nav#runner a, a.box-link, a[data-section=contact], a.shift").live('click',function() {
		var section = $(this).attr('data-section');
		var content = $(this).attr('data-content');
		contentShift(section,content);
		return false;
	});

	sizeElements();
	
	$(window).resize(function() {
  		sizeElements();
	});
	
	$('input[type=text], input[type=password], textarea').each(function() {
		$(this).attr('data-default',$(this).val());
	});
	
	$('input[type=text], input[type=password], textarea').live('focus',function() {
		$(this).val('');
	});
	
	$('input[type=text], input[type=password], textarea').live('blur',function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('data-default'));
		}
	});	
	
	$("#submit").live('click',function() {
		var name = $('input#name').val();
		var email = $('input#email').val();
		var number = $('input#number').val();
		var regarding = $('input#regarding').val();
		var query = $('#query').val();
		$('#contact-form').html('<p style="text-align:center;padding-top:40px;"><img src="/img/loader.gif" /></p>');
		$('#contact-form').load('/includes/submit.inc.php',{name:name,email:email,number:number,regarding:regarding,query:query}, function() { Cufon.refresh(); });
		return false;
	});		

	$("#subscribe input[type=submit]").live('click',function() {
		var email = $('#subscribe input[name=email]').val();
		$('#subscribe .ibox').html('<p style="text-align:center;padding:40px 0 0 40px;"><img src="/img/loader-b.gif" /></p>');
		$('#subscribe .ibox').load('/includes/subscribe.inc.php',{email:email}, function() { Cufon.refresh(); });
		return false;
	});	

	$("#contact-subscribe input[type=submit]").live('click',function() {
		var email = $('#contact-subscribe input[name=email]').val();
		$('#contact-subscribe').html('<p style="text-align:center;padding:40px 0 0 40px;"><img src="/img/loader.gif" /></p>');
		$('#contact-subscribe').load('/includes/subscribe.inc.php',{email:email}, function() { Cufon.refresh(); });
		return false;
	});

});

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

var contentShift = function(section,content) {
	
	$('article#interchange').animate({'opacity':0}, function() {
		randomNo = Math.floor(Math.random()*bgImagesNo);
		switch (section) {
			case 'home':
				$('#background').prepend('<img src="'+bgImages[randomNo]+'" width="100%" height="100%" alt="Intuity Partners" style="z-index: 1;opacity:0;">');
				var data = 'section=home';
				$.post("/home.inc.php", data, function(theResponse){
						$('article#interchange').html(innerShiv(theResponse, false));
						Cufon.refresh();
						$('article#interchange, #background img').animate({'opacity':1},500); 
						sizeElements();
				}); 
				break;
			case 'news':
				$('#background').prepend('<img src="'+bgImages[randomNo]+'" width="100%" height="100%" alt="Intuity Partners" style="z-index: 1;opacity:0;">');
				var data = 'section='+section;	
				if (content) { data = data+'&content='+content; }	
				
				$.post("/news.inc.php", data, function(theResponse){
						$('article#interchange').html(innerShiv(theResponse, false));
						Cufon.refresh();
						$('article#interchange, #background img').animate({'opacity':1},500); 
						sizeElements();
				}); 
				break;
			case 'case-studies':
				$('#background').prepend('<img src="'+bgImages[randomNo]+'" width="100%" height="100%" alt="Intuity Partners" style="z-index: 1;opacity:0;">');
				var data = 'section=case-studies';
				if (content != null) { data += '&content='+content; }
				$.post("/case-study.inc.php", data, function(theResponse){
						$('article#interchange').html(innerShiv(theResponse, false));
						Cufon.refresh();
						$('article#interchange,  #background img').animate({'opacity':1},500); 
						sizeElements();
				}); 
				break;
			case 'contact':
				$('#background').prepend('<img src="'+bgImages[randomNo]+'" width="100%" height="100%" alt="Intuity Partners" style="z-index: 1;opacity:0;">');
				var data = 'section=contact';
				$.post("/contact.inc.php", data, function(theResponse){
						$('article#interchange').html(innerShiv(theResponse, false));
						Cufon.refresh();
						$('article#interchange, #background img').animate({'opacity':1},500); 
						sizeElements();
				}); 
				break;
			default:
				$('#background').prepend('<img src="'+bgImages[randomNo]+'" width="100%" height="100%" alt="Intuity Partners" style="z-index: 1;opacity:0;">');
				var data = 'section='+section;	
				if (content) { data = data+'&content='+content; }
				
				$.post("/content.inc.php", data, function(theResponse){
						$('article#interchange').html(innerShiv(theResponse, false));
						Cufon.refresh();
						$('article#interchange, #background img').animate({'opacity':1},500); 
						sizeElements();
				}); 
				break;
		}
		$('#background img:last-child').remove();
	});
}

var sizeElements = function() {
	var browserWidth = $(window).width(); 
	if (browserWidth>1920) {
		fontSize = 14;
		h1Size = 26;
	}	
	if (browserWidth<=1920&&browserWidth>1680) {
		fontSize = 13;
		h1Size = 26;
	}
	if (browserWidth<=1680&&browserWidth>1440) {
		fontSize = 12;
		h1Size = 16;
	}
	if (browserWidth<=1440&&browserWidth>1280) {
		fontSize = 12;	
		h1Size = 16;
	}
	if (browserWidth<=1280) {
		fontSize = 12;
		h1Size = 16;
	}
	
	$('nav#client-types').css('height',$('#specialise').height());
	$('aside#balloons').css('height',$('aside#careers').height());
	//$('p').css("font-size",fontSize);
	//$('h1').css("font-size",h1Size);
	Cufon.refresh();
};

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

function startAnalytics() {
var pageTracker = _gat._getTracker("UA-8385425-3");
pageTracker._trackPageview();
}

if (window.addEventListener) {
	window.addEventListener('load', startAnalytics, false);
}
else if (window.attachEvent) {
	window.attachEvent('onload', startAnalytics);
}
