/* © Blueberry Creative Consultants and John Conway, 2007 */

/* Initialisation */

window.onload= function(){
	initNavbarSections();
	scrollListener();
	initChocolateBox();
	initMap();
	initMovieLink();
	initBubbles();
	initBubblesTestimonials();
	//footerLinks();
	}

//..............................................................................


/* Navbar Functions */

function hover(id){
	if(document.body.id == id){highlighted(document.body.id);return false;}
	else{
		var sectionId = 'navbar_'+id;
		var sectionText= sectionId+'_text';
		document.getElementById(sectionId).onload = function(){document.getElementById(sectionId).style.height='100px';}
		document.getElementById(sectionId).onmouseover = 
			function(){
				$(sectionId).effect('height', 	{duration: 200, transition: Fx.Transitions.linear}).start(80, 85);
				$(sectionId).effect('opacity', 	{duration: 200, transition: Fx.Transitions.linear}).start(.6, 1);
				$(sectionText).effect('opacity', 	{duration: 200, transition: Fx.Transitions.linear}).start(.6, 1);
				}
		document.getElementById(sectionId).onmouseout = 
			function(){
				$(sectionId).effect('height', 	{duration: 300, transition: Fx.Transitions.linear}).start(85, 80);
				$(sectionId).effect('opacity', 	{duration: 300, transition: Fx.Transitions.linear}).start(1, .6);
				$(sectionText).effect('opacity', 	{duration: 300, transition: Fx.Transitions.linear}).start(1, .6);
				}
		}
	}

function highlighted(id){
	var sectionId = 'navbar_'+id;
	var sectionText= sectionId+'_text';
	document.getElementById(sectionText).style.background="#974C88";
	$(sectionId).effect('opacity', {duration: 400, transition: Fx.Transitions.linear}).start(.6, 1);
	}

function initNavbarSections(){
	hover('home');
	hover('team');
	hover('permanent');
	hover('services');
	hover('talent');
	hover('gallery');
	hover('testimonials');
	hover('features');
	}
	

//..............................................................................

/* Ajax */

function shortlist(ID){
	var input=('shortlist_add.php?id='+ID+'&ajax=on');
	new Ajax (input, {update: $('shortlist_menu')}).request(); 
	return false;
	}
function shortlistRmv(ID){
	var input=('shortlist_remove.php?id='+ID+'&ajax=on');
	new Ajax (input, {update: $('shortlist_menu')}).request(); 
	return false;
	}
	

//..............................................................................

/* Chocolate box functions */

function initChocolateBox(){
	if(document.getElementById('talent_navbar')){
		hoverChocolateBox();
		}
	else {return false;}
	}

function hoverChocolateBox(type){
	var oneem = document.getElementById('oneem').offsetHeight;
	var innerSkill	= null; var outerSkill = null; var innerGenre = null; 
	var outerGenre = null; var innerKit = null; var outerKit = null;	
	
	if(document.getElementById('talent_refine_list_skill')){
		var innerSkill 	= document.getElementById('talent_refine_list_skill').offsetHeight;
		var outerSkill 	= 'talent_refine_skill';
		document.getElementById(outerSkill).onmouseover=function(){
			$(outerSkill).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(innerSkill);
			if(document.getElementById('talent_refine_list_genre')){$(outerGenre).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			if(document.getElementById('talent_refine_list_kit')){$(outerKit).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			}
		} 	
	if(document.getElementById('talent_refine_list_genre')){
		var innerGenre 	= document.getElementById('talent_refine_list_genre').offsetHeight;
		var outerGenre 	= 'talent_refine_genre';	
		document.getElementById(outerGenre).onmouseover=function(){
			$(outerGenre).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(innerGenre);
			if(document.getElementById('talent_refine_list_skill')){$(outerSkill).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			if(document.getElementById('talent_refine_list_kit')){$(outerKit).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			}
		}
	if(document.getElementById('talent_refine_list_kit')){
		var innerKit 	= document.getElementById('talent_refine_list_kit').offsetHeight;
		var outerKit 	= 'talent_refine_kit';	
		document.getElementById(outerKit).onmouseover=function(){
			$(outerKit).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(innerKit);
			if(document.getElementById('talent_refine_list_skill')){$(outerSkill).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			if(document.getElementById('talent_refine_list_genre')){$(outerGenre).effect('height', {duration: 700, transition: Fx.Transitions.linear}).start(oneem);}
			}
		}
	}


//..............................................................................

/* Scrolling Shortlist Menu */

function getScrollY() {
		var scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			} 
		else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			}
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			}
		return scrOfY;
		}

function findPos(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	return curtop;
}


function floatShortlistMenu(){		
	var oldScroll = setTimeout('getScrollY()',100);
	var newScroll = setTimeout('getScrollY()',300);
	if(oldScroll == newScroll){
		return false;
		}
	else{
		var scroll = getScrollY();
		if(document.getElementById('shortlist_offset')){
			var navbarHeight = document.getElementById('shortlist_offset').offsetHeight;
			}
		else{
			var navbarHeight = '0';
			}
		
		startFloatNum=(navbarHeight + 220);
		
		if(scroll > startFloatNum){
			var stop = scroll - startFloatNum +40; // 40 added by jamie to keep shortlist header on screen
			$('shortlist_menu').effect('top', {duration: 1000}).start(stop),$('shortlist_menu');
			}
		else{
			var stop = 0; 
			var start = findPos('shortlist_menu');
			$('shortlist_menu').effect('top', {duration: 1000}).start(stop),$('shortlist_menu');
			}
		}
	}
	
	
function scrollListener(){
	if(document.getElementById('shortlist_menu')){
		setInterval('floatShortlistMenu()',1500);
		}
	else{
		return false;
		}
	}
	
//..............................................................................


/* Profiles functions */

function expand_disabled(id){
	var oldProfileHeight=('profile_contracted_'+id);
	var oldProfile=('profile_contracted_'+id);
	var oldProfileCont=('profile_contracted_cont_'+id);
	var newProfile=('profile_expanded_'+id);
	var newProfileCont=('profile_expanded_cont_'+id);
	
	var expandLink=('profile_expandlink_'+id);
	document.getElementById(expandLink).style.display='none';
	var contractLink=('profile_contractlink_'+id);
	document.getElementById(contractLink).style.display='inline';
	
	var startH = document.getElementById(oldProfile).offsetHeight;
	var stopH = document.getElementById(newProfile).offsetHeight + 30; // +30 added by jamie because things tend to get cut off.
	
	$(oldProfileCont).effect('height', {duration: 500, transition: Fx.Transitions.linear}).start(0);
	$(newProfileCont).effect('height', {duration: 1500, transition: Fx.Transitions.linear}).start(stopH);
	}

function contract_disabled(id){
	var oldProfileHeight=('profile_contracted_'+id);
	var oldProfile=('profile_contracted_'+id);
	var oldProfileCont=('profile_contracted_cont_'+id);
	var newProfile=('profile_expanded_'+id);
	var newProfileCont=('profile_expanded_cont_'+id);
	
	var expandLink=('profile_expandlink_'+id);
	document.getElementById(expandLink).style.display='inline';
	var contractLink=('profile_contractlink_'+id);
	document.getElementById(contractLink).style.display='none';
	
	var startH = document.getElementById(oldProfile).offsetHeight;
	var stopH = document.getElementById(newProfile).offsetHeight;
	
	$(newProfileCont).effect('height', {duration: 1000, transition: Fx.Transitions.linear}).start(0);
	$(oldProfileCont).effect('height', {duration: 1000, transition: Fx.Transitions.linear}).start(startH);
	}

/* ------- new expand / contract functions ------ */
// need to fix problem which occurs if you try to contract while it is still expanding
// poss store original height permanently as a prameter inside the object - use MooTools' new Element Storage system?

	function expand(item,expandButton,contractButton) {	
		var container = $(item);
		var small = $$('#' + item + ' .smallversion')[0];
		var big = $$('#' + item + ' .bigversion')[0];
		var containerHeight = parseInt(container.getStyle('height'));
		var expandBtn = $(expandButton);
		var contractBtn = $(contractButton);
		
		//var smallHeight = small[0].getStyle('height'); // 160px
		//var smallHeight = small[0].offsetHeight; // 160
		//var smallHeight = small[0].style.pixelHeight; // undefined
		//var smallHeight = small[0].pixelHeight; // undefined
		
		var smallHeight = parseInt(small.getStyle('height')); 
		//console.log(containerHeight);

		container.setStyle('height',containerHeight).setStyle('overflow','hidden');
		big.setStyle('display','block');
		small.setStyle('display','none');
		
		var bigHeight = parseInt(big.getStyle('height')); // can only be found out once big is set to visible
		
		//alert('bigHeight:'+bigHeight+' smallHeight:'+smallHeight);
		if(window.ie) {
			//document.getElementById(newProfile).offsetHeight;
			//alert ('offsetHeight:'+small.offsetHeight);
		}
		
		
		var margin = containerHeight - smallHeight; // recreate the natural margin
		container.effect('height', {duration: 500}).start(bigHeight+margin);
		
		if(expandBtn && contractBtn) {
			expandBtn.setStyle('display','none');
			contractBtn.setStyle('display','inline');
		}
		
	}
	
	function expand_mootools(item,expandButton,contractButton) {
		/* experimental. must hide each big version with fx.slide::hide(), and store the fx instance inside 1.2's element storage hash */	
		var container = $(item);
		var small = $$('#' + item + ' .smallversion')[0];
		var big = $$('#' + item + ' .bigversion')[0];
		var containerHeight = parseInt(container.getStyle('height'));
		var expandBtn = $(expandButton);
		var contractBtn = $(contractButton);

		var fx = big.retrieve('sliderFx'); 
		fx.slideIn();
		


		if(expandBtn && contractBtn) {
			expandBtn.setStyle('display','none');
			contractBtn.setStyle('display','inline');
		}
		
	}
	

	
	function contract(item,expandButton,contractButton) {	
		var container = $(item);
		var small = $$('#' + item + ' .smallversion')[0];
		var big = $$('#' + item + ' .bigversion')[0];
		var containerHeight = parseInt(container.getStyle('height'));
		var expandBtn = $(expandButton);
		var contractBtn = $(contractButton);
		
	
		var bigHeight = parseInt(big.getStyle('height')); // can only be found out once big is set to visible


		container.setStyle('height',containerHeight).setStyle('overflow','hidden');
		
		small.setStyle('display','block');
		small.injectAfter(big); // small version should be after big version, if not already
		
		var smallHeight = parseInt(small.getStyle('height')); 
		

		var margin = containerHeight - bigHeight; // recreate the natural margin
		container.effect('height', {duration: 500,onComplete:function(){big.setStyle('display','none');}}).start(smallHeight+margin);
		
		if(expandBtn && contractBtn) {
			expandBtn.setStyle('display','inline');
			contractBtn.setStyle('display','none');
		}
	}
//..............................................................................


// Footer functions

/*function footerLinks(){
	document.getElementById('ealing_studios_link').onmouseover=function(){
		$('ealing_studios_logo').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,1);
		}
	document.getElementById('ealing_studios_link').onmouseout=function(){
		$('ealing_studios_logo').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(1,0);
		}
	document.getElementById('uk_screen_link').onmouseover=function(){
		$('uk_screen_logo').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,1);
		}
	document.getElementById('uk_screen_link').onmouseout=function(){
		$('uk_screen_logo').effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(1,0);
		}	
	}*/

function closeMap(oSize){
	document.getElementById('map_cameo').onclick=function(){
		$('map_cameo').effect('height', {duration: 1000, transition: Fx.Transitions.linear}).start(600, oSize);
		$('map_cameo').effect('width', {duration: 1000, transition: Fx.Transitions.linear}).start(600, oSize);
		$('map_cameo').effect('border-width', {duration: 1000, transition: Fx.Transitions.linear}).start(1, 0);
		initMap();
		var oldMap = function(){document.getElementById('map_cameo').style.background='url(_assets/map_cameo.gif) 50% 50% #ccc';}
		setTimeout(oldMap,1000);
		}
	}

function initMap(){
	if(document.getElementById('footer_map')){
		var oSize = document.getElementById('footer_map').offsetHeight;
		document.getElementById('map_cameo').onclick=function(){
			document.getElementById('map_cameo').style.background='url(_assets/map.gif)';
			$('map_cameo').effect('height', {duration: 1000, transition: Fx.Transitions.linear}).start(oSize, 600);
			$('map_cameo').effect('width', {duration: 1000, transition: Fx.Transitions.linear}).start(oSize, 600);
			$('map_cameo').effect('border-width', {duration: 1000, transition: Fx.Transitions.linear}).start(0,1);
			closeMap(oSize);
			}
		}
	}

	
//..............................................................................	


function initMovieLink(){
	if(document.getElementById('movie_link_icon')){
		hoverMovieLink('movie_link_icon');
		}
	}
function hoverMovieLink(id){
	document.getElementById(id).onmouseover=function(){
		$(id).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0.2,0.5);
		}
	document.getElementById(id).onmouseout=function(){
		$(id).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0.5,0.2);
		}
	}

function showLightbox(id,mid){
	var lightbox = 'lightbox_'+id;
	var lightbox_contents = 'lightbox_contents_'+id;
	document.getElementById(lightbox).style.display='block';document.getElementById(lightbox_contents).style.display='block';
	var lightboxContentsTop = getScrollY()+380;
	document.getElementById(lightbox_contents).style.top=lightboxContentsTop;
	$(lightbox).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,0.9);
	$(lightbox_contents).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,1);
	var ajaxInput = 'feature_media_show.php?id='+mid;
	new Ajax (ajaxInput, {update: $(lightbox_contents)}).request(); 
	}
function hideLightbox(id){
	var lightbox = 'lightbox_'+id;
	var lightbox_contents = 'lightbox_contents_'+id;
	var none=function(){document.getElementById(lightbox).style.display='none';document.getElementById(lightbox_contents).style.display='none';}
	setTimeout(none, 1000);
	$(lightbox).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0.9,0);
	$(lightbox_contents).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(1,0);
	}
	
function showLightboxRelated(id,mid){
	var lightbox = 'lightbox_'+id;
	var lightbox_contents = 'lightbox_contents_'+id;
	var lightbox_close = 'close_lightbox_'+id;
	document.getElementById(lightbox).style.display='block';document.getElementById(lightbox_contents).style.display='block';
	$(lightbox).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,0.9);
	$(lightbox_contents).effect('opacity', {duration: 1000, transition: Fx.Transitions.linear}).start(0,1);
	$(lightbox_contents).effect('top', {duration: 1000, transition: Fx.Transitions.linear}).start(relatedTop());
	$(lightbox_close).effect('top', {duration: 1000, transition: Fx.Transitions.linear}).start(relatedTop());
	var ajaxInput = 'related_image_show.php?id='+mid;
	new Ajax (ajaxInput, {update: $(lightbox_contents)}).request(); 
	}

function relatedTop(){
	if(getScrollY() < 250){
		return 50;
		}
	else{
		return (getScrollY()-200);
		}
	}
function initBubbles(){
	document.getElementById('bubbles').innerHTML="<object id='bg_bubbles' data='_assets/bg_bubbles.swf' type='application/x-shockwave-flash' width='950' height='80' > <param name='movie' value='_assets/bg_bubbles.swf' /> <param name='quality' value='high' /> <param name='bgcolor' value='#ffffff' /> <param name='wmode' value='transparent' /> </object>";
	}
function initBubblesTestimonials(){	
	if(document.body.id == 'testimonials'){
		document.getElementById('bubbles_testimonials').innerHTML="<object id='bg_bubbles_testimonials' data='_assets/bg_bubbles_testimonials.swf' type='application/x-shockwave-flash' width='750' height='500' > <param name='movie' value='_assets/bg_bubbles_testimonials.swf' /> <param name='quality' value='high' /> <param name='bgcolor' value='#ffffff' /> <param name='wmode' value='transparent' /> </object>";
		}
	else{return false;}
	}