Shadowbox.loadSkin('classic', 'src/skin');
Shadowbox.loadLanguage('en', 'src/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], 'src/player'); 

window.onload = function(){
	var options = {
	        resizeDuration:     '0.4', 
			animSequence:       'hw',
			flvPlayer:       'flvplayer.swf'
	    };

    Shadowbox.init(options);
	sethash();
	twitterTarget();
	showVideo(); 
	
	// open a welcome message
	    // Shadowbox.open({
	    // 	        player:     'flv',
	    // 	        title:      'Welcome',
	    // 	        content:    '_videos/valentino_beauty.flv',
	    // 	        // height:     350,
	    // 	        // width:      350
	    // 	    }); 
};

function twitterTarget(){
	twitterlinks = document.getElementById('twitter_update_list').getElementsByTagName("a");
	for(var i = 0; i < twitterlinks.length; i++){
		twitterlinks[i].setAttribute('target', '_blank');
	}
}


function sethash(){
	var hash_id = parent.location.hash;   
	// Shadowbox.open('_videos/valentino_beauty.flv');
	
	
	if(hash_id == '' || hash_id == '#home'){
		firstLoad('home_page', 'home_nav');
		Effect.Appear('footer', {duration: fadeSpeed}); 
	} else if(hash_id == '#about' ){
		firstLoad('about_page', 'about_nav');
	} else if(hash_id == '#theatre'){
		firstLoad('theatre_page', 'theatre_nav');
		
	} else if(hash_id == '#video'){
		firstLoad('video_page', 'video_nav');
		
	} else if(hash_id == '#gallery'){
		firstLoad('gallery_page', 'gallery_nav');
		
	} else if(hash_id == '#press'){
		firstLoad('press_page', 'press_nav');
		
	} else if(hash_id == '#contact'){
		firstLoad('contact_page', 'contact_nav');
	} else if(hash_id == '#pug_page'){
		firstLoad('pug_page', 'pug_nav');
	} else if(hash_id == '#dvd'){
			firstLoad('dvd_page', 'dvd_nav');
	} else {
		firstLoad('home_page', 'home_nav');
	}
}

var currentPage = 'home_page';
var currentNav = 'home_nav';
var currentAboutSubNav = 'about_synopsis';
var fadeSpeed = 0.3; 

function firstLoad(targetPage, activeLink){
	Effect.Appear(targetPage, {duration: fadeSpeed});
	
	$(activeLink).setStyle({
	  backgroundPosition: 'bottom left'
	})   
	
	new Effect.Morph('page_mask', 
			{style: 'height:'+$(targetPage).getHeight()+'px;', duration: fadeSpeed}); 
			
			currentNav = activeLink;
			currentPage = targetPage; 
}



function getPage(targetPage, activeLink){   	
	if(currentPage != targetPage){
		if(currentPage != null){
			Effect.Fade(currentPage, {duration: fadeSpeed});
		}
		
		                              
			Effect.Appear(targetPage, {duration: fadeSpeed, delay:fadeSpeed});
			
			$(currentNav).setStyle({
				  backgroundPosition: 'top left'
			});
	} 
	
	new Effect.Morph('page_mask', 
			{style: 'height:'+$(targetPage).getHeight()+'px;', duration: fadeSpeed});
	
	currentNav = activeLink;
	currentPage = targetPage;
	
	$(currentNav).setStyle({
	  backgroundPosition: 'bottom left'
	}); 
		
	if(currentPage != 'home_page'){
		Effect.Fade('footer', {duration: fadeSpeed});   
	} else {
		Effect.Appear('footer', {duration: fadeSpeed});   
	}
	return false;    
}

function trailer_toggle(action){
	if(action == 'img'){
		Effect.Fade('front_img', {duration: fadeSpeed});
		Effect.Appear('front_trailer', {duration: fadeSpeed, delay: fadeSpeed}); 
	} else 	if(action == 'tlr'){
		Effect.Fade('front_trailer', {duration: fadeSpeed});
		Effect.Appear('front_img', {duration: fadeSpeed, delay: fadeSpeed}); 
	}
}

function aboutSubnavToggle(target, current, subnavId){ 
    if(currentAboutSubNav != subnavId){
		
		Effect.Fade(current, {duration: fadeSpeed});   
	   	Effect.Appear(target, {duration:fadeSpeed, delay:fadeSpeed/2,afterFinish:function(){resizeContainer()}});
		
		
		$(subnavId).setStyle({
		  backgroundPosition: 'bottom left'
		});
		
		$(currentAboutSubNav).setStyle({
		  backgroundPosition: 'top left'
		});

		 new Effect.Morph(currentAboutSubNav, {style: 'color:#ddd', duration: fadeSpeed}); 
		 new Effect.Morph(subnavId, {style: 'color:#73BA00', duration: fadeSpeed}); 

		function resizeContainer(){
				new Effect.Morph('page_mask', 
				{style: 'height:'+document.getElementById('about_page').getHeight()+'px;', duration: fadeSpeed});
				}    
		  }
		currentAboutSubNav = subnavId; 
	}

function fbs_click(targeturl)
{   
	
	                 
	if(!targeturl){
		u=location.href;
	} else {
		u = targeturl;
	}
t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}

function shareMySpace()
{
    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent("Valentino")
    + '&c=' + encodeURIComponent("<p><strong>Valentino:</strong> The Last Emperor, produced and directed by Matt Tyrnauer, Special Correspondent for Vanity Fair magazine, is an intimate and engaging fly-on-the-wall exploration of the singular world of one of Italy's most famous men. The film documents the colorful and dramatic closing act of Valentino's celebrated career, tells the story of his extraordinary life, and explores the larger themes affecting the fashion business today. At the heart of the film is the unique relationship between Valentino and his business partner and companion of 50 years, Giancarlo Giammetti.</p>") + '&u=' + encodeURIComponent("http://www.valentinomovie.com") + '&l=3';
    window.open(targetUrl);
}

share_toggle = false;



function shareCaption(action, text){
	// alert('hello');
	if(action == 'focus'){
		document.getElementById('share_caption').innerHTML = text;
		$('share_caption').setAttribute('style', 'color:#fff;');
} else if (action == 'blur'){
		document.getElementById('share_caption').innerHTML = 'SHARE';
		$('share_caption').setAttribute('style', 'color:#e11a22');
	}
}


function setForm(target, button, action){
	targetBox = document.getElementById(target);
	if(action == 'blur'){
		if(targetBox.value == ''){
			Effect.Fade(button+'_submit', {duration: fadeSpeed});
			
			$(targetBox).setStyle({
			  color: '#666666'
			});
			
			targetBox.value = targetBox.defaultValue;
		}
	} else if(action == 'focus'){
		Effect.Appear(button+'_submit', {duration: fadeSpeed});
		
		$(targetBox).setStyle({
		  color: '#ffffff'
		});
		targetBox.value = '';
		$('submit_button').setAttribute('href', 'newsletter.html?'+targetBox.value );
		//$('submit_button').setAttribute('rel', 'shadowbox;width=370px;height=150px;options={animate: false}');
		//rel="shadowbox;width=370px;height=150px;options={animate: false}" 
	}
}
