var jsReady = false;
function isReady()
{
	return jsReady;
}
function pageInit()
{
	detectFallback();
	jsReady = true;
}

var date_now = new Date();
function getParams()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}
var hash 		= getParams();
var callsign	= (hash["callsign"] != undefined) 	? hash["callsign"] 	: "MAXIMAFM";
var streamid 	= (hash["streamid"] != undefined) 	? hash["streamid"] 	: 3993;
var channelid 	= (hash["channelid"] != undefined) 	? hash["channelid"] : "";

//OAS Bigbox
currentBigBoxURL = "";
function loadBigbox(bannerURL)
{
	if (currentBigBoxURL != bannerURL)
	{
		document.getElementById("bigboxIframe").contentWindow.location.replace(bannerURL);
		document.getElementById('bigboxIframe').style.display 	= "block";
		document.getElementById('bigboxContainer').style.zIndex = 1000;
		currentBigBoxURL = bannerURL;
	}
}

function detectFallback()
{
	if (!flashVersionIsAtLeast(9, 0, 28))
	{
		document.getElementById('fallbackMessage').innerHTML 		= 'Para obtener la mejor calidad de audio y acceder a contenido por demanda en nuestro player, por favor descargue y instale la ultima version del <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">ADOBE Flash Player</a>. Alternativamente, <a href="http://player.streamtheworld.com/liveplayer.php?callsign=' + callsign + '" target="_blank">escuche con nuestro player basico.</a>';
		document.getElementById('fallbackMessage').style.display 	= "block";
		document.getElementById('flashPlayer').style.top 			= '35px';
		document.getElementById('bigboxContainer').style.top 		= '101px';
	}
}

function flashVersionIsAtLeast(a, b, c)
{
	var flashVersion = deconcept.SWFObjectUtil.getPlayerVersion();
	if (flashVersion['major'] > a)
		return true;
	else if (flashVersion['major'] == a)
	{
		if (flashVersion['minor'] > b)
			return true;
		else if (flashVersion['minor'] == b)
		{
			if (flashVersion['rev'] >= c)
				return true;
		}
	}
	return false;
}

function updateWindowTitle(newTitle)
{
	top.document.title = newTitle;
}

/**
 * Call OAS JavaScript
 */
function getOASPreroll(pageURL)
{
	document.getElementById("prerollWrapperIframe").contentWindow.location.replace(pageURL);
}

/**
 * Callback from OAS
 */
function sendOASPrerollCallback(urlvideo, urlclick, urlPixel, urlPixelRedir)
{
    thisMovie("UnionRadioPlayer").onSendPreroll(urlvideo, urlclick, urlPixel, urlPixelRedir);
}

/**
 * Callback from OAS (Unable to get a preroll)
 */
function sendOASPrerollCallbackError()
{
	thisMovie("UnionRadioPlayer").onPrerollError();
}

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

