/**
 * @author Ralph Sledge
 * @copyright 2007 AccuRadio, LLC
 * 
 * @requires swfobject.js
 * 
 * This is the file that gets loaded to support the flash-based
 * version of the player.
 * 
 */

var CDATA = 0;
var currVol = 60;
var flashProxy = new Object();

function acPause() {
	if (mtype == "swf7") flashProxy.call("player_pause");
	else document.AccuPlayer.asPause();
}

function acResume() {
	if (mtype == "swf7") flashProxy.call("player_start");
	else document.AccuPlayer.asResume();
}

function acGwFin() {
	if (mtype == "swf7") var j;
	else document.AccuPlayer.asGwFin();
}

function acSkip() {	
	if (mtype == "swf7") flashProxy.call("player_skip");
	else document.AccuPlayer.asSkip();
	
	// track skip, if the function exists
	var fSongTrack = songTrack ? songTrack : false;
	if (fSongTrack) {
		fSongTrack(false, "/static/html/skiptrack.html");
	}
	
	$.event.trigger("skipFinished");
}

function acVolume(num) {
	// This has to be converted to conform to the old accuradio ratio
	// (range 1-6)
	//var realnum = parseInt(num / 16);
	var realnum = parseInt(num);
	if (mtype == "swf7") flashProxy.call("player_setvolume_normal", realnum);
	else document.AccuPlayer.asSetVolume(realnum);
}

function acSetDs() {
	if (mtype == "swf7") flashProxy.call("player_setds");
	else document.AccuPlayer.asSetNew();
}

function writeFlash() {
	// Find dimensions
	if (typeof(pWidth) == "undefined") {
		var dWidth = $("#div_player").css("width");
		if (parseInt(dWidth) > 0)
			pWidth = parseInt(dWidth);
		else
			pWidth = 220;
	}
	if (typeof(pHeight) == "undefined") {
		var dHeight = $("#div_player").css("height");
		if (parseInt(dHeight) > 0)
			pHeight = parseInt(dHeight);
		else
			pHeight = 24;
	}
	
	if (typeof(plpath_override) != "undefined") plpath = plpath_override;
	
	if (mtype == "swf96") {
		// write swf9 > 115
		
		var qs = new Array();
		qs.push("listid=" + listid);
		if (typeof(plpath) != "undefined") qs.push("plpath=" + plpath);
		//if (typeof(brand) != "undefined") qs.push("brand=" + brand);
		if (typeof(brandid) != "undefined") qs.push("brand=" + brandid);
		if (typeof(cssURL) != "undefined") qs.push("css=" + cssURL);
		if (typeof(ando) != "undefined") qs.push("ando=" + ando);
		if (typeof(sip) != "undefined") qs.push("sip=" + sip);
		if (typeof(adsense_channels) != "undefined") qs.push("adsense_channels=" + adsense_channels);
		// Problematic if the 300x250 comes after this code
		if (typeof(google_adtest) != "undefined") qs.push("adtest=" + google_adtest);
		var flashVars = qs.join("&");
		
		var att = {
			data: "/static/swf/AccuPlayerAS.swf",
			width: pWidth,
			height: pHeight,
			id: "AccuPlayer",
			name: "AccuPlayer",
			allowScriptAccess: "always"
		};
		var par = {
			flashvars: flashVars,
            allowscriptaccess: "always"
		};
		swfobject.createSWF(att, par, "div_swfplayer");
	} else {
		// write swf7
		var lcId = new Date().getTime();
		
		flashProxy = new FlashProxy(lcId, '/static/swf/JavaScriptFlashGateway.swf');
		
		var flashVars = 'lcId=' + lcId + "&listid=" + listid;
		if (typeof(brand) != "undefined") flashVars += "&thisBrand=" + brand;
		if (typeof(ando) != "undefined") flashVars += "&ando=" + ando;
		if (typeof(sip) != "undefined") flashVars += "&sip=" + sip;
		if (typeof(plpath) != "undefined") {
			// So we don't need multiple override settings
			if (plpath.indexOf("xspf96") > -1) plpath = plpath.replace("xspf96", "xspf7");
			flashVars += "&plurl=" + plpath;
		}
		
		var isie6 = (navigator.appVersion.indexOf("MSIE 6") != -1) ? true : false;
		if (isie6) flashVars += "&pisie6=1";
		
		// write the tag
		var tag = new FlashTag('/static/swf/accuplayer7.swf', pWidth, pHeight, '7,0,14,0');
		tag.bgcolor = "000000";
		tag.setFlashvars(flashVars);
		tag.write(document);
	}
}

function swfGoHome() {
	var nw = window.open("/", "listmusic");
	nw.focus();
}

window.onload = function() {
}
