
document.domain = 'tros.nl'
var hashBool 	= false;
var shareType 	= '';
var shareTitle 	= '';
var shareDate	= '';
var sharePage	= '';
var tvpAnchorAllow = false;

function loadPlaylist(sHash){

 	if(hashBool)return false;
 	
 	
 	if(tvpAnchorAllow){
 		tempArr = document.URL.split("#");
 		document.location=tempArr[0]+'#top';	
 	}
 	tvpAnchorAllow = true;
 	

    $('#tvpcontainer').html('<iframe width="100%" height="100%" scrolling="no" frameborder="0" allowtransparency="true" id="trosvideoplayer-iframe"><p>U browser ondersteund geen iframes.</p></iframe>');
    url = 'http://player.tros.nl/p/'+sHash;
   	$('iframe#trosvideoplayer-iframe').attr('src', url);

    $('iframe#trosvideoplayer-iframe').load(function() 
    {
    	 //LOAD
    	$('iframe#trosvideoplayer-iframe').unbind('load');
	location.hash ='';

    });
    
    
   
    return false;
}


function goFullScreen(sUrl){
	$().colorbox({ href:sUrl, width:"855px", height:"650px", iframe:true});
}

function shareVid(hash,item,type,title,date){
		
		if(type != 'mail') sharePage = window.open("#","plain","width=1000,height=500");		
		shareTitle = title;
		shareDate = date;
		shareType = type;
	
		//CLEAR POTENTIAL HASH
		urlArr = document.URL.split("#");
		//MAKE TINY URL
		makeTinyUrl(urlArr[0]+'|'+hash+'/'+item);
		
}

function makeTinyUrl(url)
{

    $.get('/typo3conf/ext/trosvideoplayer/php/tinyurl.php?u='+escape(url), 
    	function(tinyurl)
    	{ 
    		socialTitle = encodeURIComponent('Bekijk deze video op TROS.NL: '+shareTitle);
    		tinyurl =  encodeURIComponent(tinyurl);

    		switch(shareType){
				case 'fb':
				  	sharePage.location.href = "http://www.facebook.com/share.php?u="+tinyurl+"&t="+socialTitle;
				break;
				case 'twitter':
					sharePage.location.href =  "http://twitter.com/home?status="+socialTitle+"+%23tros+"+tinyurl;
				break;
				case 'hyves':
					sharePage.location.href = "http://www.hyves.nl/profilemanage/add/tips/?name="+socialTitle+"&text=+"+tinyurl+"&rating=5&type=12";
				break;
				case 'mail':
					window.location.href = "mailto:?subject="+socialTitle+"&body=Bekijk%20de%20video%20hier:%20"+tinyurl;
				break;
			}
    	}
    )
}

$(document).ready(function() {
  
  if(location.hash != '') {
  	hashBool = true;

  	//GET HASH
  	tempHash = location.hash;
  	tempHash = tempHash.slice(1);
  	vidArr = tempHash.split("/");
	
	

  	
		$('#tvpcontainer').html('<iframe width="100%" height="100%" scrolling="no" frameborder="0" allowtransparency="true" id="trosvideoplayer-iframe"><p>U browser ondersteund geen iframes.</p></iframe>');
		url = 'http://player.tros.nl/p/'+vidArr[0]+'/std/1/402/'+vidArr[1]+'/0/0/blue/';
		$('iframe#trosvideoplayer-iframe').attr('src', url);
	
		$('iframe#trosvideoplayer-iframe').load(function() 
		{
		     //LOAD
		    $('iframe#trosvideoplayer-iframe').unbind('load');
		    hashBool = false;
		    
		});
  	 
	
	
  }
  
});
