var sections = ['general','credits','services','scenes','awards','press','bts'];
var current_section ='';
var current_nav='';
var current_id =0;
var current_service;
var myQTObject;

var nav_holder = [];
var nav_titles = [];
var nav_cur_nav =  false;

function goBack()
{
	var it = nav_holder[nav_holder.length - 2];
	nav_holder.pop(); nav_holder.pop();
	nav_titles.pop(); nav_titles.pop();
	if (it)
	{
		popOver(it.id, it.nav);
	} else {
		//alert('can not go back'); // for debug
	}
}

function popOver(id,nav,callback)
{
	//document.getElementById('debugger').innerHTML = id;
	if (document.getElementById('mediaframe'))
	{
		document.getElementById('mediaframe').src = 'about:blank';
	}
	
	//if ((nav_cur_nav != nav && nav != undefined) || nav == 'reels')
	{
		nav_cur_nav = nav;
		nav_holder.push({id: id, nav: nav});
		//alert('added ' + nav + ' / ' + id); // debug...
	}
	//if (canPopOver)
//	{
		
	// # section
		if(!nav && !id){
			alert('problem')
		}
		
		
		if(id > 0){
			if(!nav){
				nav = 'features';
			}
			
		}else{
			nav = id;
			//nav = 7;
		}
			
		removeVideo('mediatime');
		if (document.getElementById('mainbody'))
		{
			document.getElementById('mainbody').className = '';	
		}
		
		switch(nav){
			case "features":
				var url = '/features_detail.php/?id='+id;
				document.getElementById('mainbody').className = 'features';
				break;
				
			case "commercials":
				var url = '/commercials_detail.php/?id='+id;
				document.getElementById('mainbody').className = 'commercials';
				break;
				
			case "reels":
				var url = '/reels.php?id='+id;
				break;
				
			case "email_reel":
				var url = '/reel_email.php?reel_id='+id;
				break;
				
			case "bts":
				var url = '/bts_features_detail.php?id='+id;
				break;
			
			case "press":
				var url = '/press_detail.php?id='+id;
				break;
			
			case "guidelines":
				var url = '/guidelines.php';
				break;
				
			case "eligibility":
				var url = '/eligibility.php';
				break;
			
			case "projects_gow":
				var url = '/projects_gow.php';
				break;
				
			case "projects_vw":
				var url = '/projects_vw.php';
				break;
				
				
		}
	// # end	
			
		current_nav = nav;	
		current_id =id;
		
		//url = '/features_detail.php/?id='+id;
		//document.getElementById('debugger').innerHTML = url;
		var args = {"url":url,"dataType":"TEXT","cache":"true"};
		callback= (callback?callback:popOverConfirm);	
		dd.ajax.sendRequest('GET',args,callback);			
	//}
}

function popOverConfirm(e)
{
	if (e == 'close')
	{
		closeOverlay();
		return;
	} else if (e.substr(0, 9) == 'redirect:') {
		window.open(e.substr(9, e.length));
		closeOverlay();
		return;
	}
	
	//document.getElementById('mainbody').className = '';
	var overlay = document.getElementById('overlay');
	overlay.innerHTML = e;
	overlay.style.display = 'block';
	selectedBackground('a_general');
	document.getElementById('flashMovie').style.visibility = 'hidden';
	sIFRConvert();
		
	switch(current_nav){
		case 'reels':
			//playVideo(current_id, current_nav);
			showReelService(current_id);
			break;
			
		case 'commercials':
		case 'bts':
			//playVideo(current_id, current_nav);
			showSection('general');
			break;
			
		case 'features':
			showSection('general');
			break;
		
	}
	
	if (document.getElementById('nav_title'))
	{
		nav_titles.push(document.getElementById('nav_title').innerHTML);
	} else {
		nav_titles.push('PREVIOUS PAGE');
	}
	
	var nav_name = current_nav;
	var nav_pg = nav_titles[nav_titles.length - 1];
	
	var no_track = 0;
	switch(nav_name)
	{
		case 'email_reel':
			no_track = 1;
			break;
		
		case 'bts':
			nav_name = 'behind the scenes';
			break;
		
		case 'projects_gow':
			nav_name = 'projects';
			nav_pg = 'Gears of War';
			break;
		
		case 'projects_vw':
			nav_name = 'projects';
			nav_pg = 'VW Interactive Campaign';
			break;
	}
	
	if (!no_track)
	{
		pageTracker._trackPageview('/' + nav_name + '/' + nav_pg);
	}
	
	if (document.getElementById('return'))
	{
		if (nav_holder.length >= 2)
		{
			var ret_title = nav_titles[nav_titles.length - 2];
			document.getElementById('return').style.display = 'block';
			//document.getElementById('return').innerHTML = '<a href="javascript:void(0);" class="white" onclick="goBack()">RETURN TO: ' + ret_title + '</a>';
			document.getElementById('return').innerHTML = '<a href="javascript:void(0);" class="grey" onclick="goBack()">' + ret_title + '</a>';
		} else {
			document.getElementById('return').style.display = 'none';
		}
	}

}


function closeOverlay()
{	
	nav_holder = [];
	//if(current_nav == 'reels' || current_nav == 'commercials'){
	removeVideo('mediatime');
	//}
	canPopOver = 1;
	
	if (document.getElementById('mediaframe'))
	{
		document.getElementById('mediaframe').src = 'about:blank';
	}
	
	var overlay = document.getElementById('overlay');
	document.getElementById('flashMovie').style.visibility = 'visible';
	overlay.style.display = 'none';	
}

function showSection(s)
{
	
	var div = document.getElementById('b_'+s);
	if(div){				
		div.style.display ='block';
		current_section =s;
	}
	
	for(var i=0; i < sections.length;i++){
				
		if(current_section != sections[i]){
			unSelectedBackground('a_'+sections[i]);	
			hideSection(document.getElementById('b_'+sections[i])) // hide non selected div
		}else{
			selectedBackground('a_'+sections[i]);
		}
	}
}



function showService(id,title)
{
	if (current_service != id && document.getElementById('services'+current_service))
	{
		document.getElementById('services'+current_service).className = "";
	}
	document.getElementById('ts').innerHTML = title;
	document.getElementById('sd').innerHTML = services_desc[id];
	document.getElementById('services'+id).className = "upper";
	current_service = id;
	document.getElementById('serviceNote').style.visibility = 'hidden';
	
}

// # reels
function showReel(id,e)
{
	if(!id){
		return;
	}
	if(e){
		current_reel_service = e;
	}
	removeVideo('mediatime');
	popOver(id,'reels');
	return false;
}

function showReelService(id)
{
	
	if(!id){
		return;
	}
	
	id = parseInt(id);
	var current_reel_service;
	switch(id){
		case 1:
			current_reel_service = 'dd';
			break;
		case 2:
			current_reel_service = 'characters';
			break;
		case 3:
			current_reel_service = 'vehicles';
			break;
		case 4:
			current_reel_service = 'environments';
			break;
		case 5:
			current_reel_service = 'natural';
			break;
		case 6:
			current_reel_service = 'mat';
			break;
		case 7:
			current_reel_service = 'liquid';
			break;
		case 8:
			current_reel_service = 'human';
			break;
		case 9:
			current_reel_service = 'composition';
			break;
	}	
		
	toggle(current_reel_service);
	if(document.getElementById(current_reel_service)){
		document.getElementById(current_reel_service).className = "select";
	}
	
	
}

function playVideo(id,section){
	
	if (document.getElementById('video_size'))
	{
		var d = document.getElementById('video_size');
		var data = d.innerHTML.split('x');
		var w = data[0];
		var h = data[1];
	} else {
		var w = 480;
		var h = 360;
	}
	myQTObject = new QTObject("/play_video.php?id="+id+"&section="+escape(section), "media_qt", w, (parseInt(h)+ 15));
	
	myQTObject.addParam("autoplay", "true");
	myQTObject.addParam("pluginspage", "http://quicktime.apple.com"); 
	myQTObject.addParam("bgcolor", "#1b1f1e");	
	myQTObject.addParam("controller", "true");
	myQTObject.addParam("enablejavascript", "true");
	myQTObject.addParam("cache", "true");
	
	if (!myQTObject.write('mediatime'))
	{
		return;
	}
	
	/*iowaQT.Swap("http://digitaldomain.staging.iowalab.com/play_video.php?id="+id+"&section="+escape(section));
	var pos = YAHOO.util.Dom.getXY('mediatime'); 
	YAHOO.util.Dom.setXY('qt_container', pos);*/
}

function clearIframe(id,section){
	window.frames[0].location.href = 'movie.php';
}


function removeVideo(div) {  
	return;
	var obj = document.media_qt;
	
    if (obj )
	{
		try
		{
			obj.Stop();
		}
		catch (err)
		{
			//alert(err);
		}
       
    }
    if(document.getElementById(div)){
    	div = document.getElementById(div);
   		div.innerHTML = '';
    }
    //iowaQT.Stop();
}

function hideSection(div)
{	
	if(div){
		div.style.display ='none';		
	}
}

function selectedBackground(div)
{
	if(document.getElementById(div)){
		/*document.getElementById(div).style.background = '#eb2227';
		document.getElementById(div).style.color = '#fff';	*/
		
		//document.getElementById(div).class = "on";		
		document.getElementById(div).className = "on";		
	}	
}

function unSelectedBackground(div)
{
	if(document.getElementById(div)){
		/*document.getElementById(div).style.background = '#1B1F1E';
		document.getElementById(div).style.color = '#a1a1a4';*/
		//document.getElementById(div).class = "";	
		document.getElementById(div).className = "";
	}				
}

function sIFRConvert(){
	
	
	switch(current_nav){
			case "features":
			case "commercials":
			case "reels":
			case "bts":
			case "press":
				sIFR.replaceElement(named({sSelector:"ul.pager li.page", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#a1a1a4", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=6"}));
				sIFR.replaceElement(named({sSelector:"ul.pager li.red", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=6"}));
				sIFR.replaceElement(named({sSelector:"h2.sifrRed", sFlashSrc:"/sifr/helvetica_45lght_18pt.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));
				sIFR.replaceElement(named({sSelector:"ul.pager li#red", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center&offsetTop=6"}));
				//sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"/helvetica_45lght_28pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"/sifr/helvetica_45lght_28pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#1b1f1e", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));

				sIFR.replaceElement(named({sSelector:"h1.sifrWhite_blackBG", sFlashSrc:"/sifr/helvetica_45lght_28pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));

				//sIFR.replaceElement(named({sSelector:"h1.sifrWhite_blackBG", sFlashSrc:"/helvetica_45lght_15pt.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				sIFR.replaceElement(named({sSelector:"h1.sifrGrey", sFlashSrc:"/sifr/helvetica_45lght_18pt.swf", sColor:"#a1a1a4", sLinkColor:"#a1a1a4", sBgColor:"#1b1f1e", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));
				sIFR.replaceElement(named({sSelector:"h2.sifrGrey", sFlashSrc:"/sifr/helvetica_45lght_15pt.swf", sColor:"#717073", sLinkColor:"#a1a1a4", sBgColor:"#1b1f1e", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));
				sIFR.replaceElement(named({sSelector:"h2.subheading", sFlashSrc:"/sifr/helvetica_45lght_15pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1"}));
				sIFR.replaceElement(named({sSelector:"h2.sifrRed2", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", sFlashVars:"textalign=left&offsetTop=0"}));

				break;
				
				
			case "guidelines":
				sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"sifr/helvetica_neue.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				break;
				
			case "eligibility":
				sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"sifr/helvetica_neue.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				break;
			
			case "projects_gow":
			case "projects_vw":
				//sIFR.replaceElement(named({sSelector:"h3.visible strong", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0}));
				sIFR.replaceElement(named({sSelector:"h3.visible strong", sFlashSrc:"/sifr/helvetica_45lght_18pt.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				//sIFR.replaceElement(named({sSelector:"h3.visible span", sFlashSrc:"/sifr/helvetica_neue.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0}));
				sIFR.replaceElement(named({sSelector:"h3.visible span", sFlashSrc:"/sifr/helvetica_45lght_18pt.swf", sColor:"#eb2227", sLinkColor:"#eb2227", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0}));
				sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"/sifr/helvetica_45lght_28pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1",preventWrap: 'false' ,forceSingleLine: 'false'}));

				//sIFR.replaceElement(named({sSelector:"h1.sifrWhite", sFlashSrc:"sifr/helvetica_neue.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				//sIFR.replaceElement(named({sSelector:"h2.sifrWhite", sFlashSrc:"sifr/helvetica_neue.swf", sColor:"#ffffff", sLinkColor:"#a1a1a4", sBgColor:"#000000", sHoverColor:"#eb2227", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
				sIFR.replaceElement(named({sSelector:"h2.sifrWhite", sFlashSrc:"/sifr/helvetica_45lght_28pt.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sBgColor:"#000000", sHoverColor:"#ffffff", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=1",preventWrap: 'false' ,forceSingleLine: 'false'}));

				break;
				
				
		}
};

var services_desc = {1:'These are the latest and greatest excerpts from our award-winning and visually stunning body of work.  From feature films to commercials, Digital Domain employs world-class talent and our standard of excellence is reflected in this epic montage.',
					 2:"From robots to animals, and most recently CG humans, Digital Domain has become known for pushing the envelope of the \"digital actor.\"  Here you'll find examples of our extensive character work throughout the years.",
					 3:"Cars, planes, trains, helicopters, spaceships... this reel showcases them all.  Digital Domain has an impressive ensemble of work from which we set the standard for automotive advertising and created some of the most epic movie moments in history.",
					 4:"Applying the best of 2D and 3D, Digital Domain creates complete surroundings in which characters and/or vehicles thrive and interact.  Our Environments reel showcases the expertise Digital Domain has applied to generate locations that don't exist, and even ones that \"once\" existed.",
					 5:"Re-creating the wrath of Mother Nature, we've advanced the reality and ferocity of our planet on both the big and small screens.  Using proprietary software, Digital Domain has created visually stunning events inspired by the unrelenting power of our surrounding world.  Whether the project calls for floods, tornadoes, volcanic eruptions, clouds, smoke, explosions or extreme weather conditions, Digital Domain has done them all.",
					 6:"A 2D or 3D art in which \"digital paintings\" are used as set-extensions, lighting environments and reflections, matte painting is one of the original forms of visual effects.  Digital Domain has pushed this classic art to its limits by creating striking locales and incredible sets for films and commercials.",
					 7:"One of the most difficult effects to achieve in CG is water and liquid, but Digital Domain's technical expertise and proprietary software keep us a cut above the competition.  This reel showcases several amazing projects we've completed using our exclusive workflow.",
					 8:"As advertising and cinema progress, so does the technology to create photo-real CG actors.  This reel displays broad steps in that direction and, whether it's extras in a war epic or a featured character in a commercial or film, Digital Domain is pioneering the technique." ,
					 9:"The art of integration is an essential part of the CG business and one for which Digital Domain has become known throughout the years.  Using proprietary compositing software, combining digital images with live-action photography has become second nature."
					}


function toggle(obj, curid) {
	if (curid != current_id)
	{
		if(document.getElementById(obj)){
			var el = document.getElementById(obj);
		}else{
			return;
		}
		
		var sibling = el.nextSibling;
	
		if( sibling.style.visibility == '' || sibling.style.visibility == 'hidden' ) { sibling.style.visibility = 'visible'; }
		else { sibling.style.visibility = 'hidden'; }
	}
}


function submitReelEmail()
{
	document.getElementById('sent_message').style.display = 'none';
	var args = {"url":'reel_email.php',"dataType":"TEXT","formid":"request"};
	dd.ajax.sendRequest('POST',args,submitReelCallback);
}

function submitReelCallback(e)
{
	if (e == 'ok')
	{
		document.getElementById('sent_message').style.display = 'block';
		document.getElementById('request').reset();
	} else {
		alert(e);
	}
}

var iowaQT = {
	qtobj:null,
	timer:0,
	
	init:function()
	{
		iowaQT.ffx = function()
		{
			try
			{ 
				var o = document.getElementById("media_qt"); 
				o.GetPluginStatus(); 
				iowaQT.qtobj = o; 
			}
			catch(e)
			{ 
				try 
				{ 
					var o = document.getElementById("media_qt_e"); 
					o.GetPluginStatus(); 
					iowaQT.qtobj = o; 
				}
				catch(e)
				{
					try 
					{ 
						var o = document.media_qt;
						o.GetPluginStatus(); 
						iowaQT.qtobj = o; 
					}
					catch(e)
					{
						try 
						{ 
							var o = document.media_qt_e;
							o.GetPluginStatus(); 
							iowaQT.qtobj = o; 
						}
						catch(e)
						{
							iowaQT.qtobj = null;
							//alert('did not find qt :(');
						}
					}
				}
			}
			
			if ((iowaQT.qtobj != null) && (iowaQT.qtobj.GetPluginStatus() == "Playable" 
				|| iowaQT.qtobj.GetPluginStatus() == "Complete"))
			{
				clearTimeout(iowaQT.timer);
				setTimeout('iowaQT.Play()',1000);
				return;
			} else {
				//alert('obj: ' + iowaQT.qtobj);
			}
			
			iowaQT.timer = setTimeout("iowaQT.ffx()", 700);
		}
		
		iowaQT.timer = setTimeout("iowaQT.ffx()", 700);
	},
	
	Play: function()
	{
		if (iowaQT.qtobj != null)
		{
			try
			{
				iowaQT.qtobj.Play();
			}
			catch (err)
			{
				alert('problem with play(): ' + iowaQT.qtobj.GetURL());
			}
		}
		return false;
	},
	
	Stop: function()
	{
		if (iowaQT.qtobj != null)
		{
			try
			{
				iowaQT.qtobj.Stop();
				document.getElementById('qt_container').style.visibility = 'hidden';
			}
			catch (err)
			{
				
			}
		}
		
		return false;
	},
	
	Swap: function(url)
	{
		if (iowaQT.qtobj)
		{
			try
			{
				//iowaQT.Stop();
				iowaQT.qtobj.SetURL(url);
				iowaQT.qtobj.SetControllerVisible(true);
				document.getElementById('qt_container').style.visibility = 'visible';
				iowaQT.ffx();
				//iowaQT.timeout = setTimeout(iowaQT.checkSwap, 100, url);
			}
			catch(err)
			{
				alert('problem on Swap():' + err);
			}
		}
		return false;
	},
	
	checkSwap: function(url)
	{
		var eurl = iowaQT.qtobj.GetURL();
		if (eurl == url)
		{
			clearTimeout(iowaQT.timeout);
			iowaQT.ffx();
		} else if (eurl != null) {
			alert(eurl);
			iowaQT.timeout = setTimeout(iowaQT.checkSwap, 300, url);
		}
	}
}
//iowaQT.init();