/* NuYoung - Roneri 2009 | JQUERY ADDRESS |*/// navegation
/*<![CDATA[*/
$(document).ready(function() {
	
	function log() {
		if (window.console && window.console.log)
			window.console.log( Array.prototype.join.call(arguments,' '));
	};
	
	$.ajax({ 
	url:"js/jcycle.js"
	,dataType:"script"
	,cache: true
	,contentType:"utf-8"
	,success  : function(){
			$('#pratosDestake').cycle({
				fx:     'scrollRight'
				,timeout:  18000
			});
		}
	});
						   
	$.ajax({ 
		url:"js/jquery.easing.1.3.js"
		,dataType:"script"
		,cache: true
		,success  : function(){				   
			var style = 'easeOutBounce';
			var timed = 1000;
			var distance = 70;
			
			var default_left = Math.round($('.menu li.selected').offset().left - $('.menu').offset().left);
			var default_width = $('li.selected').width()+distance;
			$('#box').css({left: default_left});
			$('#box .head').css({width: default_width});
		
			$('.menu li').hover(function () {
				left = Math.round($(this).offset().left - $('.menu').offset().left);
				width = $(this).width() + distance;
				$('#box').stop(false, true).animate({left: left},{duration:timed, easing: style});	
				$('#box .head').stop(false, true).animate({width:width},{duration:timed, easing: style});	
			}).click(function () {
				$('.menu li').removeClass('selected');	
				$(this).addClass('selected');
			});
			
			$('.menu').mouseleave(function () {
				default_left = Math.round($('.menu li.selected').offset().left - $('.menu').offset().left);
				default_width = $('.menu li.selected').width() + distance;
				$('#box').stop(false, true).animate({left: default_left},{duration:timed, easing: style});	
				$('#box .head').stop(false, true).animate({width:default_width},{duration:timed, easing: style});		
			});
		}
	});
	$.ajax({ 
		url:"js/jquery.cacheimage.js"
		,dataType:"script"
		,cache: true
		,contentType:"utf-8"
		,success  : function(){
			var image  = $('#img_topo');
			image.hide();
			image.attr( 'src', image.attr('src') );
			image.cacheImage({
				load: function () {
					
					image.show();
					$("#slideshow").append('<div class="prato"><img src="images/home_fidel_2.jpg" alt="Cardápio Especial Fidel" /><div class="descricao"><strong>Lagosta do chef.</strong><br />Lagosta flambada com taglierini negro de tinta de lula, creme de alho poro, manteiga trufada.</div></div>'+
				   +'<div class="prato"><img src="images/home_fidel_3.jpg" alt="Cardápio Especial Fidel" /><div class="descricao"><strong>Tagliatelli com camarão.</strong><br />Massa fresca com camarões grelhados, ao creme de açafrão, shitake, primenta rosa e azeite.</div></div>'+
				   +'<div class="prato"><img src="images/home_fidel_4.jpg" alt="Cardápio Especial Fidel" /><div class="descricao"><strong>Filet Aceto de Modena.</strong><br />Filet mignon flambado ao balsmico, rucula e risoto de parmesão.</div></div>');
							
					$('#slideshow').cycle({
						fx:     'fade'
						,timeout:  13000
						,before:   onBefore
						,after:   onAfter
					});
					
					function onBefore(curr, next, opts) { 
						$('.descricao').animate({ bottom:'-80px' }, 1200);
					}; 
					function onAfter(curr, next, opts, fwd) {
						setTimeout(function(){$('.descricao').animate({ bottom:'40px' }, 1200)}, 2000);
					}
					
				}
			})
		}
	});
	
	
	$.address.init(function(event) {
		$('.menu li[title!=' + event.value + ']').removeClass('selected');
		$('.menu li[title*=' + event.value + ']').addClass('selected');
	}).change(function(event) {
		var text = (event.value == '/') ? 'Home' : 
		event.pathNames[0].substr(0, 1).toUpperCase() + 
		event.pathNames[0].substr(1);
		
		if (text=='Localização'){
			pagina = 'Localizacao'
		}else{
			pagina = text;	
		}
		if (text=='Contato'){
			$('#Imprensa[title*=back]').animate({ top:'0px' }, 1400, function() {
				$('#Imprensa').removeAttr("title")
			});
			$('#pratosDestake[title*=front]').animate({ top:'156px' }, 1400, function() {
				$('#pratosDestake').removeAttr("title")
			});
		}else{
			$('#Imprensa[title!=back]').animate({ top:'-156px' }, 1400, function() {
				$('#Imprensa').attr('title', 'back');
			});
			$('#pratosDestake[title!=front]').animate({ top:'0px' }, 1400, function() {
				$('#pratosDestake').attr('title', 'front');
			});
		}
		
			$.ajax({
				url: pagina +'.php'
				,data: $.address.queryString()
				,cache: false
				,beforeSend : function(){
					$('.loader').fadeIn('fast');
				}
				,success  : function(data){
					$(".corpo").html(data);
					$.ajax({
						url: pagina +'.js'
						,cache: true
						,contentType: 'iso-8859-1'
						,dataType: 'script'
					})
				}
			})
		
		$.address.title($.address.title().split(' | ')[0] + ' | ' + text);
	});

	$.ajax({ 
		url:"js/jquery.jplayer.min.js"
		,dataType:"script"
		,cache: true
		,success  : function(){
			$("#jquery_jplayer").jPlayer({
				ready: function () {
					this.element.jPlayer("setFile", "gentlyloop.mp3").jPlayer("play");
				},
				volume: 100
			})
			.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
				if ($.jPlayer.convertTime(playedTime) == '00:45'){
					$("#jquery_jplayer").jPlayer("stop");
					$("#jquery_jplayer").jPlayer("play");
				}
			})
		}
	});
	
	$('#soundVol').bind('click', function() {
		if($('#soundVol').html() == "Desligar som"){
			$("#jquery_jplayer").jPlayer("stop");
			$('#soundVol').html("Ligar som")
		}else{
			$("#jquery_jplayer").jPlayer("play");
			$('#soundVol').html("Desligar som")
		}
	});


});			
	/*]]>*/