	/**
 * @author mfox
 */

var objectName = "flashMovie";

var bContactShown = false;
var bInTransition = false;

var flashObj;
var divHeaderHeight = 0;
var topbarHeight = 0;
var submenuHeight = 0;
var contactHeight = 0;

var date = new Date();
date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
var cookie_options = { path: '/', expires: date };
var flashvars = { opened:0 };
var params = { wmode:"transparent", base:"/assets/flash/ericstein", allowScriptAccess: "sameDomain"};
var attributes = {id:objectName};

/*
Ericstein calls: openFlash flashClosed
Javascript tells ericstein: resizeFlash & readyToOpen

openFlash & closeFlash
*/

function onWindowResize()
{

	steinSize();
	alignSliderNav ();
	
	
/*
	if (bShowEric)
	{
		onFlashResize();
	}
*/
	
	// position submenu
	var subOffset = $('#submenu ul').offset();
	if (subOffset)
	
	{
		subOffset.left = $('.nav ul').offset().left;
		//$('#submenu ul').offset(subOffset);
		//$('#contact-container').offset(subOffset);
		//alert(subOffset.left);
	}
}


function embedFlash()
{		
	swfobject.embedSWF("/assets/flash/ericstein/ericsteinLoader.swf", "feature-flash", "100%","100%", "9.0.0","/lib/swfobject/expressInstall.swf", flashvars, params, attributes);	
}

function steinSize (){
	divHeaderHeight = $("#topbar").height();
	var fheight = $(window).height() - divHeaderHeight;
	$("#steinInnerWrapper").css('height',fheight);
}

function openFlash()
{
	
	divHeaderHeight = $("#topbar .home").height();
	var fheight = $(window).height() - divHeaderHeight;
	
	
	$("#content,#footer,#controls").fadeOut(500);
	
	if ($('#contact-content').is(':visible')){
		toggleContact();
	}
	setTimeout (function(){

		$("#slider,#steinOuterWrapper").css('height',fheight);
	
		$("#feature").animate({'height':fheight},500,function(){
			var flashObject = document.getElementById(objectName);
			if (flashObject && typeof flashObject.readyToOpen != "undefined"){
				flashObject.readyToOpen($(window).width(),fheight);
			}
		});
		
	},500);
}

function closeFlash()
{	

	$("#feature").animate({'height':'421px'},500,function(){

		$("#slider,#steinOuterWrapper").css('height','382px');

		$("#content,#footer,#controls").fadeIn(500);

	});
	
}

function initSubmenu()
{
	populateContactMenu();
	
	//originalHeight = $("#feature").height();
	//originalFlashHeight = 382; //$("#feature-flash").height();
	divHeaderHeight = $("#topbar").height();
	onWindowResize();
	submenuHeight = $('#submenu').height(); 
	
	submenuActive = $('#submenu ul li').hasClass('active');
	
	if (submenuActive)
	{
		$('#submenu').show();
		$("#topbar").css({height:divHeaderHeight + submenuHeight});
	}else
	{
		$('#submenu').hide();
			setTimeout(function(){
			$('#submenu').show('blind', {easing:'easeOutCubic'}, 500);
			$("#topbar").animate({height:divHeaderHeight + submenuHeight}, 500);
		}, 500);
	}  

	
	
}

function showUnsupported()
{
	$.ajax({ url: "/home/unsupported-message", context: document.body, success: function(data){
		$.fancybox({
			'padding'		: 0,
			'modal' 		: true,
			'content'		: data,
			'width'			: 520,
			'height'		: 375,
			'autoDimensions': false,
			'transitionIn'	: 'elastic',
			'scrolling'		: 'no'
		});
	}});
}

function toggleContact()
{
	if (!bContactShown && !bInTransition)
	{
		bInTransition = true;
		bContactShown = true;
		topbarHeight = $("#topbar").height();

		$('#contact-content').show('blind', {easing:'easeOutCubic'}, 500);
		$("#topbar").animate({height:divHeaderHeight + contactHeight}, 500, function(){ bInTransition = false; });
	}
	else if (!bInTransition)
	{
		bInTransition = true;
		bContactShown = false;
		$('#contact-content').hide('blind', {easing:'easeOutCubic'}, 500);
		$("#topbar").animate({height:topbarHeight}, 500, function(){ bInTransition = false; });
	}
}
	
function populateContactMenu()
{
	$.ajax({ url: "/contact/contact-content", context: document.body, success: function(data){
		$(data).appendTo($('#nav5'));

		$('#nav5 a[title="Contact"]').click(function(e){
			e.preventDefault();
			toggleContact();
		});
		contactHeight = $('#contact-content').height();
		$('#contact-content').hide();
      }});	
}

function hideLocations(e)
{
	if (e.success)
	{
		$('#locations-container').hide();
	}
}

function noFlash()
{
	this.getContainer().innerHTML = '<h2>Flash version 9.0 or greater is required</h2><h3>You have no Flash plugin installed</h3><p>Download latest version from <a href="http://www.adobe.com/go/getflashplayer">here</a></p>';
}

function featureRotator ()
{
    var numberOfSlides = $('#slider').find('ul li').length;
    
    if(numberOfSlides > 1){
	    $('#slider').easySlider({
			controlsShow: true,
			speed: 500,
			pause: 5000,
			numeric: true
		});
		
		featureThumbs();    
    }
 
}

/*Adding thumbnails to slider controls*/
function featureThumbs (){
	
	$("#controls a").html("");
	alignSliderNav ();
		
	var thumbnails = [
		"url(/assets/images/feature/thumbs/thumb_ericstein.jpg)",
		"url(/assets/images/feature/thumbs/thumb_kalbitor.jpg)",
		"url(/assets/images/feature/thumbs/iq.gif)"
	]
	
	var i = 0;
	
	$("#controls a").each(function(){
		$(this).css('background-image',thumbnails[i]);
		i++;
	});
		
}

/*Aligning slider controls since its parent container is full width of screen.  Also gets called when window resizes*/
function alignSliderNav (){

	var windowWidth = $(window).width();
	var leftX = Math.round((windowWidth - 976) / 2 - 3);
	$("#controls").css('left' , leftX + 'px');

}

/*Fading in and out the text for the Clio and MMM awards*/
var headlines = ['#clioAwards_leftColumn', '#mmmAwards_leftColumn'];
var headlineIndex = 0;
var currentHeadline = headlines[headlineIndex];
var loopAnimation = true;

function textFade (){
	textFadeOutDelay();
	$('#awardsTextFade').click(function(){
		loopAnimation = false;
	});
}

function textFadeOutDelay() {
	if (loopAnimation)
	{
		setTimeout (textFadeOut , 10000);
	}
}

function textFadeOut() {
	if (loopAnimation)
	{
		$(currentHeadline).fadeOut(1000, textFadeIn);
	}
}

function textFadeIn() {
	if (loopAnimation)
	{
		headlineIndex++;
	}
	
	if (headlineIndex == headlines.length)
	{
		headlineIndex = 0;
	}
	currentHeadline = headlines[headlineIndex];
	$(currentHeadline).fadeIn(1000, textFadeOutDelay);
}

function tabControl () {
var i;	
	$("#tabsContainer .tab").click(function(){
		$("#tabsContainer .tab").css("zIndex","0");
		$(this).css("zIndex","2");
		$("#tabsContainer > div").removeClass('active');
		$(this).parent().parent().addClass('active');
	});

}
