/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", initialize, false);
}



function refreshAd(){
	var d=document.getElementById('ad');
	if(d){	
		var s=d.getElementsByTagName('iframe');
		if(s && s.length){
			s[0].src=s[0].src+'&'+new Date().getTime();
		}
	}
	return true;
}



function injectVideoInfo(info)
{
	//refreshAd();
	
	/*
	
	var d=document.getElementById('videoinfo');
	if(d){	
		var s=d.getElementsByTagName('iframe');
		if(s && s.length){
			s[0].src=s[0].src+'&'+new Date().getTime();
		}
	}
	return true;*/
}



/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
   document.write("<script defer src=ie_onload.js><"+"/script>");
/*@end @*/

/* for other browsers */
window.onload = initialize;

function initialize() 
{
  dhtmlHistory.initialize();	
  dhtmlHistory.addListener(handleHistoryChange);
  
  // determine our current location so we can
  // initialize ourselves at startup
  var initialLocation = dhtmlHistory.getCurrentLocation();
  
  // set the default
  if (initialLocation == ""){
    initialLocation = "<i>default to PlayinUrTubez</i>";
	}

  // now initialize our starting UI
	//updateUI not needed for flash version
  updateUI(initialLocation, null);
}


/** A simple method that updates our user
    interface using the new location. */
function updateUI(newLocation, historyData) 
{
  // simply display the location and the
  // data
  var historyMessage;
  if (historyData != null){
    historyMessage = historyData.message;
		document.title = ".PlayinUrTubez.";
	} else {
		historyMessage = "<i>No History Data - init history</i>";
		document.title = ".PlayinUrTubez.";
	}    
  	var message = "<b>Location:</b> " + newLocation + "<br /><b>History Data Storage:</b> " + historyMessage;                
   //output.innerHTML = message;
}


function navHistoryForward()
{
	if (window.history.length > 0) window.history.go(1);
}

function navHistoryBackward()
{
	if (window.history.length > 0) window.history.go(-1);
}


function handleHistoryChange(newLocation, historyData) 
{
	// this is updating the temp html UI changes
  	updateUI(newLocation, historyData);
	
	if(thisMovie("mb_loader").dispatchIncomingDDL)
	{
	   thisMovie("mb_loader").dispatchIncomingDDL(dhtmlHistory.getCurrentLocation());
	}
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}


function loadTrackingPixel(url)
{
   var img = new Image(1,1);
   img.src = url;
   
   console.log(img.src);
}


function setDeepLink(newLocation, historyMessage)
{	
	var historyData = {message:historyMessage};
	updateUI(newLocation, historyData);
	
	//Add to the dhtml history
	dhtmlHistory.add(newLocation, historyData);
	//pageTracker._trackPageview('/' + newLocation);
}

function getDeepLink()
{
	return dhtmlHistory.getCurrentLocation();
}

function getPageTitle(){
	//debugMsg("getPageTitle() called - " + document.title);
	return document.title;
}

function setPageTitle(windowTitle){
	//debugMsg("setPageTitle() called - " + windowTitle);
	document.title = windowTitle;
}

function popup(url, w, h) 
{
	var wid = 600;
	var hi = 476;
	
	if (w != null) wid = w; 
	if (h != null) hi  = h; 
	
	var scroll = true;
	
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	
	new_spec = wid + "_" + hi + scroll;
	scrolling = scroll? "yes": "no";
	if (scroll && document.all && (navigator.userAgent.indexOf("Mac") > -1)) wid = wid+17;
	newwin=window.open(url,new_spec,"WIDTH=" + wid + ",HEIGHT=" + hi + ",scrollBars=" + scrolling + ",resizable=no,screenX="+winl+",screenY="+wint+",left="+winl+",top="+wint);
	newwin.focus();
}


function doNothing() { return true; }

function allSwfsMustDIE()
{
	var objects = document.getElementsByTagName("OBJECT");

	//alert('destroy all ' + (objects.length) + ' swfs');
	for (var i=0; i < objects.length; i++) 
	{
		for (var x in objects[i]) 
		{
			if (typeof objects[i][x] == 'function') 
			{
			//alert('destroying ' + objects[i][x]);
			objects[i][x] = null;
			}
		}
	}
}
	

if (typeof window.onunload == 'function') {
  var oldunload = window.onunload;
  window.onunload = function() {
    allSwfsMustDIE();
    oldunload();
  }
} else {
  window.onunload = allSwfsMustDIE;
}


function scrollWindow(xScroll, yScroll){
	scroll(xScroll,yScroll);
	return true;
}