$(document).ready(function(){


	Cufon.replace('.heading');
	


	//External links.
	$('a[rel="external"]').click(function(){
		window.open( $(this).attr('href') );
		return false;
	});
	
	$('#li_audio').click(function(){
		popoutNav();
		return false;
	});
	
	jQuery.event.add(window, "load", resizeDiv);
	jQuery.event.add(window, "resize", resizeDiv);

	function resizeDiv(){
  	$("div#div_container").css('height',$(document).height()-10);
	}

});


function popoutNav(){
	myPopupWindow=window.open("popoutplayer.html?track=0&pos=0","","location=no, scrollbars=no, resizable=yes, toolbar=no, menubar=no, width=300, height=150" );
}

var myPopupWindow = '';
function popoutplayer(array)
{
/*
	url="popoutplayer.html";
	name="ChapelClub";
	width=300;
	height=150;
	
	//Remove special characters from name
	    name = name.replace(/\/|\-|\./gi, "");

	    //Remove whitespaces from name
	    var whitespace = new RegExp("\\s","g");
	    name = name.replace(whitespace,"");

	    //If it is already open
	    if (!myPopupWindow.closed && myPopupWindow.location)
	    {
	        myPopupWindow.location.href = encodeUrl(url);
	    }
	    else
	    {
	        myPopupWindow= window.open(encodeUrl(url),name, "location=no, scrollbars=no, resizable=yes, toolbar=no, menubar=no, width=" + width + ", height=" + height );
	        if (!myPopupWindow.opener) myPopupWindow.opener = self;
	    }

	     //If my main window has focus - set it to the popup
	    if (window.focus) {myPopupWindow.focus()}
*/
myPopupWindow=window.open("popoutplayer.html?track=" + array[0] + "&pos=" + array[1],"","location=no, scrollbars=no, resizable=yes, toolbar=no, menubar=no, width=300, height=150" );
}


function popoutplayerold(array){
	settings = {
				height:150, // sets the height in pixels of the window.
				width:300, // sets the width in pixels of the window.
				toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
				scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
				status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
				resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
				left:0, // left position when the window appears.
				top:0, // top position when the window appears.
				center:0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
				createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
				location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
				menubar:0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			};
			
			parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
			
			window.open("popoutplayer.html?track=" + array[0] + "&pos=" + array[1], name, parameters).focus();
}


function encodeUrl(url)
{
 	if (url.indexOf("?")>0)
 	{
		encodedParams = "?";
 		parts = url.split("?");
 		params = parts[1].split("&");
 		for(i = 0; i < params.length; i++)
 		{
			if (i > 0)
	 		{
				encodedParams += "&";
			}
			if (params[i].indexOf("=")>0) //Avoid null values
			{
				p = params[i].split("=");
				encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
			}
			else
			{
				encodedParams += params[i];
			}
		}
		url = parts[0] + encodedParams;
	}
	return url;
}
