/***** JQUERY SWFOBJECT *****/

(function(f,h,i){function k(a,c){var b=(a[0]||0)-(c[0]||0);return b>0||!b&&a.length>0&&k(a.slice(1),c.slice(1))}function l(a){if(typeof a!=g)return a;var c=[],b="";for(var d in a){b=typeof a[d]==g?l(a[d]):[d,m?encodeURI(a[d]):a[d]].join("=");c.push(b)}return c.join("&")}function n(a){var c=[];for(var b in a)a[b]&&c.push([b,'="',a[b],'"'].join(""));return c.join(" ")}function o(a){var c=[];for(var b in a)c.push(['<param name="',b,'" value="',l(a[b]),'" />'].join(""));return c.join("")}var g="object",m=true;try{var j=i.description||function(){return(new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}()}catch(p){j="Unavailable"}var e=j.match(/\d+/g)||[0];f[h]={available:e[0]>0,activeX:i&&!i.name,version:{original:j,array:e,string:e.join("."),major:parseInt(e[0],10)||0,minor:parseInt(e[1],10)||0,release:parseInt(e[2],10)||0},hasVersion:function(a){a=/string|number/.test(typeof a)?a.toString().split("."):/object/.test(typeof a)?[a.major,a.minor]:a||[0,0];return k(e,a)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(a){if(!a.swf||this.expressInstallIsActive||!this.available&&!a.hasVersionFail)return false;if(!this.hasVersion(a.hasVersion||1)){this.expressInstallIsActive=true;if(typeof a.hasVersionFail=="function")if(!a.hasVersionFail.apply(a))return false;a={swf:a.expressInstall||this.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:this.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:a.swf,type:"application/x-shockwave-flash",id:a.id||"flash_"+Math.floor(Math.random()*999999999),width:a.width||320,height:a.height||180,style:a.style||""};m=typeof a.useEncode!=="undefined"?a.useEncode:this.encodeParams;a.movie=a.swf;a.wmode=a.wmode||"opaque";delete a.fallback;delete a.hasVersion;delete a.hasVersionFail;delete a.height;delete a.id;delete a.swf;delete a.useEncode;delete a.width;var c=document.createElement("div");c.innerHTML=["<object ",n(attrs),">",o(a),"</object>"].join("");return c.firstChild}};f.fn[h]=function(a){var c=this.find(g).andSelf().filter(g);/string|object/.test(typeof a)&&this.each(function(){var b=f(this),d;a=typeof a==g?a:{swf:a};a.fallback=this;if(d=f[h].create(a)){b.children().remove();b.html(d)}});typeof a=="function"&&c.each(function(){var b=this;b.jsInteractionTimeoutMs=b.jsInteractionTimeoutMs||0;if(b.jsInteractionTimeoutMs<660)b.clientWidth||b.clientHeight?a.call(b):setTimeout(function(){f(b)[h](a)},b.jsInteractionTimeoutMs+66)});return c}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject);

//$.flash.expressInstaller = 'myFlashPath/expressInstall.swf';

/***** EASING *****/

jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeInOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInExpo:function(e,f,a,h,g){return(f===0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f===0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInRegular:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutRegular:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutRegular:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a}});

/**
 * http://detectmobilebrowser.com/
 * jQuery.browser.mobile will be true if the browser is on a mobile device
 **/
(function(a){jQuery.browser.mobile=/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))})(navigator.userAgent||navigator.vendor||window.opera);

/***** MOUSEWHEEL LISTENER *****/

(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(i){var g=i||window.event,f=[].slice.call(arguments,1),j=0,h=true,e=0,d=0;i=c.event.fix(g);i.type="mousewheel";if(i.wheelDelta){j=i.wheelDelta/120}if(i.detail){j=-i.detail/3}d=j;if(g.axis!==undefined&&g.axis===g.HORIZONTAL_AXIS){d=0;e=-1*j}if(g.wheelDeltaY!==undefined){d=g.wheelDeltaY/120}if(g.wheelDeltaX!==undefined){e=-1*g.wheelDeltaX/120}f.unshift(i,j,e,d);return c.event.handle.apply(this,f)}})(jQuery);

/***** jQuery reverse $("selecteor").reverse(); Returns revered array. *****/

$.fn.reverse = [].reverse;



function setCSS(css) {
	try{
		document.write(css);
	}catch(e){
		setTimeout(function(){setCSS(css)}, 100);
	}
}
var css = '<style id="jscss" type="text/css">#overlay{opacity:1;filter:alpha(opacity=100);z-index:4;}#inner{width:0;}</style>';
setCSS(css);
css = null;

function workCallouts(){
	$(".fadeCallouts.caseStudies a").hover(function(){
		$("img", this).stop().fadeTo(200, 0);
	},function(){
		$("img", this).stop().fadeTo(300, 1);
	});
	$(".fadeCallouts a").not($(".fadeCallouts.caseStudies a")).fadeTo(0, 0.65);
	$(".fadeCallouts a").not($(".fadeCallouts.caseStudies a")).hover(function(){
		$(this).stop().fadeTo(100, 1);
	},function(){
		$(this).stop().fadeTo(500, 0.65);
	});
	
	//Awards
	
	/*$(".fadeCallouts li").each(function(){
		if($("span", this).find("img").length == 0){
			var before = $("span", this).height();
			$("span", this).css("height", "auto");
			var auto = $("span", this).height();
			//15px needs to be sorted out;
			var calc = (auto / 15)
			$("span", this).css("line-height", before / calc+"px");
			$("span", this).css("height", before);
		}
	});*/
	var Þ = $("#rightColumn .rightArrow");
	if(Þ.html() == ""){
		Þ.hide();
	}
}

function showSite(){
	$('#overlay').stop().fadeTo(1000,0,'easeInRegular',function(){
		$('#overlay').css('z-index','2').fadeTo(1300,opacity,'easeOutRegular');
		$('#inner').animate({
			width:960
		},1400,'easeOutQuint',function(){
			//$('#inner').css('overflow','visible')
			if($('#contactBox').size() > 0){
				$('#contactBox').animate({
					width:$('#contactBoxInner').width()
				},500,'easeOutRegular');
			}
			$('#top, #leftColumn, #footerWrap').stop().fadeTo(2000,1,'easeOutRegular',function(){
				$('#jscss').remove();
				$(this).removeAttr('style');
			});
			//Custom Listener for when the page is tweened into existance:
			$(document).trigger("tweenReady");
		})
	});
	
	$('#overlay, #inner, #top, #leftColumn, #footerWrap, #contactBox').stop(true, true);
}

calloutArray=[];

calloutArray.push(['<h3><a href="/">site-zero</a></h3><p>the new, improved, iampms.com<br/><a href="/">Explore case study</a></p>', "/pics/right_at_you.jpg"]);	
calloutArray.push(['<h3><a href="//">1</a></h3><p>test <br/><a href="r/">Explore case study</a></p>', "/pics/dude.jpg"]);
calloutArray.push(['<h3><a href="//">2</a></h3><p>test deliver <br><a href="/">Explore case study</a></p>', "/pics/i_am_small.jpg"]);

flashvars = {};
for(i=0; i<calloutArray.length; i++){
	flashvars["video" + i] = calloutArray[i][1];
}

function changeCallout(n){
	$('#homeRight').animate({
		height:'4px',
		marginBottom:'148px'
	},500, 'easeOutRegular',function(){
		$('#homeRightInner').html(calloutArray[n][0]);
		$('#homeRight').animate({
			//height: $('#homeRightInner').outerHeight()
			height: '122px',
			marginBottom: '30px'
		},500, 'easeOutRegular');
	});
}


function initSite(){
	changeCallout(0);

	
	if(animated == 'yes' && $('#background img').size() > 0 && navigator.platform.indexOf("iPad")==-1 && !jQuery.browser.mobile){

	$('#top, #leftColumn, #footerWrap').fadeTo(0,0);
			var imgSrc = $('#background img:first').attr('src');
			var img = eval["img" + imgSrc.slice(imgSrc.lastIndexOf("/") + 1, imgSrc.lastIndexOf("."))];
			img = new Image();
			img.onload = function (evt){
				showSite();
			};
			img.src = imgSrc;
	}else{
		$('#overlay').css('z-index','2').fadeTo(0,opacity);
		$('#inner').width(960);
	}
	//setInterval( "changeCallout(1)", 3000 );
	//setInterval( "changeCallout(2)", 10000 );
}
function findHeight($this){
	var height = 0;
	$this.find('> *').each(function(){
		height += $(this).outerHeight();
	});
	return height;
}

var mouseDown = false;
var currentX = 0
var startX = 0;
var sX = 0
var eX = 0;
var newPos = 0;
var d = new Date();
var t1 = 0;
var t2 = 0;
function showCasePos(){
	var sWidth = $(window).width();
	var remainder = (sWidth / 2) - (652 / 2) - 652;
	var xOffset = $('#wideColumn').offset().left - remainder;
	if(sWidth < 960){
		sWidth = 960;
	}
	$('#showcase').css('margin-left', -xOffset).width(sWidth - $('#showcase').offset().left);
}

function mobileHandler(){
	if(navigator.platform.indexOf("iPad")>=0 || jQuery.browser.mobile){
		$('#background').flash().remove();
		$("#background").css("background-image", "url("+$("#background img").attr("src")+")");
		$("#background img").remove();
		$("#background img, #background, #overlay").css("height", $("#wrap").height()+"px");
		$(window).resize(function() {
			$("#background img, #background, #overlay").css("height", $("#wrap").height()+"px");
		});
	}
}
var tabdata = {};
function tabs(tar){
	$("a", tar).each(function(){
		$($(this).attr("href")).hide();
	});
	$("a", tar).click(function(e){
		if(!$(this).hasClass("on")){
			tabdata.target = this;
			
			$(".on", tar).fadeTo(0, 0.65);
			$(".on", tar).hover(function(){
				$(this).stop().fadeTo(100,1);
			},function(){
				$(this).stop().fadeTo(500,0.65);
			});
			$(".on", tar).removeClass("on");
			$(this).addClass("on").unbind("mouseenter mouseleave");
			$(this).stop().fadeTo(100,1);
			
			//$("#tab-data").empty().append($($(this).attr("href")).html());
			
			$("#tab-data").fadeTo(100,0, function(){
				$("#tab-data").empty().append($($(tabdata.target).attr("href")).html())
				.fadeTo(500, 1);
			});
			
		}
		e.preventDefault();
		return false;
	});
	$(tar).after("<div id='tab-data'></div>");
	$("a", tar).first().click();
}

function hotfix(){
	//Sorts awards into newest first. Need to get someone in back end to make a perma-fix;
	//$("#awards").empty().append($("#awards").find("li").reverse());
	
	$("head").append('<meta name="SKYPE_TOOLBAR" content="SKYPE_TOOLBAR_PARSER_COMPATIBLE" />');
	
	if($(".thankyou").length !== 0){
		$(".thankyou").each(function(){
			$(this).parents(".formDownInner").find(".arrowBtn").click();
		});
	}
}

function dev(){
	if(document.location.hash == "#dev"){
	}else{
	}
}

$(function(){
	//fadeEl();
	initSite();
	//formDown();
	//ddCallouts();
	//blogArchive();
	//footer();
	//showcaseInit();
	
	//imageSliderPeople();
	//dropdown("#leftNav");
	//tabs("#tabs");
	workCallouts();
	//mobileHandler();
	
	//hotfix();

	//dev();
});

$(window).unload(function(){});
