function getProperty(s, name, delimiter)
{
	if (s)
    	var m = s.match(new RegExp(name + '=([^' + delimiter + ']*)'));
    	
    return (m ? unescape(m[1]) : null);	

}

function setCookieValue(name, value, time)
{
	var date = new Date();
	date.setTime(date.getTime() + (time * 1000));
	document.cookie = name + "=" + value + '; expires=' + date.toGMTString() + "; path=/; domain=.rhapsody.com";
}


function renderSignIn()
{

	var username = getProperty(document.cookie, "username", ";");
	
	accountMenu = new Element('p');
	 
	if (username)
	{
		$("account").insert(new Element('p', {'class': 'username'}).update(username));	    
		 accountMenu.insert(new Element('a', {href: '/authentication/logout', 'class': 'first' }).update('Sign Out'));		
	}
	else
	{
		 accountMenu.insert(new Element('a', {href: '/authentication/login', 'class': 'first' }).update('Sign In'));	
	}
	
	accountMenu.insert(new Element('a', {href: 'https://account.rhapsody.com/' }).update('My Account'));
	accountMenu.insert(new Element('a', {href: '/-helpcenter' }).update('Help'));
	$("account").insert(accountMenu);


}

document.observe("dom:loaded", function() {

	setCookieValue("lastViewedUrl", escape(document.location.href), 10000);

	renderSignIn();
});


