/*
player functions
*/
function setCookie(name, value, expire) {
	// CREATE COOKIE STRING WITH NAME, VALUE, AND EXPIRY PERIOD (in seconds)
	//variables
	var cookie_today = new Date();
	var expires = new Date();
	expires.setTime(cookie_today.getTime() + 1000*expire);
	document.cookie = name + '=' + escape(value) + '; path=/; expires=' + expires.toGMTString();
}
function getCookie(Name,deflt) {
	// RETRIEVE COOKIES FROM BROWSER, SET deflt DEFAULT VALUE IF IT IS NOT FOUND
	var search = Name + '=';
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(';', offset);
			if (end == -1) {
				end = document.cookie.length;
			}
			valueout = unescape(document.cookie.substring(offset, end));
			return valueout;
		}
		else
			return deflt;
		}
	else
		return deflt;
}

function playSong(file, artist, track, duration, image, repeat)	{
	//variables
	var songstring;
	//check for open marineplayer
	if(getCookie('marineplayer_open', 0) != 1)	{
		if(!repeat) launchPlayer();
		//if we have a sample to play, loop until player is found
		if((file != '') && (file != undefined)) {
			timer = setTimeout("playSong('" + file + "', '" + artist + "', '" + track + "', '" + duration + "', '" + image + "', '" + 1 + "')",3000);
		}
	}
	else {
		if((file != '') && (file != undefined)) {
			songstring = '_' + file + '|' + artist + '|' + track + '|' + duration + '|';
			(image == '') ? songstring += 'genThumb.jpg' : songstring += image;
			songstring += '|';
			setCookie('marineplayer_mp3', songstring, 15);
		}
	}
}
function launchPlayer()	{
	var w;
	var h;
	if (document.all) {
	   w = screen.width;
	   h = screen.height;
	}
	else {
	   w = window.innerWidth;
	   h = window.innerHeight;
	}
	var popW = 320;
	var popH = 170;
	var leftPos = (w-popW-70);
	var topPos = 50;
//	marineplayer = window.open('/player/detect.html','marineplayer','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
	marineplayer = window.open('/player/090312-detect.html','marineplayer','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
}