	var is_active = false;
	var timeoutID = '';
	var showddID = '';
	var currentmenu = '';
	var creditcarddetails = '';
	var creditcardbreak = '';
	var menuskin = 'skin1';
	var cartContextOptions='';
	var active_window = null; /*
	* global active window stored as this has to be opened with an onclick before any ajax requests are made. prevening the dreaded popup security theck
	* ideally should be stored as JUNO_API.config.window['active_name'] but prototyping overrides this --> ajax login nightmare.
	*/ 
	var securePopup='';
	function addToCartWindow(newurl, media_id) {
		if (media_id == 2 || media_id == 1) {
			// merchandise
			h=605;
		} else {
			h=400;
		}
        w=700;
		win = window.open('http://' + location.hostname + '/' + newurl, 'MiniJunoRecords', 'height='+h+',width='+w+',toolbar=no,scrollbars=yes,resizable=1,location=1');
		win.focus();
        return false;
	}	
	
	function MiniNewWindow(newurl) {
	    h=130;
	    w=250;
		
		win = window.open('http://' + location.hostname + '/' + newurl, 'MiniJunoRecords', 'height='+h+',width='+w+',toolbar=1,scrollbars=1,resizable=1,location=1');
		win.focus();
        return false;
	}
	function MiniWindow(newurl) {
	    h=130;
	    w=250;
		
		win = window.open('http://' + location.hostname + '/' + newurl, 'MiniJunoRecords', 'height='+h+',width='+w+',toolbar=1,scrollbars=1,resizable=1,location=1');
	}
	function LinkAddWindow(newurl) {
	   	document.location ='http://' + location.hostname + '/' + newurl;
	}
	function MiniChartAddWindow(newurl) {
	    w=790;
	    h=150;
      		    
		win = window.open('http://' + location.hostname + '/' + newurl, 'MiniJunoRecords', 'height='+h+',width='+w+',toolbar=1,scrollbars=1,resizable=1,location=1');
		//win.focus();
	}
	function MiniAddWindow(newurl) {
	    h=130;
	    w=250;
		
		win = window.open('http://' + location.hostname + '/' + newurl, 'MiniJunoRecords', 'height='+h+',width='+w+',toolbar=1,scrollbars=1,resizable=1,location=1');
		win.focus();
	}
	function MiniNewWindowS(newurl) {
		win = window.open('https://' + location.hostname + '/' + newurl, 'MiniJunoRecordsS', 'height=110,width=250,toolbar=1,scrollbars=1,resizable=1,location=1');
        win.focus();
		return false;
	}
	
	function NewWindow(url, width, height, win_name) {
		var default_width = 660;
		var default_height = 540;

		/*
		if (arguments.length == 1) {
			// We need to use the default width and height
			
			width = default_width;
			height = default_height;
		}
		else*/ 
		
		width  = width  || default_width;
		height = height || default_height;
		
		if(arguments.length != 4) var win_name = 'JunoRecords';

		var options = 'width=' + width + ',height=' + height + ',toolbar=1,scrollbars=1,resizable=1,location=1';

		win = window.open('http://' + location.hostname + '/' + url, win_name, options);
		win.focus();
		
		return false;
	}
	
	function StandardWindow(url, width, height, win_name) {
		var default_width = 1024;
		var default_height = 768;

		if (arguments.length == 1) {
			// We need to use the default width and height
			
			width = default_width;
			height = default_height;
		}
		else if(arguments.length != 4) var win_name = 'JunoRecords';

		var options = 'width=' + width + ',height=' + height + ',toolbar=1,scrollbars=1,resizable=1,location=1';

		win = window.open('http://' + location.hostname + '/' + url, win_name, options);
		win.focus();
	
		return false;
	}
		
	function NewWindowS(url, width, height, win_name) {
		var default_width = 700;
		var default_height = 540;

		if (arguments.length == 1) {
			// We need to use the default width and height

			width = default_width;
			height = default_height;
		}
		else if(arguments.length != 4) var win_name = 'JunoRecords';

		var options = 'width=' + width + ',height=' + height + ',toolbar=1,scrollbars=1,resizable=1,location=1';

		win = window.open('https://' + location.hostname + '/' + url, win_name, options);
		win.focus();
		return false;
	}
	
	var mouseX, mouseY, source;
	
	function highlight(id){
		document.getElementById(id).style.backgroundColor = "highlight";
		document.getElementById(id).style.color = "white";
	}

	function lowlight(id) {	
		document.getElementById(id).style.backgroundColor = "white";
		document.getElementById(id).style.color = "black";
	}
	function jumpto(event) {
		if (source.className == "menuitems") {
			if (source.getAttribute("target") != null)
				window.open(source.url, source.getAttribute("target"));
			else
				window.location = source.url;
		}
	}
	function getScrollingPosition(){
		var position = [0, 0];
		
		if (typeof window.pageYOffset != 'undefined'){
			position = [
				window.pageXOffset,
				window.pageYOffset
			];
		}
		else if (typeof document.documentElement.scrollTop!= 'undefined' && document.documentElement.scrollTop > 0){
			position = [
				document.documentElement.scrollLeft,
				document.documentElement.scrollTop
			];
		}
		else if (typeof document.body.scrollTop != 'undefined'){
			position = [
				document.body.scrollLeft,
				document.body.scrollTop
			];
		}
		return position;
	}
	/*
	function getMousePos(e){
		if (!e)
			var e = window.event||window.Event;
		
		source=srcEl = e.srcElement? e.srcElement : e.target;
		if('undefined'!=typeof e.pageX){
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
		else{
			mouseX = e.clientX + document.body.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop;
		}
	}
	// Then assign the mouse handler
	if (document.addEventListener){
		document.addEventListener('mousemove',getMousePos,true);
    }
    else if (document.attachEvent) {
  		document.attachEvent("onmousemove", getMousePos);
    }
    else {                        
 		document.onmousemove = getMousePos;
    }
    */
	function PlayerWindow(url, width, height, win_name) {
		var default_width = 600;
		var default_height = 240;

		if (arguments.length == 1) {
			// We need to use the default width and height
			
			width = default_width;
			height = default_height;
		}
		else if(arguments.length != 4) var win_name = 'JunoRecords';

		var options = 'width=' + width + ',height=' + height + ',toolbar=0,scrollbars=0,resizable=0,location=0';

		window.open('http://' + location.hostname + '/' + url, win_name, options);
		return false;

	}

	function preloadimages(){
		var myimages=new Array();
		for (i=0; i < preloadimages.arguments.length; i++) {
			myimages[i]=new Image();
			myimages[i].src=preloadimages.arguments[i];
		}
	}

	function close_and_go_to(page, new_page) {
		if (new_page === true) {
			// We need to spawn a totally new window for the cart
			// rather that loading it into the old calling frame
			
			// Need to force some options or firefox opens things in tabs.
			window.open(page, '', 'toolbar=1,scrollbars=1,resizable=1,location=1');
		}
		else {
			if(window.opener.opener)
				window.opener.opener.location.href = page;
			else
				window.opener.location.href = page;
		}
		
		window.close();
	}
	function close_and_go_to2(page, new_page) {
		if (new_page === true) {
			// We need to spawn a totally new window for the cart
			// rather that loading it into the old calling frame
			
			// Need to force some options or firefox opens things in tabs.
			window.open(page, '', 'toolbar=1,scrollbars=1,resizable=1,location=1');
		}
		else {
			window.location.replace(page);
				
		}
		
		tb_remove();
	}
	function go_to(page,replace) {
		if(replace === true)
			document.location.replace(page);		
		else
			document.location.href = page;
	}

	function buy_track(id) {
		var sel = document.getElementById('buy_'+id);
		MiniNewWindow('cart/add/?popup=yes&track[]='+id+'-'+sel.options[sel.selectedIndex].value);
		return false;
	}
	
	function cb_submit(obj) {
	    var smt = false;
	    var url = 'cart/addbulk/?popup=yes';
	    var count = 0;
	    
	    for(var i=0;  i<obj.form.elements.length; i++)
		{
		    cb = obj.form.elements[i];
			if(cb.name.substring(0,3)=='cb-' && cb.checked)
			{
				var id = cb.name.replace('cb-','');
				if(sel = document.getElementById('buy_'+id)) {
					id+='-'+sel.options[sel.selectedIndex].value;
				}
			    smt = true;
			    url += '&cb-'+id+'=1';
			    count++;
			}
		}

		if(smt)
		{
		   var val = $(obj).parent().siblings().find('select').val();
		 
			if ( val == 'wl_remove')
			{
		    	obj.form.cb_dropdown.value = val;
		    	obj.form.submit();
				return true;
			}
			else if ( val == 'cart_add' || val == 'cart_move' )
			{
				url += '&cb_dropdown=' + val;
				NewWindow(url,790,150);
      		    obj.blur();
		    	obj.form.reset();
				return true;
			}
		}

		if(!smt)
		{
		    alert("No items were selected!");
		    obj.form.reset();
		}
		else if(val == '-')
		    alert("No option was selected!");

	    window.focus();
	    return false;
	}

	function cb_set(obj) {
		var cb;

		if(obj.name.substring(0,3)=='cb-')
		{
			if(obj.checked==false)
			{
				document.getElementById('cb_all_1').checked = false;
				document.getElementById('cb_all_2').checked = false;
			}
			
			return;
		}	
				
		for(var i=0; i<obj.form.elements.length; i++)
		{
			cb = obj.form.elements[i];
			if(cb.type=='checkbox' && cb.id.substring(0,3)=='cb_')
			    cb.checked = obj.checked;
		}
	}
	
	function set_window() {
		var max_height = 750;
		var max_width  = 730;

		window.resizeTo(max_width, 100);
		var tbl_height = $(document).height()+150;

		if(tbl_height>max_height) 
			tbl_height = max_height;
		window.resizeTo(max_width,tbl_height);
	}

	function drop_down_hide_delay(elementid,protocol) {
		window.clearTimeout(showddID);
		timeoutID = window.setTimeout("drop_down_hide('" + elementid + "','" + protocol + "')", 500);
	}

	function drop_down_hide(elementid,protocol) {
		if($('#'+elementid).is('*')){
			$('#'+elementid).hide(0);
			
			if( $('#navigation_' + elementid).is('*') ) {
				$('#navigation_' + elementid).attr('src', images_dir[elementid][1] );
			}
			
			if(currentoption!="") {
				document.images['navigation_' + currentoption].src=images_dir[currentoption][0];
			}
		}
	}

	function drop_down_show(elementid,protocol) {
		if (currentmenu == elementid) {
			window.clearTimeout(timeoutID);
		}
		showddID = window.setTimeout("do_drop_down_show('" + elementid + "','" + protocol + "')", 300);
	}

	function do_drop_down_show(elementid,protocol) {
		window.clearTimeout(timeoutID);
		window.clearTimeout(showddID);

		currentmenu = elementid;
		
		// hide all other dropdowns
		var elems = ['genres', 'this_week', 'stop_press', 'eight_weeks', 'charts', 'juno_recommends', 'dj_charts', 'all_titles', 'dj_equipment', 'classics_download', 'faq'];
		for(i=0; i<elems.length;i++) {
			if(elementid!=elems[i] && $('#'+elems[i]).is('*')) {
				$('#navigation_' + elems[i]).attr('src', images_dir[elems[i]][1]);
				$('#'+elems[i]).hide(0);
			}
		}

		$('#'+elementid).show(0);

		// if this is a nav dropdown, change the image
		if( $('#navigation_' + elementid).is('*') ) {
			$('#navigation_' + elementid).attr('src', images_dir[elementid][0] );
		}
	}
	
	/* navigation start #8235 point 1 */
	function drop_down_hide_delay_nav(elementid,protocol) {
		window.clearTimeout(showddID);
		timeoutID = window.setTimeout("drop_down_hide_nav('" + elementid + "','" + protocol + "')", 500);
	}

	function drop_down_hide_nav(elementid,protocol) {
		if($('#'+elementid).is('*') && !is_active){
			$('#'+elementid).hide(0);
			
			if( $('#navigation_' + elementid).is('*') ) {
				$('#navigation_' + elementid).attr('src', images_dir[elementid][1] );
			}
			
			if(currentoption!="") {
				document.images['navigation_' + currentoption].src=images_dir[currentoption][0];
			}
		}
	}
	
	function drop_down_show_nav(elementid,protocol) {
		if (currentmenu == elementid) {
			window.clearTimeout(timeoutID);
		}
		showddID = window.setTimeout("do_drop_down_show_nav('" + elementid + "','" + protocol + "')", 300);
	}

	function do_drop_down_show_nav(elementid,protocol) {
		is_active = true;
		window.clearTimeout(timeoutID);
		window.clearTimeout(showddID);

		currentmenu = elementid;
		
		// hide all other dropdowns
		var elems = ['genres', 'this_week', 'stop_press', 'eight_weeks', 'charts', 'juno_recommends', 'dj_charts', 'all_titles', 'dj_equipment', 'classics_download', 'faq'];
		for(i=0; i<elems.length;i++) {
			if(elementid!=elems[i] && $('#'+elems[i]).is('*')) {
				$('#navigation_' + elems[i]).attr('src', images_dir[elems[i]][1]);
				$('#'+elems[i]).hide(0);
			}
		}

		$('#'+elementid).show(0);

		// if this is a nav dropdown, change the image
		if( $('#navigation_' + elementid).is('*') ) {
			$('#navigation_' + elementid).attr('src', images_dir[elementid][0] );
		}
	}
	
	/* navigation ends */

	function textarea_maxsize(te, size) {
		// This is a simple function that allows us to cap the size of
		// a textarea box. Nothing to fancy. It'll just stop people
		// from typing out esseys as Textarea doesn't have a size limit
		// native to it. All we're going to do is check the contents of
		// the text area and lop off any chars over the size stipulated
		// thus giving it the apperance that you can't type any more

		if (te.value.length > size) {
			te.value = te.value.substring(0, size);
		}

		return true;
	}
	
	function digital_release_mask(cb) {
		// This little function is used on the product page. It disables/enables
		// all the individual tracks for a given value (and re-enables them)
		
		// First we need to know what it is that we want to do
		
		var disable = false
		if (cb.checked) {
			disable = true
		}
		
		// Now we need to know for what type product to do it for
		
		var matcher = /-([^-]+)$/
		var result = cb.value.match(matcher)

		if (result != null) {
			//alert("MATCHED -> " + result[1]);
		
			// We've know what resolution we want. Now it's time to find
			// all the right fellas and disable them or something
			
			var matcher2 = new RegExp("-" + result[1] + "$")
			for (i = 0; i < document.tracks_form.length; i++) {
				if (document.tracks_form.elements[i].name == 'track[]') {
					// We only want to mess with the track adding checkboxes
					
					var result2 = document.tracks_form.elements[i].value.match(matcher2)
					if (result2 != null) {
						// This is something we want to play with!
						//alert(document.tracks_form.elements[i].name + " -> " + document.tracks_form.elements[i].value)
						document.tracks_form.elements[i].disabled = disable
					}
				}
			}
		}
	}
	
	function digital_release_add(url) {
		// This function aggregates all the form data supplied to use on the
		// product page and throws it at a popup window. Nothing too complex
		// really
		
		var qs_array = new Array('popup=yes');
		var j = 2;
		var found = false;
		for (i = 0; i < document.tracks_form.length; i++) {
			if (document.tracks_form.elements[i].checked == true) {
				// This is some data that we want to forward on!
				qs_array[j++] = document.tracks_form.elements[i].name + '=' + escape(document.tracks_form.elements[i].value)
				found = true
			}
		}
		
		
		if (found) {
			var qs = qs_array.join('&');
			var full_url = url + '?' + qs;
			//alert(full_url);
			addToCartWindow(full_url);
		}
		else {
			// Better tell the user that they haven't actually selected anything
			// to buy
			
			alert("You must select at least one item to add to your cart");
		}
	}

function chk_mt(fm) {
	cb = false; // tells if at least one checkbox exists
	ch = false; // tells if at least one checkbox is checked
	for(var i=0; i<fm.length; i++) {
		elm = fm.elements[i];
		if(elm.type == 'checkbox' && elm.id.substring(0,3)=='mt_') {
			cb = true;
			if(ch == false)
				ch = elm.checked;
		}
	}
	if(cb==true && ch==false) {
		alert('Please select at least one media format!');
		return false;
	}
	else
		return true;
}
	
/*
	This function gets called when a state is chosen from the drop-down. If the state is FPO or APO it will 
	make the document's fedex box inactive. And add the message that the FedEx delivery is not made to FPO
	or APOs.	
	- nsm 11/10/6
*/	
function fedex_verify() {
	// find out the value of the current drop-down
	// if the value is FPO or APO then dim the fedex box and unhide the span with the red message.
	var state = document.getElementById('STATECOUNTY').value
	
	if ((state == 'FPO') || (state == 'APO')) {
		document.getElementById('FedEx').value = 0;
		document.getElementById('FedEx').disabled = true; 
	} else if (state == '---') {
		alert('Please choose a state');
		document.getElementById('STATECOUNTY').value = '';
	} else {
		document.getElementById('FedEx').disabled = false; 
	}
	return true;
}	

function flash_text(on,count) {
	var ms = 80;
	var num = 8; // Always use an even number!!!

	if(on==1) {
		on = 0;
	    for(var i=0; i<pulse.length; i++) {
	        elm = document.getElementById(pulse[i])
 			elm.style.color = color_on;
		}
	}
	else {
		on = 1;
	    for(var i=0; i<pulse.length; i++) {
	        elm = document.getElementById(pulse[i])
 			elm.style.color = color_off;
		}
	}

	if(count<num) {
		setTimeout('flash_text('+on+','+(++count)+')',ms);
	}
}

function cb_force_select(check_elm, set_elm) {
	var cobj = document.getElementById(check_elm);
	var sobj = document.getElementById(set_elm);
	var fm = cobj.form;
	
	if(cobj.type == 'checkbox' && !cobj.checked){
		sobj.checked = true;
	}
	
	if(check_elm == 'searchfor_music' && !cobj.checked) {
		cobj.form.s_music_product_type[0].disabled = true;
		cobj.form.s_music_product_type[1].disabled = true;
		cobj.form.s_music_product_type[2].disabled = true;
		if(fm.s_media_type) fm.s_media_type.disabled = true;
		document.getElementById('search_item_hint').style.display = 'block';
		if(fm.s_media_type) document.getElementById('media_type_hint').style.display = 'block';
	}
	else {
		cobj.form.s_music_product_type[0].disabled = false;
		cobj.form.s_music_product_type[1].disabled = false;
		cobj.form.s_music_product_type[2].disabled = false;
		if(fm.s_media_type) fm.s_media_type.disabled = false;
		document.getElementById('search_item_hint').style.display = 'none';
		if(fm.media_type) document.getElementById('media_type_hint').style.display = 'none';
	}
	
	if(check_elm == 'searchfor_merchandise' && !cobj.checked) {
		fm.s_merchandise_id.disabled = true;
		document.getElementById('merch_cat_hint').style.display = 'block';
	}
	else {
		fm.s_merchandise_id.disabled = false;
		document.getElementById('merch_cat_hint').style.display = 'none';
	}
}

function checkExpressInstall() {
	var pver = deconcept.SWFObjectUtil.getPlayerVersion();
	return ((pver.major == 6 && pver.rev>=65) || (pver.major>6) );
}	

function zm () {

	$("a").click(function(){
		$(this).hide("slow");
		return false;	
	 });
}

function ajax_login(attr) {
	var data_vars ='';
	var str='';
	$('#ajax_login_form :input').each(function(){
		data_vars += this.name + '=' + (this.checked ? this.checked : this.value) + '&';
	})
//alert(data_vars)		
	attr = typeof attr == 'undefined' ? '' : attr;
	//send an ajax request to login the user
	//var data_vars = 'email=' + $('#ajax_login_email').val() + '&password=' + $('#ajax_login_password').val() + '&redir=' + $('#ajax_login_redir').val() + '&callback=' + $('#ajax_login_callback').val() + '&callbackoptions=' + $('#ajax_login_callbackoptions').val();
	securePopup = window.open('', 'securePopup', 'height=145,width=250,toolbar=0,scrollbars=0,resizable=0,location=0');
	securePopup.document.open("text/html","replace");
	securePopup.document.close();
	$.ajax({
		type:    'POST',
		/*url: 	 'ajax_login.php?type=' + attr,*/
		url: '/api/',
		data:    data_vars,
		dataType:'html',
		error:   function(XHR, textStatus, errorThrown) { return false; },
		success: function(msg) {
		
		var _msg = eval("(" + msg + ")");
		
				// continue to publish chart
				if(_msg.login == 'valid') {

					// remove login box
					tb_remove();
					if(_msg.callback == 'pl_addToWl_Context'){
						return eval(_msg.callback + '(\'' + _msg.callbackoptions + '\')');
					}
					else if(_msg.callback == 'pl_addToWl'){
						return eval(_msg.callback + '(\'' + _msg.redir + '\')');
					}
					else if((typeof _msg.redir || _msg.redir) != 'undefined'){
						
						securePopup.close();
						window.location.replace(_msg.redir);
						
					}
					
					else{	
						window.location.reload();
					}
					// submit the chart form
					if(document.getElementById('chart_details_form')){
						setConfirmUnload(false);
						$('#chart_details_form').submit();
					}

				} else {
					securePopup.close();
					//$('#ajax_login_error_msg').html($('#ajax_login_error_text').html());
					//$('#email').val('');
					$('#ajax_login_password').val('');
				} 
	
			}
	 });

}
function enable_auto_play_chart_player(){
		var _id 		= 'chart_player_textarea'; //id of text box in which to update params
		var _string 	 = $('#' + _id).val();
		var _on 		= "&amp;start_playing=1";
		var _off 		= "&amp;start_playing=0";
		var _checked 	= $('#auto_play_chart_player:checked').val();
		var playlist_url = _string.match(/playlist_url=(.)*?tracks_only/gi);
		var actual_url = playlist_url[0];
			actual_url = actual_url.replace(_on,'')
			actual_url = actual_url.replace(_off,'')
			
			if(_checked =='on'){
				actual_url = actual_url.replace('.xspf','.xspf' + _on)
			}else{
				actual_url = actual_url.replace('.xspf','.xspf' + _off)
			}
			
			actual_url = actual_url;	
			
			$('#' + _id).val(_string.replace(/playlist_url=(.)*?tracks_only/gi,actual_url));
				
}

//shows context menu next to event
function show_pl_chartOptions(e,options,icon,div){
	_icon = $(icon).offset();
	$('#release_pl_cart_cm').hide();
	$('#pl_cart_cm').hide();
	cartContextOptions = options;
	cursor = getPosition(e);
	/*
	 * bind for mouse out
	 */
	$(document).mousemove(function(e){
		_cursor = getPosition(e);
		//alert(parseInt($('#' + div).css("width").replace("px","")) + 10);
		if((_cursor.x < (cursor.x - 7)) ||
			(_cursor.x > (cursor.x + parseInt($('#' + div).css("width").replace("px","")) + 22)) ||
			(_cursor.y < (cursor.y - 7)) || 
			(_cursor.y > (cursor.y + parseInt($('#' + div).css("height").replace("px","")) + 7))			
		){
			$('#' + div).hide();
		}
	});
	
	$('#' + div).css("top", _icon.top +  12);
	$('#' + div).css("left", _icon.left + 12);
	//setTimeout("$('#' + " + div + ").show()",500);
	
	$('#' + div).fadeIn(1000);
}

//hides "context" menu
function hide_lp_cartOptions(div){
	$('#' + div).hide();	
}
//gets cursor position relative to event
function getPosition(e) {    
	e = e || window.event;    
	var cursor = {x:0, y:0}; 
	   
	if (e.pageX || e.pageY) {        
		cursor.x = e.pageX;        
		cursor.y = e.pageY;    
	} else {        
		cursor.x = e.clientX +  (document.documentElement.scrollLeft  ||  document.body.scrollLeft) - document.documentElement.clientLeft;        
		cursor.y = e.clientY +   (document.documentElement.scrollTop  ||  document.body.scrollTop)  - document.documentElement.clientTop;    
	} 
	return cursor;
}
//adds items to charts or wishlist(if logged in)
function pl_addToUser(which){
	
	//chart
	if(which == 'chart'){
		MiniAddWindow('charts/add/?popup=yes&titleid=' +  cartContextOptions[0]  + '&productid=' +cartContextOptions[1] + '&tracknumber=' + cartContextOptions[2]);
	}
	//wishlistf
	else if(which == 'wishlist'){
		MiniAddWindow('wishlist/add/?popup=yes&titleid=' + cartContextOptions[0]+ '&productid=' + cartContextOptions[1]+ '&tracknumber=' + cartContextOptions[2]);
	}
	//wishlistf
	else if(which == 'all_tracks'){
		MiniAddWindow('charts/add/?popup=yes&titleid=' +  cartContextOptions[0]  + '&productid=' +cartContextOptions[1] + '&add_all_tracks=1');
	}
	else if(which == 'add_release'){
		MiniAddWindow('wishlist/add/?popup=yes&titleid=' + cartContextOptions[0]+ '&productid=' + cartContextOptions[1]+ '&tracknumber=');
	}
	else if (which == 'shown_tracks'){
		MiniAddWindow('charts/add/?popup=yes&titleid=' +  cartContextOptions[0]  + '&productid=' +cartContextOptions[1] + '&add_shown_tracks=1');
	}
	cartContextOptions='';
	hide_lp_cartOptions()
}
//adds individual items to cart
function pl_addToCart(options){
		MiniNewWindow('cart/add/?popup=yes&track[]=' + options[0]  + '-' + options[1]  + '-' +  options[2]);

}
/* add to wishlist not logged in
 * on from the context menu
 */
function pl_addToWl_Context(which,popup){

	var _url = '/wishlist/add/' + '?popup=yes&titleid=' + cartContextOptions[0] + '&productid=' + cartContextOptions[1];
	
	if(which == 'add_release'){
		
	}
	else if(which == 'shown_tracks'){
		_url += '&add_shown_tracks=1';
	}
	else{
		_url +=  '&tracknumber=' + cartContextOptions[2];
	}
	 
	if(popup){
			MiniNewWindow(_url);
		}else{
			_url = 'http://' + location.hostname + _url;
			$.ajax({
							type:    'GET',
							url: 	 _url,
							data:    '',
							dataType:'html',
							error:   function(XHR, textStatus, errorThrown) { return false; },
							complete:'',
							success: function(data) {
									data = data.replace('window.close();','window.location.reload();tb_remove();')
									data = data.replace('close_and_go_to','close_and_go_to2')
									$('#TB_ajaxContent').html(data);
								}
			});
	}
	
}
/* add to wishlist -- not context menu
 * 
 */
function pl_addToWl(_data){
	var data = eval("(" + _data + ")");
	
	var _url = data.redir + '&titleid=' + data.titleid + '&productid=' + data.productid;
	if(data.tracknumber){
		_url += '&tracknumber=' + data.tracknumber;
	}
	$.ajax({
					type:    'GET',
					url: 	 _url,
					data:    '',
					dataType:'html',
					error:   function(XHR, textStatus, errorThrown) { return false; },
					complete:'',
					success: function(data) {
							data = data.replace('window.close();','window.location.reload();tb_remove();')
							data = data.replace('close_and_go_to','close_and_go_to2')
							$('#TB_ajaxContent').html(data);
						}
	});
	
}
function show_genre_tracks_help(e){
	cursor = getPosition(e);
	
	$('#show_genre_tracks_help').css("top", cursor.y);
	$('#show_genre_tracks_help').css("left", (cursor.x -  parseInt($('#show_genre_tracks_help').css("width").replace("px","")) - 20));
	$('#show_genre_tracks_help').show();
}
function hide_genre_tracks_help(){
	$('#show_genre_tracks_help').hide();
	
}
function quick_buy_entire_release(options){
	MiniNewWindow('cart/add/?popup=yes&release[]=' + options[0]  + '-' + options[1]  + '-' +  options[2]);
}
function quick_buy_entire_release_prompt(options){
	var r = confirm("This item is not available in WAV format that you have selected, would you like to add this to your cart as a 320 MP3?");
	if(r){
		MiniNewWindow('cart/add/?popup=yes&release[]=' + options[0]  + '-' + options[1]  + '-mp3_192');
	}else{
		return false;
	}
	
}
function ajax_register(){
	$('#ajax_login_form :input').each(function(){
		data_vars += this.name + '=' + (this.checked ? this.checked : this.value) + '&';
	})
	$.ajax({
		type:    'POST',
		url: 	 '/ajax_register.php',
		data:    data_vars,
		dataType:'jsonp',
		jsonp:	 'jsonp_callback',
		error:   function(XHR, textStatus, errorThrown) { return false; },
		success: function(msg) {

				// continue to publish chart
				if(msg.register == 'valid') {

					// remove login box
					tb_remove();

					// submit the chart form
					setConfirmUnload(false);
					$('#chart_details_form').submit();

				} else {

					$('#register_error').html(msg.errors);
				} 
	
			}
	 });

}
function ajax_login_forgotten_pwd(){
		
	return false;	
}
function ajax_get_page(type){
	data_vars = "&method=" +  type + ".getPage";
	$.ajax({
		type:    'GET',
		url: 	 '/api/',
		data:    data_vars,
		dataType:'html',
		error:   function(XHR, textStatus, errorThrown) { return false; },
		success: function(data) {
				$('#TB_ajaxContent').html(data);
			}
	 });
	 return false;
}
function doLoginCallBack(_data){
	var data = eval("(" +_data + ")");
	
	if(data.login == 'valid') {
		// remove login box
		//parent.tb_remove();
		
		
		JUNO_API.User.getFramePage('loading');
		/*
		 * 
		if(JUNO_API.config.data_vars['callback']){
			JUNO_API.config.window['active_name'].focus();
		}
		if(data.callback == 'pl_addToWl_Context'){
				parent.location.replace(data.redir);
				return eval(data.callback + '(\'' + data.callbackoptions + '\')');
			}
			else if(data.callback == 'pl_addToWl'){
				parent.location.replace(data.redir);
				return eval(data.callback + '(\'' + data.redir + '\')');
			}
			else if(data.callback=='setConfirmUnload'){
				JUNO_API.config.window['active_name'].close();
				setConfirmUnload(false);
				$('#chart_details_form').submit();
			}
			else if((typeof data.redir || data.redir) != 'undefined'){
				
			}
			else{
				if(window.opener){	
					parent.location.reload();
				}else{
					window.location.reload();
				}
			}
		*/ 
	} 
	else if(data.login == 'invalid') {//error handling
					
		if(JUNO_API.config.data_vars['callback']){
			if(JUNO_API.config.window['active_name']){
				try{
					JUNO_API.config.window['active_name'].close();
				}catch(e){}
			}
		}
		$('#ajax_login_error_text').fadeOut(300).fadeIn(300);
							
	}
	else if(data.register == 'invalid'){
		if(JUNO_API.config.data_vars['callback']){
			try{
					JUNO_API.config.window['active_name'].close();
				}catch(e){}
		}
		return eval(data.error.callback + '(\'' + _data + '\')');
	}
	else if (data.register == 'valid'){
		//if there is a callback
		if(JUNO_API.config.data_vars['callback']){
			JUNO_API.User.getFramePage('loading'); //note the loading page is the one responsible for subsequent call backs
		}
		else{
			JUNO_API.User.getFramePage('registration_successful');
			reload_open_windows();
			
		}
		
	}
	else if (data.resend_password=='invalid'){
		if(JUNO_API.config.data_vars['callback']){
			JUNO_API.config.window['active_name'].close();
		}
	return eval(data.error.callback + '(\'' + _data + '\')');
	}
	else if(data.resend_password == 'valid'){
		JUNO_API.User.getFramePage('forgotten_password_success');
		
	}
	
}
//error handling
function register_cb(_data){
	var data = eval("(" +_data + ")");
	error_divs = ['ajax_invalid_email_error_text','ajax_password_short','ajax_password_mismatch'];
	for(var i in error_divs){
		$('#' + error_divs[i]).css("visibility","hidden");
		$('#' + error_divs[i]).css("display","none");
	}
	var str = '';
	var register_error = false;
	//email already in use
	if(data.error.already_email){
		$('#ajax_already_email_error').fadeOut(300).fadeIn(300);
		$('#ajax_invalid_email_error').css('display','none');
		register_error = true;
	}else{
		$('#ajax_already_email_error').hide();
	}
	if(data.error.invalid_email){
		$('#ajax_already_email_error').css("display","none");
		$('#ajax_invalid_email_error').fadeOut(300).fadeIn(300);
		register_error = true;	
	}
	
	
	if(data.error.password_short){
		$('#ajax_password_short').css("visibility","visible").fadeOut(300).fadeIn(300);
		register_error = true;
	}
	if(data.error.password_mismatch){
		$('#ajax_password_mismatch').css("visibility","visible").fadeOut(300).fadeIn(300);
		register_error = true;
	}
	
	//else successful registration
	if(!register_error)
	JUNO_API.User.getFramePage('registration_successful');
	
}
function resend_password_cb(_data){
	var data = eval("(" +_data + ")");
	error_divs = ['ajax_emptyemail_error','ajax_invalidemail_error','ajax_noemail_error'];
	for(var i in error_divs){
		$('#' + error_divs[i]).css("display","none");
	}

	if(data.error.empty_email){
		//$('#ajax_invalidemail_error').css('display','block');
		$('#ajax_invalidemail_error').fadeOut(300).fadeIn(300);
	}
	else if(data.error.no_email){
		//$('#ajax_noemail_error').css('display','block');
		$('#ajax_noemail_error').fadeOut(300).fadeIn(300);
	}
	else if(data.error.invalid_email){
		//$('#ajax_emptyemail_error').css('display','block');
		$('#ajax_emptyemail_error').fadeOut(300).fadeIn(300);
	}
}
function publish_chart_cb(){
	tb_remove();
	setConfirmUnload(false);
	$('#chart_details_form').submit();
}

function redeem_voucher_cb(_data){
	var data = eval("(" +_data + ")");
	var _url = null;
	
	//attempt to make parent window logged in if viewing alerts from ppps window.
	if(window.opener){
		if(parent.parent){
			parent.opener.location.reload();
		}
		else{
			parent.location.replace(parent.location.href);
		}
	}
	
	if(JUNO_API.User.is_secure_url(document.location.href)){
		if(JUNO_API.User.is_secure_url(data.redir)){
			_url = data.redir;
		}
		else{
			_url = data.redir.replace('https','http');
		} 
	} else {
		if(JUNO_API.User.is_secure_url(data.redir)){
			_url = data.redir.replace('https','http'); 
		}
		else{
			_url = data.redir;
		}
	}
	$.ajax({
		type:   'GET',
		url: 	_url,
		data:    '',
		dataType:'html',
		error:   function(XHR, textStatus, errorThrown) { return false; },
		complete:'',
		success: function(data) {
			data = data.replace('window.close();','window.location.href='/';tb_remove();')
			$('#TB_ajaxContent').html(data);
			return false;
		}
	});
}

function getPlayer() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
             player =  window['junoplayer'];
    } else {
             player =  document['junoplayer'];
    }
    if(typeof(player) == 'undefined') return;
    if(player.length > 1){
    	player = player[0];
    }
    return player;
}

function playPlayer(){
	player = getPlayer();
	if(player) {
		player.play();
	}
}

function pausePlayer(){
	player = getPlayer();
	if(player) {
		player.pause();
	}
}

function doAddItemToPlayer(anchor_href, is_release, is_cued){
	player = getPlayer();
	
	if(player) {
		player.addProduct(hash, product_key, is_release, is_cued);
	}
}

function processAlerts(_data){
	var data = eval("(" +_data + ")");
	var _url = null;
	
	//attempt to make parent window logged in if viewing alerts from ppps window.
	reload_open_windows();
	
	if(JUNO_API.User.is_secure_url(document.location.href)){
		if(JUNO_API.User.is_secure_url(data.redir)){
		 _url = data.redir;
		}
		else{
			 _url = data.redir.replace('https','http');
		} 
	}else{
		
		if(JUNO_API.User.is_secure_url(data.redir)){
			_url = data.redir.replace('https','http'); 
		}
		else{
			_url = data.redir;
		}
	}

	$.ajax({
					type:    'GET',
					url: 	_url,
					data:    '',
					dataType:'html',
					error:   function(XHR, textStatus, errorThrown) { return false; },
					complete:'',
					success: function(data) {
							data = data.replace('window.close();','window.location.reload();tb_remove();')
							data = data.replace('close_and_go_to','close_and_go_to2')
							data = data.replace('&popup=yes','')
							$('#TB_ajaxContent').html(data);
							return false;
						}
	});
}

function junoCompatBrowser(){
		//safari
		var safari = /safari/.test(navigator.userAgent.toLowerCase()) && !/chrome/.test(navigator.userAgent.toLowerCase());
		if(safari){
			var tmp =  navigator.userAgent.toLowerCase().split(' ');
			for (var i in tmp){
					if(tmp[i].substr(0,7) == 'version'){
						_tmp = tmp[i].split('/');
						version = _tmp[1];
						if(parseFloat(version) >= 4){
							return true;
						}
						return false
					}
				}
		}
		//opera
		if($.browser.opera) return false;
		 
		return true;	
}


/* start of active records highlight */

$(document).ready(function(){

	var is_msie      = $.browser.msie;
	var is_opera      = window.opera?1:0;
	if(!is_msie && !is_opera) {
		//$('.dropdown_genre').corner("bottom 5px");
	}
	
	$('.dropdown_genre').mouseout(function () {
		is_active = false;
	});
	$('.dropdown_genre').mouseover(function () {
		is_active = true;
	});
	
	$(".sub_menu").mouseout(function () {
		$(this).removeClass("sub_menu_active");
	});
	
	$(".sub_menu").mouseover(function () {
		$(this).addClass("sub_menu_active");
		if(!msie) {
			$('.sub_menu').corner("2px");
		}
	});
	
	$(".menu_group_inner").mouseout(function () {
		var id = $(this).attr("id");
		var htmlvalue = $(this).text();
		var link = $(this).attr("link");
		if(link) {
			$(this).removeClass("menu_active");
		}
	});
	
	$(".menu_group_inner").mouseover(function () {
		var id = $(this).attr("id");
		var htmlvalue = $(this).text();
		var link = $(this).attr("link");
		
//		alert(link);
		if(link) {
			$(this).addClass("menu_active");
			is_active = true;
			if(!msie) {
				$('.menu_group_inner').corner("2px");
			}
		}
		
	});
	
});

/* end of active records highlight */

//after login all popups and parent windows need reloading
function reload_open_windows(){
	//reload popups
	if(window.opener){
		if(parent.parent){
			parent.opener.location.reload();
			//parent.location.reload();
		}
		else{
			parent.location.replace(parent.location.href);
		}
	}
}
