function startLoading() {
	buildPlaylistContent();
	displayTagCloud();
		
    //wait before we start playing... lets check if we're using a groovy URL.
    var videoIndex = 0;
    if(queryVideoIndex != ""){ videoIndex = queryVideoIndex; }
    if(queryMetaDataID != ""){ videoIndex = getMetaDataIndex(queryMetaDataID); }
    
    playVideo(videoIndex,'content');
}

function getMetaDataIndex(metadataID) {
	var playingItems;
    var contentLength = 0;
    
    if(currentlyShowing == 'content'){ playingItems = contentArray; }
    if(currentlyShowing == 'search'){ playingItems = searchContentArray; }
      	
    contentLength = playingItems.length;
      
    for(var i=0;i < contentLength;i++){	
    	if(playingItems[i].ContentMetaDataID == metadataID){
    		return i;
    	}
    }
    return 0;
}

function initPlayer(index) {
	var playingItem;
	var isContentAvailable = true;
	
	if(currentlyShowing == 'content'){ playingItem = contentArray[index]; }
	if(currentlyShowing == 'search'){ playingItem = searchContentArray[index]; }

	if(playingItem == null){
		isContentAvailable = false;
		alert("isContentAvailable:" + isContentAvailable);
	}else{
	  theFile = playingItem.VideoPath;
	  theImage = playingItem.ThumbnailPath;
	}

	if(isContentAvailable)
	{
		//device detection
		/*if (navigator.userAgent.match(/iPad/i) != null)
		{
			var height = 289;
			var width = 513;
					
			var ipad='';
			ipad+="<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' height='"+height+"' width='"+width+"'><param name='src' value='"+theFile+"' autoplay='false'><param name='autoplay' value='false'><param name='type' value='video/quicktime' height='"+height+"' width='"+width+"'><embed src='"+theFile+"'  autoplay='false' height='"+height+"' width='"+width+"' autoplay='false' type='video/quicktime' pluginspage='http://www.apple.com/quicktime/download/' flashvars='autostart=false'></object>";
		
			$("#videoHolder").html(ipad);
		}
		else
		{*/
			deletePlayer('videoHolder', 'videoWindow', 'player1'); 
			createPlayer('videoWindow', 'player1', theFile, theImage);		
		/*}*/
	}else{
		//TODO: show something saying there is no content
	}
}

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
	/*swfobject.removeSWF(thePlayerId);
	var tmp = document.getElementById(theWrapper);
	if (tmp){ tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }*/
	playerReady('player1'); // Player Status Listeners. Detected when video finished
}

function createPlayer(thePlaceholder, thePlayerId, theFile, theImage) {
	getURL(thePlaceholder, thePlayerId, theFile, theImage); // calls vidzapper-cdn.js
}

function doCreatePlayer(thePlaceholder, thePlayerId, theFile, theImage, streamFile, streamURL) {
	var flashvars;
	/*if(streamURL != ""){
		//STREAM FILE
		 flashvars = {
			streamer:streamURL,
			file:streamFile,
			type:'rtmp',
			autostart: videoPlayer_IsAutoStart,
			skin:'vidplayer/skins/elcorteingles.swf',
			abouttext:'Vivocomtech',
			aboutlink:'http://www.vivocom.es',
			controlbar: videoPlayer_ControlBar,
			controlbar:'over',
			stretching:'uniform',
			bufferlength:'2',
			image:theImage
		}
	}else{
		//PROGRESSIVE
		 flashvars = {
			file:theFile,
			provider:'http',
			autostart: videoPlayer_IsAutoStart,
			skin:'vidplayer/skins/elcorteingles.swf',
			abouttext:'Vivocomtech',
			aboutlink:'http://www.vivocom.es',
			controlbar: videoPlayer_ControlBar,
			controlbar:'over',
			stretching:'uniform',
			bufferlength:'5',
			image:theImage,
			plugins:'gapro-1&gapro.accountid=UA-3247148-60&gapro.trackstarts=true&gapro.trackpercentage=true&gapro.tracktime=true'
		 }
	}
	var params = {
		allowfullscreen:'true', 
		allowscriptaccess:'always',
				wmode: 'transparent'
	}
	var attributes = {
		id:thePlayerId,  
		name:thePlayerId
	}

	swfobject.embedSWF('vidplayer/player.swf', thePlaceholder, '513', '289', '9.0.115', false, flashvars, params, attributes);
	try{var tmp = document.getElementById('player1');tmp.innerHTML;}catch(Exception){} // We have to have this line for google chrome. (gains access to the player)*/
	
	if(streamURL != "")
	{
		//RTMP STREAM FILE
		//Comentado para poner player de V4X
		/*
		jwplayer("videoHolder").setup({
	        flashplayer: "vidplayer/player.swf",
	        streamer:streamURL,
			file:streamFile,
			type:'rtmp',
	        autostart: videoPlayer_IsAutoStart,
	        skin: theSkin,
	        abouttext: "vivocomtech",
	        aboutlink: "http://www.vivocomtech.com",
	        controlbar: videoPlayer_ControlBar,
	        stretching: "exactfit",
	        bufferlength: 5,
	        wmode: "opaque",
	        image: theImage,
       		id: thePlayerId,  
			name: thePlayerId,
	        height: 399,
	        width: 710
	    });*/		
	}
	else
	{
		 jwplayer("videoHolder").setup({
	        flashplayer: "vidplayer/player.swf",
	        file:theFile,
			provider:'http',
			autostart: 'true',
			skin:'vidplayer/skins/elcorteingles.swf',
			abouttext:'Vivocomtech',
			aboutlink:'http://www.vivocom.es',
			controlbar: videoPlayer_ControlBar,
			controlbar:'over',
			stretching:'uniform',
			bufferlength:'5',
			image:theImage,
	        height: 289,
	        width: 513
	    });
	}	
}

