preloadImages('images','strategic_hover.png','strategic_subnav.png'
			  ,'creative_subnav.png','creative_hover.png'
			  ,'production_subnav.png','production_hover.png'
			  ,'interactive_subnav.png','interactive_hover.png'
			  ,'media_subnav.png','media_hover.png'
			  ,'principals_subnav.png','principals_hover.png'
			  ,'account_service_subnav.png','account_service_hover.png');
preloadImages('images','nav_home_hover.png','nav_work_hover.png','nav_people_hover.png','nav_contact_hover.png','nav_case_studies_hover.png','nav_careers_hover.png','nav_blog_hover.png','nav_all_we_do_hover.png', 'arrow.png');

var flashHeaderMovie;

function introEnded(){
	var flashvars = {};
	var params = {};
	params.play = "true";
	params.loop = "false";
	params.menu = "false";
	params.quality = "best";
	params.scale = "noscale";
	params.wmode = "transparent";
	params.allowfullscreen = "false";
	params.allowscriptaccess = "always";
	params.allownetworking = "all";
	var attributes = {};
	attributes.id = "master_flash";
	attributes.name = "master_flash";
	swfobject.embedSWF("flash/master.swf", "flash_header_master", "100%", "100%", "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes);
	setTimeout(masterLoaded,3000);
}



function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1; 
	return (isIE) ? window[movieName] : document[movieName];
}

function initAnimation(){
	try{
		flashHeaderMovie.initAnimation();
	}catch (e){
		setTimeout(initAnimation,500);	
	}
}

function masterLoaded(){
	$('body').css({
		backgroundColor:'#241B09',
		backgroundImage:'url(../images/bgbg.jpg)'
	});
	$('#flash_header_intro').remove();
	introEnded = true;
	$('#flash_header').css({height:'733px','padding-top':'0px',width:'100%'});
	$('#flash_header_master').css({visibility:'visible'});
	$('#master_flash').css({visibility:'visible'});
	$('#html_container').css({visibility:'visible'});
	flashHeaderMovie = getFlashMovie('master_flash');
	initAnimation();
}

function makePeople(){
	$(".cross_plus").hover(function(){
		if ($(this).attr('currentsrc')=='plus'){
			$(this).children('img').attr('src','images/x.png');
		}
	},function(){
		if ($(this).attr('currentsrc')=='plus'){
			$(this).children('img').attr('src','images/plus.png');
		}
	}
	);
	$('.cross_plus').click(function(e){
		e.preventDefault();
		$(this).attr('currentsrc','x').parent().parent().parent().siblings().children('div').children('div.person_title_x').children('a').attr('currentsrc','plus').children('img').attr('src','images/plus.png');
		var person = $(this).attr('person');
		$(this).parent().parent().parent().parent().children('div.person_what_matters').scrollTo('#'+person+'s_what_matters',{duration:500});
	});
}

function navButtons(){
	var navButtons = $('.button img:first-child');
	$('#home_button img:first-child').attr('src','images/nav_home_hover.png');
	navButtons.bind('mouseover', function(e){
		if ($(this).parent().attr('id') !=  nav_ul.attr('selected')){
			$(this).attr('src', $(this).attr('hoversrc'));
		}
	});
	navButtons.bind('mouseleave', function(e){
		if ($(this).parent().attr('id') !=  nav_ul.attr('selected')){
			$(this).attr('src', $(this).attr('origsrc'));
		}
	});
	$('#blog_button').bind('mouseover', function(e){
		$('#blog_img').attr('src', $('#blog_img').attr('hoversrc'));
	});
	$('#blog_button').bind('mouseleave', function(e){
		$('#blog_img').attr('src', $('#blog_img').attr('origsrc'));
	});
}

function showWork(){
	$.scrollTo(0);
    htmlContainer.animate({ marginTop: '-57px', height: '147px' }, 500);
	portfolioVisible = true;
}

function hideWork() {
	$.scrollTo(0);
	htmlContainer.animate({marginTop:'-362px',height:'457px'},500);
	portfolioVisible = false;
}

function showCaseStudies(){
	$.scrollTo(0);
    htmlContainer.animate({ marginTop: '-57px'}, 500);
	caseStudiesVisible = true;
}

function hideCaseStudies() {
	$.scrollTo(0);
	htmlContainer.animate({marginTop:'-362px'},500);
	caseStudiesVisible = false;
}

function addOverlays(){
	var overlay = '<div class="overlay"><div><img src="images/overlay_color.png" width="100%" height="100%" class="inner_overlay" /></div></div>';
	var empty_overlay = '<div class="empty_overlay"><div><img src="images/overlay_color.png" width="100%" height="100%" class="inner_overlay" /></div></div>';
	var empty_overlay_marg = '<div class="empty_overlay_marg"><div><img src="images/overlay_color.png" width="100%" height="100%" class="inner_overlay" /></div></div>';
	$('.space').each(function(){
		if ($(this).html()=='')
			$(this).append(empty_overlay);
		else{
			$(this).append(overlay);
		}
	});
	$('.empty_space').append(empty_overlay);
	$('.empty_space.marg').empty().append(empty_overlay_marg);
}

$(document).ready(function(){
	scrollablePage();
	addOverlays();
	var offsetLeft = -(win.width()-850)/2;
	if (win.width()>MAX_WIDTH){
		offsetLeft = -(MAX_WIDTH-850)/2;
	}
	setTimeout(function(){
		$('#viewable').scrollTo("#home_space",{offset:{left:offsetLeft,top:offsetTop}});
	}, 600);
	$('#home_space').children('.overlay').hide();
	navButtons();
	makePeople();
	$('#portfolio_show_button').click(function(e){
		e.preventDefault();
		showWork();
		flashHeaderMovie.showPortfolio();
	});
	
	$('.case_studies_button').click(function(){
		showCaseStudies();
		flashHeaderMovie.showCaseStudies($(this).attr('id'), 'http://www.mmaustin.com/flash/xml/CaseStudies/'+$(this).attr('id')+'.xml');
	});
});

function flashAlert(toSay){
	alert ("Flash Says: "+toSay);	
}

function mouseOverStrategic(){
	$('#strategic_planning').mouseover();
}
function mouseOutStrategic(){
	$('#strategic_planning').mouseleave();
}

function gotoStrategic(){
	$('#strategic_planning').click();
}

function mouseOverCreative(){
	$('#creative').mouseover();
}
function mouseOutCreative(){
	$('#creative').mouseleave();
}

function gotoCreative(){
	$('#creative').click();	
}

function mouseOverProduction(){
	$('#production').mouseover();
}
function mouseOutProduction(){
	$('#production').mouseleave();
}

function gotoProduction(){
	$('#production').click();
}

function mouseOverInteractive(){
	$('#interactive').mouseover();
}
function mouseOutInteractive(){
	$('#interactive').mouseleave();
}

function gotoInteractive(){
	$('#interactive').click();	
}

function mouseOverMedia(){
	$('#media').mouseover();
}
function mouseOutMedia(){
	$('#media').mouseleave();
}

function gotoMedia(){
	$('#media').click();	
}

function mouseOverAllWeDo(){
	$('#all_we_do').mouseover();
}
function mouseOutAllWeDo(){
	$('#all_we_do').mouseleave();
}

function gotoAllWeDo(){
	$('#all_we_do').click();
}

function makeAllWeDoButtons(){
	/*	
	$('#all_we_do').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'all_we_do')
			flashHeaderMovie.mouseOverAllWeDo();
	});
	$('#all_we_do').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'all_we_do')
			flashHeaderMovie.mouseOutAllWeDo();
	});
	*/
	
	$('#all_we_do').bind('click',function(e){
		if (subnav.attr('selected') != 'all_we_do')
			flashHeaderMovie.gotoAllWeDo();
	});
	
	/*
	$('#media').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'media')
			flashHeaderMovie.mouseOverMedia();
	});
	$('#media').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'media')
			flashHeaderMovie.mouseOutMedia();
	});
	*/
	
	$('#media').bind('click',function(e){
		if (subnav.attr('selected') != 'media')
			flashHeaderMovie.gotoMedia();
	});
	
	/*
	$('#interactive').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'interactive')
			flashHeaderMovie.mouseOverInteractive();
	});
	$('#interactive').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'interactive')
			flashHeaderMovie.mouseOutInteractive();
	});
	*/
	
	$('#interactive').bind('click',function(e){
		if (subnav.attr('selected') != 'interactive')
			flashHeaderMovie.gotoInteractive();
	});
	
	/*
	$('#production').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'production')
			flashHeaderMovie.mouseOverProduction();
	});
	$('#production').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'production')
			flashHeaderMovie.mouseOutProduction();
	});
	*/
	
	$('#production').bind('click',function(e){
		if (subnav.attr('selected') != 'production')
			flashHeaderMovie.gotoProduction();
	});
	
	/*
	$('#creative').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'creative')
			flashHeaderMovie.mouseOverCreative();
	});
	$('#creative').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'creative')
			flashHeaderMovie.mouseOutCreative();
	});
	*/
	
	$('#creative').bind('click',function(e){
		if (subnav.attr('selected') != 'creative')
			flashHeaderMovie.gotoCreative();
	});
	
	/*
	$('#strategic_planning').bind('mouseover',function(e){
		if (subnav.attr('selected') != 'strategic_planning')
			flashHeaderMovie.mouseOverStrategic();
	});
	$('#strategic_planning').bind('mouseout',function(e){
		if (subnav.attr('selected') != 'strategic_planning')
			flashHeaderMovie.mouseOutStrategic();
	});
	*/
	
	$('#strategic_planning').bind('click',function(e){
		if (subnav.attr('selected') != 'strategic_planning')
			flashHeaderMovie.gotoStrategic();
	});
}

$(document).ready(function(){
	$('#acc_service_next').click(function(e){
		e.preventDefault();
		$('#people_subspace_viewable').scrollTo('#acc_service_2',{duration:speed});
	});
	$('#acc_service_prev').click(function(e){
		e.preventDefault();
		$('#people_subspace_viewable').scrollTo('#acc_service_1',{duration:speed});
	});
	
	$('#acc_service_next_img').bind('mouseover', function(e){
		$('#acc_service_next_img').attr('src', $('#acc_service_next_img').attr('hoversrc'));
	});
	$('#acc_service_next_img').bind('mouseleave', function(e){
		$('#acc_service_next_img').attr('src', $('#acc_service_next_img').attr('origsrc'));
	});
	
	$('#acc_service_prev_img').bind('mouseover', function(e){
		$('#acc_service_prev_img').attr('src', $('#acc_service_prev_img').attr('hoversrc'));
	});
	$('#acc_service_prev_img').bind('mouseleave', function(e){
		$('#acc_service_prev_img').attr('src', $('#acc_service_prev_img').attr('origsrc'));
	});
});