//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 600);
});
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();
			
			$.get("/ajax/get_dyn-video-info_mll.cfm",query, function(data){
				title_array=data.split("~");
				document.title=title_array[0];
				$("#dyn-video-detail-wrap").html(title_array[3]);
				$("#dyn-video-title").html(title_array[1]);
				$("#dyn-article-area").html(title_array[4]);
				$("#DelvePlayer").ready(function () { DelvePlayer.doLoadMedia(title_array[2], true, 3000); } );
				
				// update menu??
				//$("#loading").hide();

			});
			
		}
		
	}
}

function dynamicVideo(destinationURL) { 
	destination_array=destinationURL.split("/");
	alias=destination_array[4];
	window.location='#'+alias;
	
	newPageTrackerLine='/'+destination_array[3]+'/'+destination_array[4];
	$("#Article_Skyscraper").html('<iframe frameborder="0" scrolling="no" width="172" height="600" style="margin:0; padding:0; background:transparent;" src="/mllserve.cfm?alias='+destination_array[4]+'" id="Article_Skyscraper_iframe"></iframe>');
	$("#Video_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=Video_Footer_Leaderboard" id="Video_Footer_Leaderboard_iframe"></iframe>');

	try {
		var pageTracker = _gat._getTracker("UA-1851223-1");
		pageTracker._trackPageview(newPageTrackerLine);
	} catch(err) {
	}

}
