
var siteAjaxed = false;


function open_player(address)
{	
	window.open('/player/?adr=' + address,'mp3_web_player', 'toolbar=0,menubar=0,location=no,directories=no,scrollbars=no,resizable=yes,status=no,width=320,height=400,top=0,left=0');
	return false;
}

function pageload(hash) {
	if(hash) {
		$.getJSON(hash, function(json) {
			
			for (var i in json) {
				$('#' + i).empty().html(json[i]);
				$('#' + i + ' a').not('.noAjax').each(function(){
					if ($(this).closest('.noAjax').size()) return;
					$(this).attr('href', '#' + $(this).attr('href'));
				});
			}
			
			$('head meta[name="scriptsPlaceholder"]').nextAll().remove();
			$('head').append(json.headScript);
			$('head').append(json.headLink);
			document.title = json.headTitle;
		});
	} 
}


$(document).ready(function(){
	//ajax content
	if (siteAjaxed) {
		$.historyInit(pageload);
		$('a').not('.noAjax').each(function(){
			if ($(this).closest('.noAjax').size()) return;
			$(this).attr('href', '#' + $(this).attr('href'));
		});
		$('a').live('click', function(){
			if ($(this).hasClass('.noAjax')) return true;
			if ($(this).closest('.noAjax').size()) return true;
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});
	}
	 $("#ajaxLoader").ajaxStart(function(){
		$(this).show();
	 }). ajaxStop(function(){
		   $(this).hide();
	 }).css('opacity', '0.5');
	 
	 //mp3 player
	 $("a.showPlayer").live('click', function(){
		 open_player($(this).attr('href'));
		 return false;
	 });
	 
	 //search
	 $('#releaseIndexForm').live('submit', function(){
		 var dest  = this.action + '/hledat/' +  $("input:text[name='search']", this).val();
		 var searchType = $("#searchType option:selected").val();
		 dest += '/typ-hledani/' + searchType;
		 if (siteAjaxed) {
			 $.historyLoad(dest);
		 } else {
			 window.location = dest;
		 }
		 return false;
		 
	 });
	 
	 $('.filters select').live('change', function(){
		 var dest = $(this).val();
		 if (siteAjaxed) {
			 $.historyLoad(dest);
		 } else {
			 window.location = dest;
		 }
	 });
});



