
$(document).ready(function(){
						   
		
		
		//$('ul.sf-menu').superfish({
//								  
//			hoverClass:    'sfHover',          // the class applied to hovered list items 
//			pathClass:     'current', // the class you have applied to list items that lead to the current page 
//			pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
//			delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
//			animation:     {opacity:'show', height:"show"},   // an object equivalent to first parameter of jQuery’s .animate() method 
//			speed:         200,           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
//			autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
//			dropShadows:   true,               // completely disable drop shadows by setting this to false 
//			disableHI:     false,              // set to true to disable hoverIntent detection 
//			onInit:        function(){},       // callback function fires once Superfish is initialised – 'this' is the containing ul 
//			onBeforeShow:  function(){},       // callback function fires just before reveal animation begins – 'this' is the ul about to open 
//			onShow:        function(){},       // callback function fires once reveal animation completed – 'this' is the opened ul 
//			onHide:        function(){}        // callback function fires after a sub-menu has closed – 'this' is the ul that just closed 
//					  
//		}); 
		
		$("#agenda").click(function(){
			$(this).find("a").trigger("click");					
		});
		
		$("#klikpad li a").append(" - ");	
		
		
		$("div.playlist-wrapper").append("<ul></ul>");			
		$.get("/lib/audio/xspf.xml",{},function(xml){			
			$("track",xml).each(function(i){							  
					var title = $(this).find("title").text();	
					$("div.playlist-wrapper ul").append("<li>"+title+"</li>");							  
			});			
		});
		
		$("div.playlist-wrapper ul").hide();
		$("div.playlist-wrapper ul li").live("mouseover", function(){
			$(this).addClass("hilite");
		});
		$("div.playlist-wrapper ul li").live("mouseout", function(){
			$(this).removeClass("hilite");
		});
		
		
		$("#audioplayer #play-btn").click(function(e){					
			if($(this).hasClass("playing")){				
				if (winRef && ! winRef.closed){					
					winRef.player.sendEvent("PLAY", "false");					
					$(this).removeClass("playing");
				}else {			
					openAudioPlayer();					
					$(this).addClass("playing");
				}				
			}else{
				if (winRef && ! winRef.closed){						
					winRef.player.sendEvent("PLAY","true");						
					$(this).addClass("playing");
				}else {			
					openAudioPlayer();				
					$(this).addClass("playing");
				}	
			}
			e.preventDefault();
		});
		
		
		$("#audioplayer #next-btn").click(function(e){						
			if (winRef && ! winRef.closed){				
				winRef.player.sendEvent("NEXT","true");	
			}else {			
				openAudioPlayer();
			}		
			e.preventDefault();
		});			
		
		var selStatus=false;				
		$("div.playlist-wrapper #selected-song").click(function(e){
			if(!selStatus){	
				var theList = $(this).siblings("ul")
				theList.slideDown(800);
				
				$("body").bind('click', function(){
					theList.slideUp(100);
					selStatus = false;
					$("body").unbind('click');								 
				});
				
				selStatus = true;
			}else{
				$(this).siblings("ul").slideUp(200);
				selStatus = false;
			}
			e.stopPropagation();
		});
		
		
		defText = $("#selected-song").html();
		$("div.playlist-wrapper ul li").live("click", function(e){
			var selection = $(this).text();			
			$("#selected-song").html(selection);
			
			var songIndex = $("div.playlist-wrapper ul li").index(this);
			
			if (winRef && ! winRef.closed){	
				$("#audioplayer #play-btn").addClass("playing");
				winRef.player.sendEvent("ITEM",songIndex);					
			}else{
				openAudioPlayer();
				$("#audioplayer #play-btn").addClass("playing");
				setTimeout(function(){winRef.player.sendEvent("ITEM",songIndex);},500);					
			}
			
			$(this).parent().slideUp(200);
			selStatus = false;
			$("body").unbind('click');														  
		});
		
		
		
   
});


window.onunload = function(){
	if (winRef && ! winRef.closed){	
		winRef.parentUnloads(winRef);
	}
};

var defText;
var winRef;	

function windowClosed(){
	$("#audioplayer #play-btn").removeClass("playing");
	$("#selected-song").html(defText);
	playing=false;
}

function setPlayingSong(title){
	$("#selected-song").html(title);
}

function setPlayingState(playing){
	if(playing){
		$("#audioplayer #play-btn").addClass("playing");
	}else{
		$("#audioplayer #play-btn").removeClass("playing");
	}
}

function openAudioPlayer(){
	var specs = "width=310,height=280,directories=no,fullscreen=no,left=0,top=0,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no";
	winRef = window.open("","audioplayer",specs,false);
	
	
	if(winRef.location == "about:blank"){
		winRef.location="/audioplayer.htm";	
	}
	
	winRef.opener.focus();
}

function setPlayerState(ref, stat, itm){
	
	winRef=ref;
	
	if(stat){
		$("#audioplayer #play-btn").addClass("playing");
	}else{
		$("#audioplayer #play-btn").removeClass("playing");
	}
	
	$("#selected-song").html(itm);
	
}

function rndBackground() {	
	var randomnumber=Math.floor(Math.random()*1)+'';	
	$('body').addClass('img-'+randomnumber);
}

$(document).ready(function() {
						   
	rndBackground();
	
	
});