//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor)
			query = "alias=";
		else
		{
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
			var splits = currentAnchor.substring(1).split('&');
			//Get the section
			var alias = splits[0];
			delete splits[0];
			//Create the params string
			var params = splits.join('&');
			var query = "alias=" + alias + params;
			//Send the petition
			$("#loading").show();
			
			//alert(query);
			
			$.get("/ajax/get_dyn-playlist-video-info.cfm",query, function(data){
				title_array=data.split("~");
				//document.title=title_array[0];
				$("#dyn-playlist-title").html(title_array[0]);
				DelvePlayer.doLoadMedia(title_array[1], true, 3000);
				$("#playlist-menu").html(title_array[2]);
			});
		}
		
	}
}

function dynamicVideo(destinationURL) { 
	destination_array=destinationURL.split("/");
	alias=destination_array[7];
	p=destination_array[5];
	window.location='#'+alias+'&p='+p;
	
	newPageTrackerLine='/'+destination_array[3]+'/'+destination_array[4]+'/'+destination_array[5]+'/'+destination_array[6]+'/'+destination_array[7];
	
	$("#Article_Skyscraper").html('<iframe frameborder="0" scrolling="no" width="160" height="600" style="margin:0; padding:0; background:transparent;" src="/adserve.cfm?category='+destination_array[3]+'&amp;adzone=Article_Skyscraper" id="Article_Skyscraper_iframe"></iframe>');
	$("#Playlist_Rectangle").html('<iframe frameborder="0" scrolling="no" width="300" height="250" style="margin:0; padding:0; background:transparent;" src="/adserve.cfm?category='+destination_array[3]+'&amp;adzone=Playlist_Rectangle" id="Playlist_Rectangle_iframe"></iframe>');
	$("#Playlist_Footer_Leaderboard").html('<iframe frameborder="0" scrolling="no" width="728" height="90" style="margin:0; padding:0; background:transparent;" src="/adserve.cfm?category='+destination_array[3]+'&amp;adzone=Playlist_Footer_Leaderboard" id="Playlist_Footer_Leaderboard_iframe"></iframe>');	

	try {
		var pageTracker = _gat._getTracker("UA-1851223-1");
		pageTracker._trackPageview(newPageTrackerLine);
	} catch(err) {
	}
}
