var triplejlisten = triplejlisten || {};  
triplejlisten.popup = triplejlisten.popup || {};

triplejlisten.popup.open = function (href, vars, params)  
{  
	// Defaults (don't leave it to the browser)  
	var defaultParams = {  
		"width":       "750",   // Window width  
		"height":      "650",   // Window height  
		"top":         "50",     // Y offset (in pixels) from top of screen  
		"left":        "50",     // X offset (in pixels) from left side of screen  
		"directories": "no",    // Show directories/Links bar?  
		"location":    "no",    // Show location/address bar?  
		"resizeable":  "no",   // Make the window resizable?  
		"menubar":     "no",    // Show the menu bar?  
		"toolbar":     "no",    // Show the tool (Back button etc.) bar?  
		"scrollbars":  "no",   // Show scrollbars?  
		"status":      "no"     // Show the status bar?  
	};  

	var windowName = params["windowName"] || "new_window";  

	var i, useParams = "";  

	// Override defaults with custom values while we construct the params string  
	for (i in defaultParams) {  
		useParams += (useParams === "") ? "" : ",";  
		useParams += i + "=";  
		useParams += params[i] || defaultParams[i];  
	}  

	var i, useVars = "";
	for (j in vars) {  
		useVars += (useVars === "") ? "?" : "&";  
		useVars += j + "=";  
		useVars += vars[j];
	}  


	if (triplejlisten.popup.gWin && !triplejlisten.popup.gWin.closed) {

		triplejlisten.popup.gWin.setEmbed(vars);

	} else {

		triplejlisten.popup.gWin = window.open("", "playerWindow", useParams);
		
		if (triplejlisten.popup.gWin.launchCheck != "launched"){
			
			triplejlisten.popup.gWin = window.open(href + useVars, "playerWindow", useParams);

		} else {

			triplejlisten.popup.gWin.setEmbed(vars);
		}
	}

	triplejlisten.popup.gWin.focus();
}; 

function showPlayer(xml, mediaType, launchType, pluginTarget, pluginTitle, pluginColour) {

	if (mediaType == "gallery")
		mediaType = "image";

    var launchVars = {  
         "show":		"jukebox", 
         "xmlUrl":      xml, 
         "mediaType":   mediaType,
         "launchType":  launchType,
         "pluginTarget": pluginTarget,
         "pluginTitle": pluginTitle,
         "pluginColour": pluginColour
     };  
	
	triplejlisten.popup.open("http://www.abc.net.au/triplej/media/listen.htm", launchVars, {});
	return false;
}

function showListen() {
	
	var launchVars = {
	    "show":		"listen" 
	};  
	
	triplejlisten.popup.open("http://www.abc.net.au/triplej/media/listen.htm", launchVars, {});
	return false;
}

function showLive() {

    var launchVars = {
	    "show":		"jukeboxLive",
         "xmlUrl":      null, 
         "mediaType":   "stream",
         "launchType":  "play",
         "pluginTarget": null,
         "pluginTitle": null,
         "pluginColour": null
	};  
	
	triplejlisten.popup.open("http://www.abc.net.au/triplej/media/listen.htm", launchVars, {});
	return false;
}



function callExternalInterface(url, parseType, queueType, pluginTarget, pluginTitle, pluginColour, windowName) 
{
	if (navigator.appName.indexOf("Microsoft") != -1)
		return window["mymovie"].loadMedia(url, parseType, queueType, pluginTarget, pluginTitle, pluginColour);
	else 
		return document["mymovie"].loadMedia(url, parseType, queueType, pluginTarget, pluginTitle, pluginColour);
}

function checkBrowser() 
{ 
	var value = navigator.userAgent; 
	return value; 
}

function launchInWindow(url) 
{ 
	if (windowName)
		window.open(url, windowName);
	else
		window.open(url, "_blank");
}
