// JavaScript Document

window.enablelogging = true;
window.hide_jshidden = true;
window.generatePlayers = false;
window.downloadVideoSuffix = ' - Computer';
window.flashVideoSuffix = ' - iPhone.m4v';
window.flashVersionMajor = 9;
window.flashVersionMinor = 115;
window.correctFlash = false;
window.quicktimeInstalled = false;
window.comingsoon = 'coming soon...';
//window.siteRoot = 'http://'+window.location.href.split('/')[2]+'/';
window.siteRoot = window.location.href.split('#')[0];
window.deeplink = false;

window.imagePosterPrefix = 'images/480x360/';
window.imageThumbPrefix = 'images/105x63/105:63/';

//alert(window.location.host+"\n"+window.location.hostname+"\n"+window.location.port+"\n"+window.location.protocol)

if (navigator.plugins) {
  for (i=0; i < navigator.plugins.length; i++ ) {
	   if (navigator.plugins[i].name.indexOf("QuickTime") >= 0)
			{ window.quicktimeInstalled = true; }
	}
}

window.trace = function(msg){
	if(console){
		console.log(msg);
	}else{
		alert(msg);
	}
}
window.hideAllLevel1 = function(el){
	$$("#nav ul li ul").each(function(item,index){
		$(item).active = false;
		$(item).fade('hide');
		$(item).setStyle('visiblity','hidden');
	});
}
window.hideAllLevel2 = function(el){
	$$("#nav ul li ul li ul").each(function(item,index){
		$(item).active = false;
		$(item).fade('hide');
		$(item).setStyle('visiblity','hidden');
	});
}
var slideshowInt = null;
var slideshowIndex = null;
var slideshowTotal = null;
var slideshowTime = 5000;

window.updateWindowLocation = function(str){
	//window.location.href = window.siteRoot.split("#")[0]+str;
	hashstr = str.split('_').join('/').split('-').join(' ');
	window.location.hash = hashstr;
	
	/*
	var sections = str.split('_')
	
	if(sections.length == 2){
		var match1 = sections.join('_')
		var el = window.findHrefMatch(match1)
		//alert(el)
		window.revealSection.delay(250,window.findHrefMatch(match1).getParent().getElements('ul')[0]);
		
	}else if(sections.length == 3){
		
		window.revealSection.delay(250,window.findHrefMatch(match1).getParent().getElements('ul')[0]);
		window.revealSection.delay(500,window.findHrefMatch(match2).getParent().getElements('ul')[0]);
		
	}else if(sections.length == 4){
		
		window.revealSection.delay(250,window.findHrefMatch(match1).getParent().getElements('ul')[0]);
		window.revealSection.delay(500,window.findHrefMatch(match2).getParent().getElements('ul')[0]);
		window.revealSection.delay(750,window.findHrefMatch(match3).getParent().getElements('ul')[0]);
		
	}
	*/
}
window.findHrefMatch = function(str){
	
	var found = false;
	var el = null;
	
	$$('#nav a').each(function(item,index){
							   
		if (found) return;
		
		//window.trace($(item).get('href')+'=>'+str);
		
		if($(item).get('href') == str){
			
			found = true
			
			el =  $(item);
			
			//return $(item);
			
		}
	});
	
	return  el;
		
}
window.ajaxViewHide = function(){
	
	clearInterval(slideshowInt);
	
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_title')[0].set('html','');
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_client')[0].set('html','');
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_agency')[0].set('html','');
	
	$('videocontainer').set('html','');
	
	$('ajaxview').fade('hide')
}
window.revealSection = function(){
	this.fade('in')
}
window.ajaxViewShow = function(){
	$('ajaxview').fade('in')
}

window.ajaxViewPage = function(el){

	$('ajaxview').fade('hide')
	$('pageview').setStyles({display:'block',visibility:'visible'})
	$('pageview').fade('hide')
	
	var content = $(el.substr(1)).getParent().getElements('div')[0].get('html');

	$('pageview').set('html',content);
	
	if(el == '#_Home'){
		window.showHomePageItunes();	
	}
	$('pageview').fade('in');
}
window.ajaxViewDirectorShortcut = function(lnk){
	
	var lnk = lnk.split('_')
	/*
	$$("#nav ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
	$$("#nav ul li ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]+'_'+lnk[2]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
	*/
	$$("#nav ul li ul li ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]+'_'+lnk[2]+'_'+lnk[3]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
}
window.ajaxViewDirector = function(el){
	
	clearInterval(slideshowInt);
	
	var oriel = el;
	var section = oriel.split('_')[1];
	var profile = $(el.substr(1)).getParent().getElements('p')[0].get('html');
	var director = $(el.substr(1)).getParent().getElements('h3')[0].getElements('span')[0].get('html');
	var el = $(el.substr(1)).getParent().getElements('dl')[0].getElements('dl');
	//var elm = $(el.substr(1)).getParent().getElements('dl');
	
	$('ajaxview').setStyles({display:'block',visibility:'visible'})
	$('ajaxview').fade('hide');
	$('pageview').fade('hide');
	$('pageview').setStyles({display:'none',visibility:'hidden'});
	
	$$('#ajaxview div.ajaxview_details dl')[0].setStyles({display:'none'})
	
	$('videocontainer').set('html','');
	
	$('pageview').set('html','');
	
	$('ajaxview').setStyle('top','205px');
	
	var thumbnails = '<div id="director_thumbs">';
	
	el.each(function(item,index){
		var dds = $(item).getElements('dd');
		var title = $(item).getParent().getElements('h4')[0].getElements('span')[0].get('html');//dds[0].get('html');
		var imgPath = window.imageThumbPrefix+''+dds[4].getElements('a')[0].get('href')+'';
		
		thumbnails += '<a href="#" onclick="javascript:window.ajaxViewDirectorShortcut(\''+oriel+'_'+title.split(' ').join('-')+'\');return false;"><img src="'+imgPath+'" alt="'+title+'" class="director_thumb" /></a>';
	});
	thumbnails += '</div>';
	
	var mailto = "paul@hellolove.tv";
	
	if(section == 'Promo-Directors'){
		mailto = "paul@hellolove.tv";
	}else if(section == 'Commercial-Directors'){
		mailto = "nicci@hellolove.tv";
	}
	
	thumbnails += '<div id="director_info"><p class="director_info_title">Director\'s Profile</p><p class="director_info_description">'+profile+'</p></div>';
	thumbnails += '<div id="director_request"><br /><p><a href="mailto:'+mailto+'?subject='+director+': Reel Request&body=Please enter your details to request the showreel:%0D%0A%0D%0AYour Name:%0D%0AYour Company:%0D%0AYour contact number:%0D%0A%0D%0A">Request A Reel</a></p></div>';
	
	
	$('videocontainer').set('html',thumbnails);
	
	$$('#ajaxview .ajaxview_show')[0].setStyles({width:'350px',height:'550px'})
	$('videocontainer').setStyles({width:'350px',height:'550px'})
	
	//window.revealSection.delay(50,$('ajaxview'));
	//window.revealSection.delay(100,$('ajaxview'));
	window.revealSection.delay(150,$('ajaxview'));
	
	//window.ajaxViewShow.delay(50);
}
window.resizeFlashPlayer = function(newwidth,newheight){
		
		$('HelloLovePlayer').setStyles({'width':newwidth+'px','height':newheight+'px'});
		$('HelloLovePlayer').setProperty('width',newwidth+'px');
		$('HelloLovePlayer').setProperty('height',newheight+'px');
		
		$$('#ajaxview .ajaxview_show')[0].setStyles({'width':newwidth+'px','height':newheight+'px'});
		$('videocontainer').setStyles({'width':newwidth+'px','height':newheight+'px'});
}
window.ajaxViewProject = function(el){
	clearInterval(slideshowInt);
	
	$('ajaxview').setStyles({display:'block',visibility:'visible'})
	$('ajaxview').fade('hide');
	$('pageview').set('html','');
	
	$('pageview').fade('hide');
	$('pageview').setStyles({display:'none',visibility:'hidden'});
	$('pageview').set('html','');
	
	var oriel = el;
	
	var el = $(el.substr(1)).getParent().getElements('dl')[0];
	var dds = $(el).getElements('dd');
	var dts = $(el).getElements('dt');
	
	var title = dds[0].get('html');
	var client = dds[1].get('html');
	var agency = dds[2].get('html');
	
	var slideshowFlag = $(el).getElements('dd.isslideshow');
	var isvideo = true;
	
	if(slideshowFlag.length > 0){
		isvideo = false;
	}
	
	
	//var videoPath = dds[3].getElements('a')[0].get('href');
	var videoPath = '../'+dds[3].getElements('a')[0].get('href').split('.mov').join(flashVideoSuffix)+'';
	var downloadVideoPath = '../'+dds[3].getElements('a')[0].get('href').split('.mov').join(downloadVideoSuffix)+'';
	
	var videoDimensionsHigh = dds[3].getElements('a')[0].get('rel').split('x')
	var ratio = (videoDimensionsHigh[0] / videoDimensionsHigh[1])
	var videoDimensions = new Array(480, (480 / ratio) )
	
	var imgPath = window.imagePosterPrefix+''+dds[4].getElements('a')[0].get('href')+'';
	var img = '<img src="'+imgPath+'" alt="'+title+'" />';
	
	//var player = dds[3].get('html');
	//$$('#ajaxview div.ajaxview_show')[0].set('html',player);
	//$$('#ajaxview div.ajaxview_show')[0].set('html',img);
	
	$$('#ajaxview div.ajaxview_details dl')[0].setStyles({display:'block'})
	
	var tdts = $$('#ajaxview div.ajaxview_details dt');
	
	tdts[0].set('html',dts[0].get('html'));
	tdts[1].set('html',dts[1].get('html'));
	tdts[2].set('html',dts[2].get('html'));
	
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_title')[0].set('html',title);
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_client')[0].set('html',client);
	$$('#ajaxview div.ajaxview_details dd.ajaxview_details_agency')[0].set('html',agency);
	
	$('videocontainer').set('html','');
	
	if(oriel.indexOf('New-Talent-Room') != -1){
		videoDimensions[1] = videoDimensions[1]+22;
	}
	
	if(isvideo == true){
			
		if(window.correctFlash){
			
			var flashObj = new Swiff('js/videoplayer.swf', {
				id: 'HelloLovePlayer',
				width: videoDimensions[0],
				height: videoDimensions[1],
				container: $('videocontainer'),
				params: {
					wmode: 'opaque',
					bgcolor: '#000000',
					scale: 'noscale',
					salign: 'TL',
					menu: false,
					allowFullScreen: true
				},
				vars: {
					autostart: false,
					stretching: 'fill',
					skin: 'js/SkinOverPlaySeekFullscreenWhite.swf',
					file: videoPath,
					image: imgPath
				},
				callBacks: {
					//load: myOnloadFunc
				}
			});
			$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			$('videocontainer').setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			
		}else if(window.quicktimeInstalled){
			/*
			QT_ReplaceWithPoster('Click to Play', window.siteRoot+imgPath, $('videocontainer'), window.siteRoot+dds[3].getElements('a')[0].get('href'), 
				''+videoDimensions[0]+'', ''+videoDimensions[1]+'', '',
				'target', 'myself',
				'controller', 'false', 
				'autoplay', 'true', 
				'scale', 'tofit', // SCALE is either TOFIT, ASPECT or a number
				'bgcolor', '000000', 
				'kioskmode', 'true',
				'align', 'left');
			*/
			/*
			QT_WriteOBJECT_XHTML('sample.mov', '320', '256', '',
			    'autoplay', 'true',
			    'emb#bgcolor', 'black',
			    'align', 'middle');
			*/
			QT_ReplaceElementContents_XHTML($('videocontainer'), window.siteRoot+imgPath,''+videoDimensions[0]+'', ''+videoDimensions[1]+'', '',
				    'href', window.siteRoot+dds[3].getElements('a')[0].get('href'),
					'target', 'myself',
					'controller', 'true', 
					'autoplay', 'true', 
					'scale', 'tofit', // SCALE is either TOFIT, ASPECT or a number
					'bgcolor', '000000', 
					'kioskmode', 'true',
					'align', 'left');
			
			$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			$('videocontainer').setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			
		}else{
			$('videocontainer').set('html','<a href="'+downloadVideoPath+'" title="Click To Download Video">'+img+'</a>');
		}
	}else{
		var imgtags = $(el).getElements('dd.isslideshow')[0].getElements('img');
		if(imgtags.length > 0){
			var slideshowMarkup = '';
			var slideshowControlsMarkup = '';
			imgtags.each(function(item,index){
				slideshowMarkup += '<div style="position:absolute;width:480px;height:360px;background-color:#000;"><img class="slideshowitem" src="'+item.get('src')+'" style="margin-left:auto;margin-right:auto;"/></div';
			})
			slideshowMarkup = '<div>'+slideshowControlsMarkup+'</div><div>'+slideshowMarkup+'</div>';
			
			$('videocontainer').set('html',slideshowMarkup);
			
			slideshowIndex = 0;
			slideshowItems = $$('div#videocontainer img.slideshowitem');
			slideshowTotal = slideshowItems.length;
			
			
			slideshowItems.each(function(item,index){
				item.getParent().fade('hide');
			})
			slideshowItems[slideshowIndex].getParent().fade('in');
			slideshowInt = setInterval(function(){

				slideshowIndex++
				
				if(slideshowIndex >= slideshowTotal){
					slideshowIndex = 0;
				}
				slideshowItems.each(function(item,index){
					item.getParent().fade('out');
				})
				//slideshowItems[slideshowIndex].setStyle('display','block');
				slideshowItems[slideshowIndex].getParent().fade('in');

			},slideshowTime);		
		}else{
			$('videocontainer').set('html','Sorry, no images in this slideshow.');		
		}
		
	}
	
	if(oriel.indexOf('New-Talent-Room') != -1){
		var ntr_header  = new Element('h1', {'html':'NEW TALENT ROOM'});
		
		ntr_header.inject($('videocontainer'),'top');
		$('ajaxview').setStyle('top','185px');
		$$('#ajaxview .ajaxview_details')[0].setStyle('margin-top','40px');
	}else{
		$('ajaxview').setStyle('top','205px');
		$$('#ajaxview .ajaxview_details')[0].setStyle('margin-top','20px');
	}
	
	
	//window.revealSection.delay(50,$('ajaxview'));
	//window.revealSection.delay(100,$('ajaxview'));
	window.revealSection.delay(150,$('ajaxview'));
	
	//window.ajaxViewShow.delay(50);
}

window.checkDeeplink = function(){
	
	//alert(window.location.hash)
	
	if(window.location.hash != ""){
		
		window.deeplink = true;
		
		var str = unescape(window.location.hash).split('/').join('_').split(' ').join('-');
		
		showHomePageItunesShortcut(str)
		
		/*
		var delay1 = setTimeout(function(str){
			
			var sections = str.split('_');
			var start = sections.shift();
			
			if(sections.length > 0){
				//check menu level 1
				var level1str = '#_'+sections[0];
				var level1 = window.findHrefMatch(level1str).getParent().getParent().getParent().getParent().getParent().getParent().getElements('ul')[0];
				if(level1.active == false){
					//window.trace('level1\n'+level1.get('html'))
					level1.active = true;
					level1.fade('in');
				}
			}
			
		},125,str);
		
		var delay2 = setTimeout(function(str){
			
			var sections = str.split('_');
			var start = sections.shift();
			
			if(sections.length > 1){
				//check menu level 2
				var level2str = '#_'+sections[0]+'_'+sections[1];
				var level2 = window.findHrefMatch(level2str).getParent().getParent().getParent().getElements('ul')[0];
				if(level2.active == false){
					//window.trace('level2\n'+level2.get('html'))
					level2.active = true;
					level2.fade('in');
				}
			}
			
		},250,str);
		
		var delay3 = setTimeout(function(str){
			
			var sections = str.split('_');
			var start = sections.shift();
			
			if(sections.length > 2){
				//check menu level 3
				var level3str = '#_'+sections[0]+'_'+sections[1]+'_'+sections[2];
				var level3 = window.findHrefMatch(level3str).getParent().getParent().getParent().getElements('ul')[0];
				if(level3.active == false){
					//window.trace('level2\n'+level2.get('html'))
					level3.active = true;
					level3.fade('in');
				}
			}
			
		},400,str);
		
		var delay4 = setTimeout(function(str){
											 
			var found = false;
			
			$$('#nav a').each(function(item,index){
									   
				if (found) return;
				
				//window.trace($(item).get('href')+'=>'+str)
				
				if($(item).get('href') == str){
					
					$(item).fireEvent('click');
					found = true
				}
			});
			
		},1000,str);
		*/
	}
}

window.showHomePageItunesShortcut = function(lnk){
	
	//alert(lnk)
	
	var lnk = lnk.split('_')
	
	$$("#nav ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
	$$("#nav ul li ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]+'_'+lnk[2]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
	$$("#nav ul li ul li ul li a").each(function(item,index){
		if($(item).get('href') == '#_'+lnk[1]+'_'+lnk[2]+'_'+lnk[3]){//#_Commercial-Directors
			$(item).fireEvent('click');
		}
	})
	
}

window.showHomePageItunesDeepLink = function(id){
	
	//alert(lnk)
	
	var deeplink = "#_";
	
	if(parseInt($$('#pageview #feature_'+id+' dd')[5].get('html')) == 1){
		deeplink += "Commercial-Directors_";
	}
	if(parseInt($$('#pageview #feature_'+id+' dd')[6].get('html')) == 1){
		deeplink += "Promo-Directors_";
	}
	deeplink += $$('#pageview #feature_'+id+' dd')[7].get('html').trim() + "-" + $$('#pageview #feature_'+id+' dd')[8].get('html').trim() + "_";
	deeplink += id+'-'+$$('#pageview #feature_'+id+' dd')[0].get('html').trim().split(' ').join('-');
	
	deeplink = deeplink.split('&amp;').join('&');
	
	window.showHomePageItunesShortcut(deeplink);
	
}
									 
window.showHomePageItunesMain = function(id){
		
		$$('#pageview #itunesfeature_show div').each(function(item,index){
			$(item).fade('hide');
		});
		
		$('pageview').getElement('#'+id+'_show').fade('in');
		$('pageview').getElement('#'+id+'_show').removeEvents();
		
		var deeplink = "#_";
		
		if(parseInt($$('#pageview #feature_'+id+' dd')[5].get('html')) == 1){
			deeplink += "Commercial-Directors_";
		}
		if(parseInt($$('#pageview #feature_'+id+' dd')[6].get('html')) == 1){
			deeplink += "Promo-Directors_";
		}
		
		deeplink += $$('#pageview #feature_'+id+' dd')[7].get('html').trim() + "-" + $$('#pageview #feature_'+id+' dd')[8].get('html').trim() + "_";
		deeplink += id+'-'+$$('#pageview #feature_'+id+' dd')[0].get('html').trim().split(' ').join('-');
		
		var featuretext = '<p></p><br/>';
		
		featuretext += '<p><a href="#" class="clicktoview" onclick="javascript:window.showHomePageItunesShortcut(\'' + deeplink + '\');return false;">Click to view</a></p>';
		
		featuretext += '<p style="text-transform:uppercase;font-size:13px;">'+$$('#pageview #feature_'+id+' dd')[0].get('html') + '</p>';
		featuretext += '<p>'+$$('#pageview #feature_'+id+' dd')[7].get('html') + ' '+$$('#pageview #feature_'+id+' dd')[8].get('html') + '</p>';
		featuretext += '<p class="greylighter" style="margin-top:10px;">'+$$('#pageview #feature_'+id+' dd')[10].get('html') + '</p>';
		
		$('itunesfeature_detail').fade('hide');
		$('itunesfeature_detail').set('html',featuretext);
		$('itunesfeature_detail').fade('show');
		$('pageview').getElement('#'+id+'_show').setStyle('cursor','pointer');
		$('pageview').getElement('#'+id+'_show').addEvent('click', function(){
			window.showHomePageItunesShortcut(deeplink);
			return false;
		});
		
		var showScrollButton = setTimeout(function(){
			$$('#pageview #itunesfeature_list_scroll').fade('in');
		},1000);
	
	
}

window.showHomePageItunesScroll = function(){
	
	clearTimeout(window.showHomePageItunesAutoScrollInt);
	
	$$('#pageview #itunesfeature_list_scroll').fade('hide');
	
	var total = $$('#pageview #itunesfeature_list div').length;
	var maxY = Math.round((total-1)*105);
	var selectY = Math.round(3*105);
	
	$$('#pageview #itunesfeature_list div').each(function(item,index){
									
		var currentY = parseInt($(item).getStyle('margin-top'));
		var newY = Math.round(currentY+105);
		
		if(currentY >= maxY){
			$(item).setStyle('margin-top','-105px');
			newY = 0;
		}
		if(currentY == selectY-105){
			if($$('#pageview #itunesfeature_show div').length > 1){
				window.showHomePageItunesMain($(item).get('rel'));
			}
		}
		
		$(item).set('tween', {duration: 500});
		$(item).tween('margin-top', newY+'px');
		
	});
	window.showHomePageItunesAutoScroll();
}

window.showHomePageItunesAutoScrollInt = 0;

window.showHomePageItunesAutoScroll = function(){
	clearTimeout(window.showHomePageItunesAutoScrollInt);
	window.showHomePageItunesAutoScrollInt = setTimeout(function(){
		window.showHomePageItunesScroll();
	},10000);
}
window.showHomePageItunes = function(){
	
	var counter = 0;
	$$('#pageview #itunesfeature_list div').each(function(item,index){
												
		$(item).removeEvents();
		$(item).setStyle('cursor','pointer');
		$(item).addEvent('click', function(){
			window.showHomePageItunesDeepLink($(this).get('rel'));
			return false;
		});
		
		counter++;
		
	});
	//if(counter > 4){
	//	window.showHomePageItunesMain($$('#pageview #itunesfeature_list div')[3].get('rel'));
	//}else{
		window.showHomePageItunesMain($$('#pageview #itunesfeature_list div')[counter-1].get('rel'));
	//}
	
}
window.showHomePage = function(){
	
	window.location.hash = '';
	window.ajaxViewHide();	   
	window.hideAllLevel1();
	window.hideAllLevel2();
	
	$('ajaxview').fade('hide');
	
	$('home').set('class','standard');
	
	window.ajaxViewPage('#_Home');
	
}
window.initSite = function(){
	//init site
	
	$('ajaxview').fade('hide');
	
	if(Browser.Plugins.Flash.version > flashVersionMajor){
		window.correctFlash = true;
	}else if(Browser.Plugins.Flash.version == flashVersionMajor && Browser.Plugins.Flash.build >= flashVersionMinor){
		window.correctFlash = true;
	}
	
	if(window.hide_jshidden){
		$$(".jshidden").each(function(item,index){
			$(item).setStyles({
				display: 'none',
				visiblity: 'hidden'
			});
		});
	}
	if(window.generatePlayers && window.correctFlash){
		
		$$(".videolink").each(function(item,index){
									   
			if($(item).getElements('a')[0].get('href')){
				var videoPath = '../'+$(item).getElements('a')[0].get('href').split('.mov').join(flashVideoSuffix)+'';
			}else{
				var videoPath = '';	
			}
			if($(item).getParent().getElements('dd.imagelink').getElements('a')[0].get('href')){
				var imgPath = ''+$(item).getParent().getElements('dd.imagelink').getElements('a')[0].get('href')+'';
			}else{
				var imgPath = '';	
			}
			
			if(videoPath.length > 0){
				var obj = new Swiff('js/player.swf', {
					id: 'videoPlayer',
					width: 480,
					height: 270,
					container: $(item),
					params: {
						wmode: 'opaque',
						bgcolor: '#000000'
					},
					vars: {
						autostart: false,
						stretching: 'fill',
						file: videoPath,
						image: imgPath
					},
					callBacks: {
						//load: myOnloadFunc
					}
				});
				/*			
				var so = new SWFObject('js/player.swf','daewoo','480','270','9.0.125');
				so.addParam('allowfullscreen','true');
				so.addParam('flashvars','file=../content/commercial/philipdupee/daewoo/daewoo.m4v&image=content/commercial/philipdupee/daewoo/daewoo.jpg&autostart=false&stretching=fill');
				*/
			}
		});
	}
	window.hideAllLevel1();
	window.hideAllLevel2();
	window.ajaxViewHide();
	
	$$("#nav ul li a").each(function(item,index){
		
			 
		$(item).removeEvents();
		
		$(item).setProperty('class','inactive');
		
		$(item).addEvent('click', function(){
										   
			window.ajaxViewHide();	   
			window.hideAllLevel1();
			window.hideAllLevel2();
			
			$('ajaxview').fade('hide');
			//$('ajaxview').set('html','');
			$('pageview').fade('hide');
			$('pageview').setStyles({display:'none',visibility:'hidden'});
			$('pageview').set('html','');
			
			var lnk = $(this).get('href')
			
			if($(lnk.substr(1))){
				switch(lnk.substr(1)){
					case '_Commercial-Directors':
						$(this).getParent().getElements('ul')[0].active = true;
						$(this).getParent().getElements('ul')[0].fade('in');
						break;
					case '_Promo-Directors':
						$(this).getParent().getElements('ul')[0].active = true;
						$(this).getParent().getElements('ul')[0].fade('in');
						break;
					case '_New-Talent-Room':
						$(this).getParent().getElements('ul')[0].active = true;
						$(this).getParent().getElements('ul')[0].fade('in');
						break;
					case '_New-Media':
						$(this).getParent().getElements('ul')[0].active = true;
						$(this).getParent().getElements('ul')[0].fade('in');
						break;
					default:
						window.ajaxViewPage(lnk);
						
				}
				switch(lnk.substr(1)){
					case '_New-Talent-Room':
						$('home').set('class','newtalent');
						$('footer').setStyle('top','858px');
						break;
					default:
						$('home').set('class','standard');
						$('footer').setStyle('top','728px');
						
				}
				
				
				$$('#SectionPanels div.sectionpanel').each(function(item,index){
					$(item).setStyle('display','block'); 
					$(item).fade('hide');
				});
				
				if($(lnk.substr(1)+'-Panel')){
					$(lnk.substr(1)+'-Panel').fade('in');
				}
			}else{
				//window.trace($(this));
				alert(window.comingsoon)	
			}
			
			window.updateWindowLocation(lnk);
			
			$$("#nav ul li a").each(function(item2,index2){
				$(item2).setProperty('class','inactive');
			});
			$(item).removeProperty('class');
			
			return false;
		});
		
	});
	
	$$("#nav ul li ul li a").each(function(item,index){
		
			 
		$(item).removeEvents();
		
		$(item).setProperty('class','inactive');
		
		$(item).addEvent('click', function(){
			
			window.ajaxViewHide();	   
			window.hideAllLevel2();
			
			var lnk = $(this).get('href');
			
			if($('_'+lnk.split('_')[1]+'-Panel')){
				$('_'+lnk.split('_')[1]+'-Panel').fade('out');
			}
			
			if(lnk.indexOf('New-Media') != -1){
				window.ajaxViewProject(lnk)
			}else{
				if($(lnk.substr(1))){
					$(this).getParent().getElements('ul')[0].active = true;
					$(this).getParent().getElements('ul')[0].fade('in');
					window.ajaxViewDirector(lnk);
				}else{
					alert(window.comingsoon)	
				}
			}
			
			window.updateWindowLocation(lnk);
			
			$$("#nav ul li ul li a").each(function(item2,index2){
				$(item2).setProperty('class','inactive');
			});
			$(item).removeProperty('class');
			
			return false;
		});
		
	});
	
	$$("#nav ul li ul li ul li a").each(function(item,index){
		$(item).removeEvents();
		
		$(item).setProperty('class','inactive');
		
		$(item).addEvent('click', function(){
										   
			var lnk = $(this).get('href')
				
			window.ajaxViewProject(lnk)
			
			window.updateWindowLocation(lnk);
			
			$$("#nav ul li ul li ul li a").each(function(item2,index2){
				$(item2).setProperty('class','inactive');
			});
			$(item).removeProperty('class');
			
			return false;
		});
	});
	
}
window.initSqueezeBox = function(){
	
	/**
     * Set default options, overrideable from later calls.
     */
    SqueezeBox.initialize({
        size: {x: 500, y: 400}
    });
 
    /**
     * Assign SqueezeBox to all links with rel="boxed" attribute, the class then reads the "href".
     */
    SqueezeBox.assign($$('a[rel=boxed]'));
 
    /**
     * Open some content manually
     */
    //SqueezeBox.open('manual.html'); // handler defaults to "ajax" for urls
 
    //SqueezeBox.open('http://digitarald.de', {handler: 'iframe'}); // we force the "iframe" handler here ...
 
    //SqueezeBox.open($('welcome'), {handler: 'adopt'}); // and here we force "adopt" handler	
}
window.addEvent('domready', function() {
	//The DOM is ready
	
	window.initSite();
	/*
	window.checkDeeplink();
	
	if(window.deeplink == false){
		window.showHomePage();
	}
	*/
	window.initSqueezeBox();
	
	
});

var page_history = new Array();
var page_history_int;

window.checkHash = function(){
	
	if(page_history.length < 1){
		page_history.push(window.location.hash);
	}else{
		
		// check current page
		if( window.location.hash != page_history[page_history.length-1] ){
			
			// check last page
			if( page_history.length > 2 && window.location.hash == page_history[page_history.length-2] ){
				
				// back button pushed, let's load the page
				page_history.pop();
				var lnk = page_history.pop();
				
				if(lnk == ""){
					window.showHomePage();
				}else{
					window.showHomePageItunesShortcut(lnk.split(' ').join('-').split('/').join('_'));	
				}
				
			}else if(window.location.hash == ''){
				// it's a new page visit, just push it to the history
				page_history.pop();
				window.showHomePage();
				
			}else{
				
				// it's a new page visit, just push it to the history
				page_history.push(window.location.hash);
				
			}
		}
	}
}
window.addEvent('load', function() {
								 
	if(window.deeplink == false){
		window.showHomePageItunesAutoScroll();
	}
	
	var delay = setTimeout(function(){
		$('all').setStyles({'display':'block'});
		if($('preloader')){
			$('preloader').setStyles({'display':'none','visibility':'hidden'});
		}
		//$$('.standard')[0].setStyles({'background-image':'none'});
		//$('home').setProperty('background-image':'none');
		$('all').fade('hide');
		$('all').fade('in');
		/*
		if(window.deeplink == false){
			//$('home').set('class','standard');
		}
		*/
		window.checkDeeplink();
		
		if(window.deeplink == false){
			window.showHomePage();
		}
		
	},50);
	
	page_history_int = setInterval(function(){
		window.checkHash();						   
	},125);
	
});

