
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
	
//	alert( "agt: " + agt + ", is_major: " + is_major + ", is_minor: " + is_minor );

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

var is_opera = (agt.indexOf("opera") != -1);

var popUpWin = null;
var posX = 50;
var posY = 50;

if( is_nav )
{
	posX = window.parent.screenX + 50;
	posY = window.parent.screenY + 50;	
}
else
{
	posX = window.parent.screenLeft + 50;
	posY = window.parent.screenTop + 50;
}

function setPosition( pX, pY )   // Called when player is closed to save position
{
//  alert( "pX: " + pX + ", pY: " + pY );
	posX = pX;
	posY = pY;
}

function popUpWindow(productID, cat_id)
{
	var openWin = false;

	// See if the player is open
//	if( popUpWin == null ||  ( popUpWin.name && popUpWin.name.equals("mmw_player") != -1 ) )
    if( !is_opera )
    {
		try
		{
			if( popUpWin != null && popUpWin.document != null && popUpWin.pingPlayer() )
			{
	//			alert( popUpWin.pingPlayer() );
				// player is already open and OK so do JS commands
				popUpWin.doPreviewTrack(productID, cat_id);			// Start a new track	
			}
			else
			{
				// Wrong window, close it
				popUpWin.close();
				openWin = true;
			}
		}
		catch (e)   // Any exception better open window
		{
			openWin = true;
		}
    }
    else 
	{
		openWin = true;
	}

	if( openWin )
	{
		URLStr = "/jsp/hbMediaPlayer_v2.jsp";   // Override popup
		width = "272";
		///width = "300";
		height = "203";
		//  height = "300";
		var theLocation = URLStr + '?productID=' + productID + '&cat_id=' + cat_id;
		
		//  alert( theLocation );
		if( is_nav )
		{
			popUpWin = open(theLocation, 'mmw_player', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',screenY=' + posY + ',screenX=' + posX );
		}
		else
		{
			popUpWin = open(theLocation, 'mmw_player', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width=' + width + ',height=' + height + ',top=' + posY + ',left=' + posX );
		}
//		alert( popUpWin.pingPlayer() );
	}
}

