	var newwindow = '';
	var playerLoaded = false;
	var timeoutLoaded = 10;


/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/
$(document).ready(function () {
	$('#loginLink').click(function (e) {
		$('#login').modal();
	});

var arVersion = navigator.appVersion.split("MSIE");
if(arVersion.length>1){
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7.0)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	      {
	         var imgID = (img.id) ? "id='" + img.id + "' " : ""
	         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	         var imgStyle = "display:inline-block;" + img.style.cssText 
	         if (img.align == "left") imgStyle = "float:left;" + imgStyle
	         if (img.align == "right") imgStyle = "float:right;" + imgStyle
	         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	         var strNewHTML = "<span " + imgID + imgClass + imgTitle
	         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
	         img.outerHTML = strNewHTML
	         i = i-1
	      }
	   }
	}
}	
	
});


function help(element, divName, text){
	document.getElementById(divName).innerHTML = text;
}
	
function play(){
	getWindow();
	if (!newwindow.closed && newwindow.location) {
		sendEvent('playpause');
		getStatus();
	}
	else
	{
		playSong(0, 'play.php?SongList=HITS','HITS','', true);
	}
	
}

function getStatus(){
	try{
		pi = document.getElementById('playImage');
		if(!newwindow.closed && newwindow.location && newwindow.getStatus() == 0){
			pi.src = 'images/icons/playBig.png';
		}else{
			pi.src = 'images/icons/pause.png';
		}
	}
	catch(err){
		alert('error: ' + err);
	}
}


	function playSong(mp3id, mp3, title, photo, play){
		if(playerpop(mp3id, mp3, title, photo, play)){
			loadFile(mp3id, mp3, title, photo, play);
		}
	}

	function sendEvent(typ,prm) {
		getWindow();
		if (!newwindow.closed && newwindow.location) 
		{
			newwindow.sendEvent(typ,prm);
		} else{
			playSong(0, 'play.php?SongList=HITS','HITS','', true);
		}
	};
	
	function loadFile(mp3id, mp3, title, photo, play){
	try { 

		if(play){
			newwindow.loadFile('playerid',{id:mp3id,file:mp3,title:title,image:photo});
		}else{
			newwindow.addItem('playerid',{id:mp3id,file:mp3,title:title,image:photo},newwindow.getLength('playerid'));
		}
		} catch (err) {
			setTimeout('loadFile(' + mp3id +',\'' + mp3 + '\',\'' + title + '\',\'' + photo + '\',' + play + ')',2000);
		}
		if (window.focus) {newwindow.focus()}
	}

	function IsLoaded(mp3id, mp3, title, photo, play){
		if(!playerLoaded && timeoutLoaded>0){
			timeoutLoaded--;
			setTimeout('IsLoaded(' + mp3id +',\'' + mp3 + '\',\'' + title + '\',\'' + photo + '\',' + play + ')',1000);
			return false;
		}else{
			loadFile(mp3id, mp3, title, photo, play);
			return true;
		}
	}

	function getWindow(){
		if(newwindow)
			return;
		CookieValue = getCookie('playerLoaded');
		if(CookieValue != null && CookieValue == 'yes') {
			newwindow = window.open('','player');
			newwindow.opener = self;
		}

	}
	function playerpop(mp3id, mp3, title, photo, play) {
		getWindow();
		if (!newwindow.closed && newwindow.location) {
			setLoaded(true);
			return true;
		}
		else {
			playerLoaded = false;
			timeoutLoaded = 10;
			newwindow=window.open('player.php','player','height=440,width=475');
			newwindow.opener = self;
			if(!IsLoaded(mp3id, mp3, title, photo, play))
			{	
			if (window.focus) {window.focus()}
			return false;
			}
		}
		return true;
	}
	
	function getCookie(c_name)
	{
		try { 
		  if (document.cookie && document.cookie.length>0)
		  {
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{ 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		  }
		}
		catch(err){
			alert('error: ' + err);
		}
		return "";
	}
	
	
	function popitup(page, name, props) {
		pop=window.open(page,name,props);
		if (!pop.opener) pop.opener = self;
		if (window.focus) {pop.focus()}
		return true;
	}
	
	function setLoaded(value){
		playerLoaded = value;
		if(playerLoaded){
			document.cookie = 'playerLoaded=yes; path=/';
		}else{
			document.cookie = 'playerLoaded=no; path=/';
		}
	}
	
	function getAbsolutePosition(element) {
		var r = { x: element.offsetLeft, y: element.offsetTop };
		if (element.offsetParent) {
		  var tmp = getAbsolutePosition(element.offsetParent);
		  r.x += tmp.x;
		  r.y += tmp.y;
		}
		return r;
	}

	function toggleMe(a){
	  var e=document.getElementById(a);
	  if(!e)return true;
	  if(e.style.display=="none" || e.style.display==""){
	    e.style.display="block"
	  } else {
	    e.style.display="none"
	  }
	  return true;
	}

	function setDisplay(display, a, atElement){
	  var e=document.getElementById(a);
	  var e2=document.getElementById(atElement);
	  if(!e)return true;
	  e.style.display=display;
	  e.style.left = getAbsolutePosition(e2).x;
	  //e.style.top = getAbsolutePosition(e2).y;
	  return true;
	}
	
	function setCurrentSong(song){
		//document.getElementById('currentSongTitle').innerHTML = "<a class='linkpeq' href='" + song.link + "' >" + song.title + "</a>";
		try{
			startPosition=0;
			myMainMessage = song.title;
			myMainLink = song.link;
			if(!scrollerEnabled){
				scrollerEnabled = true;
				mainTextScroller();
			}
		}
		catch(err){
			alert('error: ' + err);
		}
	}
	
	function handleFavoritesResponse() {
	  if(xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
	       	
	        var response = xmlhttp.responseText;
					if(response == "remove"){
						document['favoritesIMG'].src='images/icons/heart.png';
					}else{
						document['favoritesIMG'].src='images/icons/brokenheart.png';
					}
			}
	    }
	}
	
	
// THESE VARIABLES CAN BE CHANGED //
var speed=300;
var scrollingRegion=13;
var myMainMessage = '';
var myMainLink = '';
var scrollerEnabled = false;

// END CHANGEABLE VARIABLES //
var startPosition=0;
function mainTextScroller() {
        var mainMessage = myMainMessage;
        //var tempLoc=(scrollingRegion*3/mainMessage.length)+1;
        //if (tempLoc<1) {tempLoc=1}
        //var counter;
        //for(counter=0;counter<=tempLoc;counter++)
         //  mainMessage+=mainMessage;
		document.getElementById('currentSongTitle').innerHTML="<a class='linkpeq' href='" + myMainLink + "' >" + mainMessage.substring(startPosition,startPosition+scrollingRegion) + "</a>";
        startPosition++;
        if(startPosition + scrollingRegion>mainMessage.length) startPosition=0;
        setTimeout("mainTextScroller()",speed); 
}

	function viewLicense(select, layerName){
		value = select.options[select.selectedIndex].value;
		layer = document.getElementById(layerName);
		if(value=='BY'){
			layer.innerHTML  = LICENSEBY;
		}else if(value=='BYEQUAL'){
			layer.innerHTML = LICENSEBYEQUAL;
		}else if(value=='BYEQUALNOCOM'){
			layer.innerHTML = LICENSEBYEQUALNOCOM;
		}else if(value=='BYNOCOM'){
			layer.innerHTML = LICENSEBYNOCOM;
		}else if(value=='BYNOCOMSHARE'){
			layer.innerHTML = LICENSEBYNOCOMSHARE;
		}else if(value=='BYSHARE'){
			layer.innerHTML = LICENSEBYSHARE;
		}else{
			layer.innerHTML = EXPLAINLICENSE;
		}
	}
	
	function getPlayer(){
		getWindow();
		if (!newwindow.closed && newwindow.location) 
		{
			var current = newwindow.getCurrentItem();
			setCurrentSong(current);
			getStatus();
		}
	}
	
function preview(inputfile, preview, width) 
{
var file = inputfile.value
if (file.length<=0) return;
var ipreview = document.all(preview);
ipreview.src = 'file://' + file;
ipreview.width = width;
}


	