// 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/640x360/';
window.imageThumbPrefix = 'images/197x94/197:94/';

//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){
	//$('addthis_container').fade('hide');
	$$("#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','');
	$('ajaxview').setStyles({'margin-left':'270px','width':'560px'});
	
	$('videocontainer').set('html','');
	
	$('ajaxview').fade('hide');
	
	$('breadcrumbnav').empty();
	
	clearTimeout(window.showHomePageItunesAutoScrollInt);
	
	/*
	if(window.location.href.indexOf('Commercial') == -1 || window.location.href.indexOf('Promo') == -1){
		$('breadcrumbnav').empty();
	}
	*/
}
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);
	
	var pagecoordinates = $('pageview').getCoordinates();
	var ypos = pagecoordinates.bottom;
	
	if(el == '#_Home'){
		window.showHomePageItunes();	
	}
	if(el == '#_Contact'){
		ypos = 700;
	}
	
	$('pageview').fade('in');
	
	//$('footer').setStyles({'top':(ypos+50)+'px'});
	window.positionFooter(ypos+50);
}
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.checkValidLink = function(el){
	return $(el);
}
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 sectionel = null;
	var directorel = null;
	
	//#_Commercial-Directors_Jenny--Ash
	var hrefmatch = '#_'+section+'_'+director.split(' ').join('-');
	var sectionhrefmatch = '#_'+section;
	
	$$('#nav ul li a').each(function(item,index){
		if($(item).get('href') == sectionhrefmatch){
			sectionel = $(item);
		}
	})
	$$('#nav ul li ul li a').each(function(item,index){
		if($(item).get('href') == hrefmatch){
			directorel = $(item);
		}
	})
	
	//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');
		var title_display = title.substr(title.indexOf('-')+1).split('-').join(' ');
		var imgPath = window.imageThumbPrefix+''+dds[4].getElements('a')[0].get('href')+'';
		
		thumbnails += '<div style="display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width:197px; height:94px; margin-bottom:10px; margin-right:10px; background-image:url(\''+imgPath+'\');">';
		thumbnails += '<a href="#" class="thumbnailViewLink" onclick="javascript:window.ajaxViewDirectorShortcut(\''+oriel+'_'+title.split(' ').join('-')+'\');return false;">'+title_display+'</a>';
		thumbnails += '</div>';
	});
	thumbnails += '</div>';
	
	var mailto = "paul@hellolove.tv";
	
	if(section == 'Promo-Directors'){
		mailto = "paul@hellolove.tv";
	}else if(section == 'Commercial-Directors'){
		mailto = "luce@hellolove.tv";
	}
	if(section != 'Content'){
		thumbnails += '<div id="director_info"><p class="director_info_title">Profile</p><p class="director_info_description">'+profile+'</p></div>';
	}
		
	if(section == 'Promo-Directors'){
		var lnk = '_Commercial-Directors_'+director.split(' ').join('-');
		if(window.checkValidLink(lnk)){
			thumbnails += '<div id="director_request"><br /><p><a href="#'+lnk+'" onclick="javascript:window.showHomePageItunesShortcut(this.href);return false;">Click here for Commercials</a></p></div>';
		}
		
	}else if(section == 'Commercial-Directors'){
		var lnk = '_Promo-Directors_'+director.split(' ').join('-');
		if(window.checkValidLink(lnk)){
			thumbnails += '<div id="director_request"><br /><p><a href="#'+lnk+'" onclick="javascript:window.showHomePageItunesShortcut(this.href);return false;">Click here for Promos</a></p></div>';
		}
	}
	if(section != 'Content'){
		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>';
	}
	thumbnails += '<div class="addthis_toolbox addthis_default_style "  style="margin-left:-1px;margin-top:15px;">';
	thumbnails += '<a class="addthis_button_facebook"></a>';
	thumbnails += '<a class="addthis_button_twitter"></a>';
	thumbnails += '<a class="addthis_button_compact"></a>';
	thumbnails += '<a class="addthis_counter addthis_bubble_style"></a>';
	thumbnails += '</div>';
	
	$('videocontainer').set('html',thumbnails);
	
	$$('#ajaxview .ajaxview_show')[0].setStyles({width:'640px',height:'550px'})
	$('videocontainer').setStyles({width:'640px',height:'550px'})
	$('director_thumbs').setStyles({width:'640px'})
	
	if(section != 'Content'){
		$$('#director_info p.director_info_description')[0].setStyles({width:'570px'})
	}
	
	if(section == 'Content' || section == 'Promo-Directors' || section == 'Commercial-Directors' || section == 'New-Talent' || section == 'Long-Form' || section == 'Fashion'){
		
		$('ajaxview').setStyles({'margin-left':'0px','width':'820px'});
		$$('#ajaxview .ajaxview_show')[0].setStyles({width:'820px',height:'auto'})
		$('videocontainer').setStyles({width:'820px',height:'auto'})
		$('director_thumbs').setStyles({width:'840px'})
		if(section != 'Content'){
			$$('#director_info p.director_info_description')[0].setStyles({width:'815px'})
		}
		
		var section_crumb = section.split('-').join(' ');
		$$('div#nav ul li.mainnav a').each(function(item,index){
			//console.log(item.get('href').substr(2)+''+section);
			if(item.get('href').substr(2) == section){
				section_crumb = item.get('title');
			}
		})
		
		var section_breadbrumb = new Element('a', {'href':section,'class':'inactive','html':section_crumb});
		section_breadbrumb.mother = sectionel;
		section_breadbrumb.addEvent('click', function(event){
			$(this).mother.fireEvent('click');
			event.preventDefault();
		});
		section_breadbrumb.inject($('breadcrumbnav'));
		
		var director_breadbrumb = new Element('a', {'href':'#','html':' / '+director});
		director_breadbrumb.mother = directorel;
		director_breadbrumb.addEvent('click', function(event){
			$(this).mother.fireEvent('click');
			event.preventDefault();
		});
		director_breadbrumb.inject($('breadcrumbnav'));
		
	}
	
	//window.revealSection.delay(50,$('ajaxview'));
	//window.revealSection.delay(100,$('ajaxview'));
	window.revealSection.delay(150,$('ajaxview'));
	
	var pagecoordinates = $('ajaxview').getCoordinates();
	window.positionFooter(pagecoordinates.bottom);
	
	//window.ajaxViewShow.delay(50);
	var delayAddThis = setTimeout(function(){
		addthis.toolbox('.addthis_toolbox', {}, {url: window.location.href});//, title: section.split('-').join(' ')+' / '+director});
	},1000);
	//addthis.init();
	
}
window.resizeFlashPlayer = function(newwidth,newheight){
	
		if(newwidth > 820){
			var ratio = (newwidth / newheight);
			newwidth = 820;
			newheight = Math.round(820 / ratio);
		}
		
		$('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'});
		
		var pagecoordinates = $('ajaxview').getCoordinates();
		window.positionFooter(pagecoordinates.bottom);
		
}
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');
	
	if(oriel.indexOf('#_Content') != -1){
		title = 'Director: '+dds[5].get('html')+'<br/>'+title;
	}
	
	var client = dds[1].get('html');
	var agency = dds[2].get('html');
	
	agency += '<div class="addthis_toolbox addthis_default_style "  style="margin-left:-1px;margin-top:15px;">';
	agency += '<a class="addthis_button_facebook"></a>';
	agency += '<a class="addthis_button_twitter"></a>';
	agency += '<a class="addthis_button_compact"></a>';
	agency += '<a class="addthis_counter addthis_bubble_style"></a>';
	agency += '</div>';
	
	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(820, (820 / ratio) )
	
	if(oriel.indexOf('ContentOLD') != -1){
		videoDimensions = new Array(550, (550 / 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','');
	
	var delayAddThis = setTimeout(function(){
		addthis.toolbox('.addthis_toolbox', {}, {url: window.location.href});//, title: section.split('-').join(' ')+' / '+director});
	},1000);
	
	if(oriel.indexOf('New-Talent-Room') != -1){
		videoDimensions[1] = videoDimensions[1]+22;
	}
	
	if(isvideo == true){
		/*
		if(supports_h264_baseline_video()){
			
			$('videocontainer').empty();
			
			var VideoPlayer  = new Element('video', {'id': 'HelloLovePlayer', 'width': videoDimensions[0], 'controls': '', 'webkitAllowFullScreen': '', 'allowFullScreen': '', 'x-webkit-airplay': 'allow', 'poster':imgPath, 'src': videoPath, 'style': 'image-fit:fill;object-fit:fill;background-color:#000000;'});
			
			$('videocontainer').adopt(VideoPlayer);
			
			//$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:$('videocontainer').getSize().y+'px'})
			//$('videocontainer').setStyles({'background-color':'black'})
			
		}else
		*/
		if(BrowserDetect.OS == 'iPad' || BrowserDetect.OS == 'iPhone/iPod'){
			var VideoPlayer  = new Element('video', {'id': 'HelloLovePlayer', 'width': videoDimensions[0], 'height': videoDimensions[1], 'controls': '', 'x-webkit-airplay': 'allow', 'poster':imgPath, 'src': dds[3].getElements('a')[0].get('href')});
			$('videocontainer').adopt(VideoPlayer);
			$('videocontainer').setStyle('display','none');
			
			var posterImage = new Element('img', {
			    src: imgPath,
			    events: {
			        load: function(){
						var ratio = (this.width/this.height);
						var correctHeight = Math.round(parseInt($('HelloLovePlayer').get('width'))/ratio);

						$('HelloLovePlayer').set('height',correctHeight);
						
						$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:correctHeight+'px'})
						$('videocontainer').setStyles({width:videoDimensions[0]+'px',height:correctHeight+'px'})

						var pagecoordinates = $('ajaxview').getCoordinates();
						window.positionFooter(pagecoordinates.bottom);

						$('videocontainer').setStyle('display','block');
			        }
			    }
			});
			
			
			/*
			QT_ReplaceElementContents_XHTML($('videocontainer'), dds[4].getElements('a')[0].get('href'),''+videoDimensions[0]+'', ''+videoDimensions[1]+'', '',
				    'href', window.siteRoot+dds[3].getElements('a')[0].get('href'),
					'obj#id', 'HelloLovePlayer',
					'emb#id', 'HelloLovePlayerEmbed',
					'id', 'HelloLovePlayer',
					'target', 'myself',
					'controller', 'true', 
					'autoplay', 'true', 
					//'enablejavascript', 'true',
					//'postdomevents', 'true',
					'scale', 'ASPECT', // SCALE is either TOFIT, ASPECT or a number
					'bgcolor', '000000', 
					'kioskmode', 'true',
					'align', 'left',
					'airplay', 'allow');

			var posterImage = new Element('img', {
			    src: imgPath,
			    events: {
			        load: function(){
						var ratio = (this.width/this.height);
						var correctHeight = Math.round(parseInt($('HelloLovePlayer').get('width'))/ratio);

						$('HelloLovePlayer').set('height',correctHeight);
						$('HelloLovePlayerEmbed').set('height',correctHeight);
						
						$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:correctHeight+'px'})
						$('videocontainer').setStyles({width:videoDimensions[0]+'px',height:correctHeight+'px'})

						var pagecoordinates = $('ajaxview').getCoordinates();
						window.positionFooter(pagecoordinates.bottom);

						$('videocontainer').setStyle('display','block');
			        }
			    }
			});
			$('videocontainer').setStyle('display','none');
			*/
			$$('#ajaxview .ajaxview_show')[0].setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			$('videocontainer').setStyles({width:videoDimensions[0]+'px',height:videoDimensions[1]+'px'})
			
			/*
			$('HelloLovePlayer').addEventListener('qt_play', function(){
				//alert('play')
			}, false);

			$('HelloLovePlayer').addEventListener('qt_loadedfirstframe', function(){
				//alert('qt_loadedfirstframe')
			}, false);

			$('HelloLovePlayer').addEventListener('qt_loadedmetadata', function(){
				//alert('qt_loadedmetadata')
			}, false);

			$('HelloLovePlayer').addEventListener('qt_begin', function(){
				//alert('qt_begin')
			}, false);
			*/
		} else 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){
		}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:820px;height:461px;background-color:#000;"><img class="slideshowitem" src="'+item.get('src')+'" style="margin-left:auto;margin-right:auto;"/></div>';
			})
			slideshowMarkup = '<div style="width:820px;height:461px;background-color:#000;"><div>'+slideshowControlsMarkup+'</div><div>'+slideshowMarkup+'</div></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');
	}
	
	if($('breadcrumbnav').getElements('a').length > 0){
		$('breadcrumbnav').getElements('a')[$('breadcrumbnav').getElements('a').length-1].set('class','inactive')
	}
	//window.revealSection.delay(50,$('ajaxview'));
	//window.revealSection.delay(100,$('ajaxview'));
	window.revealSection.delay(150,$('ajaxview'));
	
	var pagecoordinates = $('ajaxview').getCoordinates();
	window.positionFooter(pagecoordinates.bottom);
	
	var delay = setTimeout(function(){
		var pagecoordinates = $('ajaxview').getCoordinates();
		window.positionFooter(pagecoordinates.bottom);
	},1000);
	
	//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)
		
	}
}

window.showHomePageItunesShortcut = function(lnk){
	
	/*
	if(console){
		console.log(lnk);
	}
	*/
	var lnk = lnk.split('_')
	/*
	if(console){
		console.log(lnk);
	}
	*/
	$$("#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){
	
	var deeplink = "#";
	
	var lnkId = "";
	
	$$('dl dd dl dd dl dd h4').each(function(item,index){
		if(item.get('id').indexOf(id) != -1){
			//console.log("FOUND:"+item.get('id'));
			lnkId = item.get('id');
		}
	})
	
	$$('dl dd dl dd h4').each(function(item,index){
			if(item.get('id').indexOf(id) != -1){
				//console.log("FOUND:"+item.get('id'));
				lnkId = item.get('id');
			}
		})
	
	deeplink += lnkId;
	
	
	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 = "#";

		var lnkId = "";
		
		$$('dl dd dl dd dl dd h4').each(function(item,index){
			if(item.get('id').indexOf(id) != -1){
				//console.log("FOUND:"+item.get('id'));
				lnkId = item.get('id');
			}
		})
		
		$$('dl dd dl dd h4').each(function(item,index){
			if(item.get('id').indexOf(id) != -1){
				//console.log("FOUND:"+item.get('id'));
				lnkId = item.get('id');
			}
		})

		deeplink += lnkId;
		
		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><a href="#" class="clicktoview" onclick="javascript:window.showHomePageItunesDeepLink(\'' + id + '\');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);
		
		var itunesfeature_share_position = $('itunesfeature_share').getPosition();
		
		$('itunesfeature_detail').fade('show');
		$('pageview').getElement('#'+id+'_show').setStyle('cursor','pointer');
		$('pageview').getElement('#'+id+'_show').addEvent('click', function(){
			window.showHomePageItunesShortcut(deeplink);
			//window.showHomePageItunesDeepLink(deeplink);
			return false;
		});
		
}

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');
		
	});
	
	var showScrollButton = setTimeout(function(){
		$$('#pageview #itunesfeature_list_scroll').fade('in');
	},1000);
	
	var pagecoordinates = $('ajaxview').getCoordinates();
	window.positionFooter(pagecoordinates.bottom);
	
	window.showHomePageItunesAutoScroll();
}

window.showHomePageItunesAutoScrollInt = 0;

window.showHomePageItunesAutoScroll = function(){
	clearTimeout(window.showHomePageItunesAutoScrollInt);
	window.showHomePageItunesAutoScrollInt = setTimeout(function(){
		window.showHomePageItunesScroll();
	},6000);
}
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'));
		
		if($$('#pageview #itunesfeature_list div')[counter-1].get('title') == 'featureshow'){
			$$('#pageview #itunesfeature_list div')[counter-1].dispose();
		}
		
	//}
	window.showHomePageItunesAutoScroll();
	
}
window.showHomePage = function(){
	
	window.location.hash = '';
	window.ajaxViewHide();	   
	window.hideAllLevel1();
	window.hideAllLevel2();
	
	$('ajaxview').fade('hide');
	
	$('home').set('class','standard');
	
	window.ajaxViewPage('#_Home');
	
	var pagecoordinates = $('ajaxview').getCoordinates();
	window.positionFooter(pagecoordinates.bottom);
	
}
window.thumbnailView = function(el){
	
	var section = el.get('href');
	
	$('pageview').setStyles({display:'block',visibility:'visible'});
	
	var thumbs = new Element('div', {'id':'thumbnailView'});//,'style':'width:850px;'
	
	el.getNext('ul').getElements('li.director').each(function(item,index){
		
		var director = $(item).getElements('a')[0].get('html');
		var link = $(item).getElements('a')[0].get('href');
		
		if(section == "#_Content"){
			var img = $(link.substr(1)).getNext().getNext().get('src');
			var thumb = new Element('div', {'id':'thumbnailView','style':'display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width:197px; height:94px; margin-bottom:10px; margin-right:10px; background-image:url(\''+img+'\');'});
			var thumblink = new Element('a', {'class':'thumbnailViewLinkIMG','href':link});
			var img_on = new Element('img', {'src':$(link.substr(1)).getNext().getNext().getNext().get('src')});
			
			img_on.inject(thumblink);
			
			thumblink.mother = $(item).getElements('a')[0];
			thumblink.addEvents({
				click:function(event){
					$(this).mother.fireEvent('click');
					event.preventDefault();
				},
				mouseover:function(event){
					$(this).getChildren('img')[0].fade('in');
				},
				mouseout:function(event){
					$(this).getChildren('img')[0].fade('out');
				}
			});
			
			thumblink.getChildren('img')[0].fade('hide');
			
		}else{
			//console.log($(item).getElements('li a').length)
			if($(item).getElements('li a').length > 0){
				var img = '/images/197x94/197:94/'+$( $(item).getElements('li a')[0].get('href').split('#')[1] ).getParent().getElements('dd.imagelink a').get('href');
			}else{
				var img = "";
			}
			
			//var img = '/images/197x94/197:94/'+$( $(item).getElements('li a')[0].get('href').split('#')[1] ).getParent().getElements('dd.imagelink a').get('href');
			var thumb = new Element('div', {'id':'thumbnailView','style':'display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; width:197px; height:94px; margin-bottom:10px; margin-right:10px; background-image:url(\''+img+'\');'});
			var thumblink = new Element('a', {'class':'thumbnailViewLink','href':link,'html':director});
			
			thumblink.mother = $(item).getElements('a')[0];
			thumblink.addEvent('click', function(event){
				$(this).mother.fireEvent('click');
				event.preventDefault();
			});
		}
		
		thumblink.inject(thumb);
		
		thumb.inject(thumbs);
		
	});
	
	$('pageview').empty();
	
	thumbs.inject($('pageview'));
	
	var section_crumb = section.substr(2).split('-').join(' ');
	
	$$('div#nav ul li.mainnav a').each(function(item,index){
		if(item.get('href') == section){
			section_crumb = item.get('title');
		}
	})
	
	var section_breadbrumb = new Element('a', {'href':section,'html':section_crumb});
	section_breadbrumb.mother = el;
	section_breadbrumb.addEvent('click', function(event){
		$(this).mother.fireEvent('click');
		event.preventDefault();
	});
	section_breadbrumb.inject($('breadcrumbnav'));
	
	$('pageview').fade('in');
	
	var pagecoordinates = $('pageview').getCoordinates();
	window.positionFooter(pagecoordinates.bottom);
}
window.positionFooter = function(ypos){
	//alert('positionFooter')
	var minimumypos = 700;
	
	$('footer').set('tween', {transition: Fx.Transitions.Cubic.easeOut,duration:'short'});
	if(ypos > minimumypos){
		//$('footer').setStyles({'top':(ypos+50)+'px'});
		$('footer').tween('top', (ypos+50));
	}else{
		//$('footer').setStyles({'top':minimumypos+'px'});
		$('footer').tween('top', minimumypos);
	}
}

function supports_video() {
  return !!document.createElement('video').canPlayType;
}

function supports_h264_baseline_video() {
  if (BrowserDetect.OS != 'iPad' && BrowserDetect.OS != 'iPhone/iPod' && BrowserDetect.browser != 'Safari') { return false; }
  if (!supports_video()) { return false; }
  var v = document.createElement("video");
  return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}
/*
var test = "";
var totest = Browser.Engine
for(var item in totest){
	test += item+';'+totest[item]+'\n'
}
alert(test);
*/
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: 640,
					height: 360,
					container: $(item),
					params: {
						wmode: 'opaque',
						bgcolor: '#000000'
					},
					vars: {
						autostart: false,
						stretching: 'fill',
						file: videoPath,
						image: imgPath
					},
					callBacks: {
						//load: myOnloadFunc
					}
				});
			}
		});
	}
	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');
						window.thumbnailView($(this));
						break;
					case '_Promo-Directors':
						//$(this).getParent().getElements('ul')[0].active = true;
						//$(this).getParent().getElements('ul')[0].fade('in');
						window.thumbnailView($(this));
						break;
					case '_New-Talent-Room':
						$(this).getParent().getElements('ul')[0].active = true;
						$(this).getParent().getElements('ul')[0].fade('in');
						break;
					case '_New-Talent':	
						window.thumbnailView($(this));
						break;
					case '_Content':
						//$(this).getParent().getElements('ul')[0].active = true;
						//$(this).getParent().getElements('ul')[0].fade('in');
						window.thumbnailView($(this));
						break;
					case '_Long-Form':	
						window.thumbnailView($(this));
						break;
					case '_Fashion':	
						window.thumbnailView($(this));
						break;
					default:
						window.ajaxViewPage(lnk);
						
				}
				
				$('home').set('class','standard');
				
				switch(lnk.substr(1)){
					case '_New-Talent-Room':
						$('home').set('class','newtalent');
						//$('footer').setStyle('top','500px');
						
						//var pagecoordinates = (this).getParent().getElements('ul')[0].getCoordinates();
						//$('footer').setStyles({'top':(pagecoordinates.bottom+50)+'px'});
						
						break;
					case '_New-Talent':
						//$('footer').setStyle('top','900px');
						//$('footer').setStyle('top','500px');
						//var pagecoordinates = (this).getParent().getElements('ul')[0].getCoordinates();
						//$('footer').setStyles({'top':(pagecoordinates.bottom+50)+'px'});
							break;
					case '_Commercial-Directors':
						//$('footer').setStyle('top','900px');
							break;
					case '_Content':
						//$('footer').setStyle('top','900px');
						//$('footer').setStyle('top','650px');
							break;
					case '_Long-Form':
						//$('footer').setStyle('top','900px');
						//$('footer').setStyle('top','500px');
							break;
					case '_Fashion':
						//$('footer').setStyle('top','900px');
						//$('footer').setStyle('top','500px');
							break;
					case '_Promo-Directors':
						//$('footer').setStyle('top','900px');
							break;
					case '_Contact':
						//$('footer').setStyle('top','750px');
							break;
					default:
						//$('footer').setStyle('top','900px');
						
				}
				
				//$('footer').setStyle('top','900px');
				
				
				$$('#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));
				if($(this).get('rel') == 'external'){
					window.open($(this).get('href'),'_blank');
				}else{
					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();
			/*
			if(lnk.indexOf('Commercial') == -1 || lnk.indexOf('Promo') == -1){
				$('breadcrumbnav').empty();
			}
			*/
			var lnk = $(this).get('href');
			
			if($('_'+lnk.split('_')[1]+'-Panel')){
				$('_'+lnk.split('_')[1]+'-Panel').fade('out');
			}
				
			if(lnk.indexOf('ContentOLD') != -1){
				window.ajaxViewProject(lnk)
			}else{
				if($(lnk.substr(1))){
					
					//if(lnk.indexOf('Commercial-Directors') != -1 || lnk.indexOf('Promo-Directors') != -1 ){
						//window.ajaxViewDirectorThumbs(lnk);
					//}else{
						//$(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.socialButtonsFooter = function(){
	/*
	$$('#footer a.facebook')[0].addEvent('click', function(){
									   
		var lnk = $(this).get('href')
		
	});
	*/
}
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);
	
});


