var move=0;
var page_height=0;
var page_scroll=0;
var inner_height=window.innerHeight-116;

function lookup(inputString) {
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $("#suggestions").hide();
    } else {
        $.post("http://localhost/Musique/web/frontend_dev.php/findcity", {queryString: ""+inputString+""}, function(data){
            if(data.length >0) {
                $("#suggestions").show();
                $("#autoSuggestionsList").html(data);
				$(".suggestionList li").click(
						function(e) {
							var ville=$(this).html();
							 $("#inputVille").val(ville);
						});
            }
        });
    }
} // lookup

function getpx(val){
	return parseInt(val.substring(0,val.length()-2));
}

function loadSong(titre,filename){
	$('#song_title').html(titre);
	$('#jquery_jplayer').setFile("music/"+filename,"").play();
}

function demoInstanceInfo(myPlayer, myInfo) {
	 var jPlayerInfo = "<p>This jPlayer instance is running in your browser using ";
	 if(myPlayer.jPlayerGetInfo("html5")) {
	 jPlayerInfo += "<strong>HTML5</strong> with ";
	 if(myPlayer.jPlayerGetInfo("canPlayOGG")) {
	 jPlayerInfo += "<strong>OGG</strong>";
	 } else {
	 jPlayerInfo += "<strong>MP3</strong>";
	 }
	 } else {
	 jPlayerInfo += "<strong>Flash</strong> with <strong>MP3</strong>";
	 }
	 jPlayerInfo += " files.<br />This instance has the constructor option ";
	 if(myPlayer.jPlayerGetInfo("oggSupport")) {
	 jPlayerInfo += "set to <code>$(\"#jpId\").jPlayer({oggSupport: true})</code>";
	 } else {
	 jPlayerInfo += "defaulting to <code>$(\"#jpId\").jPlayer({oggSupport: false})</code>";
	 }
	 jPlayerInfo += "</p>";
	 myInfo.html(jPlayerInfo);
	} 

$(document).ready(function() {
	
	$("#menu a").mouseover(
			function(e) {
				if(move==0){
					move=1;
					$("#menu_note").css('top',(this.offsetTop+144)+'px')
								   .css('left','0px')
								   .animate({left:'266px'},532,function(){move=0;});
			    }
			}
			);
	
	$("#menu a").click(
			function(e) {
				//$("#central").load('http://localhost/Wesley/www/index.php/page/'+$(this).attr('id'), {page : $(this).attr('id')});
				if($(this).attr('id')!='members')
					link='index.php/page/'+$(this).attr('id');
				else
					link='index.php/members';
						
					$("#central").load(link, {page : $(this).attr('id')},
							function(){
										page_height=$("#central div").height();
										page_scroll=0;
										$("#central").animate({top:'116px'},1);
										});
				return false;
			});
	
	$("#publi_send").click(
			function(e) {
				$.post('http://wesley-choir.com/publish', {msg : $('#whatnews').attr('value'), userid : $('#userid').attr('value') })
			});
	
	$("#go_recrutement").click(
			function(e) {
				$("#central").load('index.php/page/recrutement', {page : 'recrutement'},
							function(){
										page_height=$("#central div").height();
										page_scroll=0;
										$("#central").animate({top:'116px'},1);
										});
				
			});
	
	$("#page_up").click(
			function(e){
				
				if(page_scroll>0)
				$("#central").animate({top:'+='+inner_height},700,function(){page_scroll-=inner_height;});
			});
	$("#page_down").click(
			function(e) {
				if(page_scroll+inner_height<page_height && page_height>inner_height)
				$("#central").animate({top:'-='+inner_height},700,function(){page_scroll+=inner_height;});
			});
	
	$('#song_title').html('Go lovely Rose - Hasley Stevens');
	$("#jquery_jplayer").jPlayer({
		ready: function () {
		$(this).setFile("music/golovelyrose.mp3","").play();
		
		},
		cssPrefix: "different_prefix_example",
		volume: 50,
		oggSupport:false
	})
	.jPlayerId("play", "player_play")
	.jPlayerId("pause", "player_pause")
	.jPlayerId("stop", "player_stop")
	.jPlayerId("loadBar", "player_progress_load_bar")
	.jPlayerId("playBar", "player_progress_play_bar")
	.jPlayerId("volumeMin", "player_volume_min")
	.jPlayerId("volumeMax", "player_volume_max")
	.jPlayerId("volumeBar", "player_volume_bar")
	.jPlayerId("volumeBarValue", "player_volume_bar_value")
	.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		var myPlayedTime = new Date(playedTime);
		var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
		var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
		$("#play_time").text(ptMin+":"+ptSec);

		var myTotalTime = new Date(totalTime);
		var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
		var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
		$("#total_time").text(ttMin+":"+ttSec);
	})
	.onSoundComplete( function() {
		$(this).play();
	});
	
	$("#player_volume_up").click(function() {
		volumeValue+=5;
		//$("#jquery_jplayer").jPlayer("volume", volumeValue);

		
	});

	$("#player_volume_down").click(function() {
		volumeValue-=5;
		//$("#jquery_jplayer").jPlayer("volume", volumeValue);
	});
});
