/*
 *	@function		launchWindow
 *	@desription		launches a javascript popup window
 *	@note			this is a copy of the function in universalIncludes/display/javascript/launchWindow.js
 *					any changes made there should be reflected here
 *					this function only gets defined if it doesn't already exist ( this is to ensure
 *						that the function exists, even if the necessary script ref is not made )
 */
 
if( typeof launchWindow == "undefined" )
{
	function launchWindow( url, n, w, h, sb, tb, mb, lb, stb, rs, fullscreen )
	{
		var win;
		var windowAttributes = "";
		
		if( !n )
		{
			win = window.open( url );
		}
		else if( fullscreen == 1 )
		{
			windowAttributes = "fullscreen=1,scrollbars=auto";
			win = window.open( url, n, windowAttributes );
		}
		else if( !w || !h )
		{
			win = window.open( url, n );
		}
		else
		{
			windowAttributes = "";
			windowAttributes += "width=" + w;
			windowAttributes += ",height=" + h;
			windowAttributes += ",scrollbars=" + ( ( sb ) ? 1 : 0 );
			windowAttributes += ",toolbar=" + ( ( tb ) ? 1 : 0 );
			windowAttributes += ",menubar=" + ( ( mb ) ? 1 : 0 );
			windowAttributes += ",location=" + ( ( lb ) ? 1 : 0 );
			windowAttributes += ",statusbar=" + ( ( stb ) ? 1 : 0 );
			windowAttributes += ",resizable=" + ( ( rs ) ? 1 : 0 );
			win = window.open( url, n, windowAttributes );
		}
		
		win.focus();
	}
}

function launchMediaPlayer( mediaPath )
{
	if( !mediaPath ) return false;
	
	if( mediaPath.indexOf( "http://watch.muchmusic.com" )==0 || mediaPath.indexOf( "http://axs.muchmusic.com" ) == 0 || mediaPath.indexOf( "http://ads.ctvdigital.net/RealMedia/" ) == 0 )
	{
		mediaPath = mediaPath.replace( /\"/g, "" );
		mediaPath = mediaPath.replace( "%22", "" );
		mediaPath = mediaPath.replace( "%22", "" );
		mediaPath = mediaPath.replace( /index.jsp/g, "" );
		
		var w = 1010;//976;
		var h = 850;//929;
		var sb = 0;
		
		if( w > screen.availWidth )
		{
			w = screen.availWidth - 20;
			sb = 1;
		}
		
		if( h > screen.availHeight )
		{
			h = screen.availHeight - 20;
			sb = 1;
		}
		
		launchWindow( mediaPath, "muchAxs", w, h, sb, 0, 0, 0, 0, 1 );
		return;
	}
	
	var url = "http://www.muchmusic.com/mediaPlayer/?mediaPath=" + mediaPath + "&";
	launchWindow( url, "mm_vidplayer", 700, 500, 0, 0, 0, 0, 0, 0 );
}


/* Legacy Window launching functions */
if( typeof select_link == "undefined" )
{
	function select_link(linkurl, wsize, hsize, scbar, mnbar)
	{
		//muchPop = window.open(linkurl,"muchpop","width= "+wsize+",scrollbars="+scbar+",height= "+hsize+",menubar="+mnbar+",toolbar=no,status=yes,location=no");
		//window.muchPop.focus();
		var scrollBars = scbar == "yes" || scbar == 1;
		var menuBar = mnbar == "yes" || mnbar == 1;
		launchWindow( linkurl, "muchpop", wsize, hsize, scrollBars, null, menuBar );
	}
}

if( typeof popWindow == "undefined" )
{
	function popWindow(linkurl, wsize, hsize, scbar, mnbar, sizeable, tb, st, loc)
	{
		//muchPop = window.open(linkurl,"muchpop","width= "+wsize+",scrollbars="+scbar+",resizable="+sizeable+",height="+hsize+",menubar="+mnbar+",toolbar="+tb+",status="+st+",location="+loc);
		//window.muchPop.focus();
		
		var scrollBars = scbar == "yes" || scbar == 1;
		var menuBar = mnbar == "yes" || mnbar == 1;
		var resizeable = sizeable == "yes" || sizeable == 1;
		var toolBar = tb == "yes" || tv == 1;
		var statusBar = st == "yes" || st == 1;
		var locationBar = loc == "yes" || loc == 1;
		
		launchWindow( linkurl, "muchPop", wsize, hsize, scrollBars, toolBar, menuBar, locationBar, statusBar, resizeable );
	}
}