var spkTimer;
function animatespeaker(){
	//var time = (Math.floor(Math.random()*300));
	$(".speaker").css({backgroundPosition: '100% 100%'});
	clearTimeout(spkTimer);
	spkTimer=setTimeout("animatespeaker2()",100); 
	}
function animatespeaker2(){
	//var time = (Math.floor(Math.random()*300));
	$(".speaker").css({backgroundPosition: '0% 0%'});
	clearTimeout(spkTimer);
	spkTimer=setTimeout("animatespeaker()",220); 
	}
function fadespeaker(){
	if ($.support.opacity) {
		$(".speaker").animate({"opacity": 'hide'},300, function(){$(".speaker").remove();});
	} else {
		$(".speaker").remove();		
	}
	}
function changespeaker(obj){
	if ($.support.opacity) {
		$(".speaker").stop(true, true);//remove();
		$(obj).after('<div class="speaker"></div>');
		$(".speaker").animate({"opacity": 'show'},200);	
	} else {
		$(".speaker").remove();
		$(obj).after('<div class="speaker"></div>');
		$(".speaker").show();	
	}

	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
	} else {
		animatespeaker();
	}
	}


$(document).ready(function(){

	$("#jquery_jplayer").jPlayer({
		ready: function () {
			//playTrack("/inc/mp3/krila.mp3",$("#play_krila").text());
			//demoInstanceInfo(this.element, $("#demo_info")); // This displays information about jPlayer's configuration in the demo page
		},
		customCssIds: true,
		//nativeSupport: false,
		swfPath: "/inc/js/jqPlayer/"
	})
	.jPlayer("onProgressChange", function(lp,ppr,ppa,pt,tt) {
 		$("#pcent").text(parseInt(ppa)+"%");
	});
 
 
 
 
	$("#pause").hide();
 
	function showPauseBtn()
	{
		$("#play").fadeOut(function(){
			$("#pause").fadeIn();
		});
	}
 
	function showPlayBtn()
	{
		$("#pause").fadeOut(function(){
			$("#play").fadeIn();
		});
	}
 
	function playTrack(t,n)
	{
		$("#jquery_jplayer").jPlayer("setFile", t).jPlayer("play");
		showPauseBtn();
 
		$("#trackname").fadeOut(function(){
			$("#trackname").text(n);
			$("#trackname").fadeIn();
		});
 
		$("#pcent").fadeOut(function(){
			$("#pcent").fadeIn();
		});
 
		return false;
	}
 

	$("#play_krila").click(function() {
		$("#jquery_jplayer").jPlayer("stop");							   
fadespeaker();
		$(this).toggleClass("active");
		if (!$(this).hasClass("active")) {
			return false;
		} else {
			$(".pjesmatools .li.active").removeClass('active');
			$(this).toggleClass("active");
changespeaker(this);
	 		return(playTrack("/inc/mp3/DavidiaN-Krila.mp3",$("#play_krila").text()));
		}
	});
	
 	$("#play_andjeo13").click(function() {
		$("#jquery_jplayer").jPlayer("stop");							   
fadespeaker();
		$(this).toggleClass("active");
		if (!$(this).hasClass("active")) {	
			return false;
		} else {
			$(".pjesmatools .li.active").removeClass('active');
			$(this).toggleClass("active");
changespeaker(this);
	 		return(playTrack("/inc/mp3/DavidiaN-Andjeo13.mp3",$("#play_andjeo13").text()));
		}
	});
	
 	$("#play_drvenivojnik").click(function() {
		$("#jquery_jplayer").jPlayer("stop");							   
fadespeaker();
		$(this).toggleClass("active");
		if (!$(this).hasClass("active")) {
			return false;
		} else {
			$(".pjesmatools .li.active").removeClass('active');
			$(this).toggleClass("active");
changespeaker(this);
	 		return(playTrack("/inc/mp3/DavidiaN-DrveniVojnik.mp3",$("#play_drvenivojnik").text()));
		}
	});
 	$("#play_pustime").click(function() {
		$("#jquery_jplayer").jPlayer("stop");							   
fadespeaker();
		$(this).toggleClass("active");
		if (!$(this).hasClass("active")) {
			return false;
		} else {
			$(".pjesmatools .li.active").removeClass('active');
			$(this).toggleClass("active");
changespeaker(this);
	 		return(playTrack("/inc/mp3/DavidiaN-PustiMe.mp3",$("#play_pustime").text()));
		}
	});
 
 
/* 
	$("#lismore").click(function() {
		return(playTrack("http://www.miaowmusic.com/mp3/Miaow-04-Lismore.mp3",$("#lismore").text()));
	});
 
	$("#thinice").click(function() {
		return(playTrack("http://www.miaowmusic.com/mp3/Miaow-10-Thin-ice.mp3",$("#thinice").text()));
	});
 */
 
	$("#play").click(function() {
		$("#jquery_jplayer").jPlayer("play");
		showPauseBtn();
		return false;
	});
 
	$("#pause").click(function() {
		$("#jquery_jplayer").jPlayer("pause");
		showPlayBtn();
		return false;
	});
 
	$("#stop").click(function() {
		$("#jquery_jplayer").jPlayer("stop");
		showPlayBtn();
		return false;
	});
 
	$("#vmax").click(function() {
		$("#jquery_jplayer").jPlayer("volume", 100);
		return false;
	});
 
	$("#vmute").click(function() {
		$("#jquery_jplayer").jPlayer("volume", 0);
		return false;
	});
 
	$("#vhalf").click(function() {
		$("#jquery_jplayer").jPlayer("volume", 50);
		return false;
	});
 
});