var currentTrack = 0;
var firstLoad = true;
(function($) {
		$.fn.customFadeIn = function(speed, callback) {
			$(this).fadeIn(speed, function() {
				if(jQuery.browser.msie)
					$(this).get(0).style.removeAttribute('filter');
				if(callback != undefined)
					callback();
			});
		};
		$.fn.customFadeOut = function(speed, callback) {
			$(this).fadeOut(speed, function() {
				if(jQuery.browser.msie)
					$(this).get(0).style.removeAttribute('filter');
				if(callback != undefined)
					callback();
			});
		};
	})(jQuery);

$(document).ready(function(){

$("a[rel=lightbox-gal]").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titlePosition' 	: 'over',
				'overlayColor'		: '#fff',
				'overlayOpacity'	: 0.8,
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

$("a.lb-letras").click(function() {
	var url = $(this).attr("href");
		$.fancybox({
			'type' : 'iframe',
			'href' : url,
			'width': 450,
			'height': 460,
			'transitionIn'	:	'fade',
			'transitionOut'	:	'fade',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'overlayColor'		: '#fff',
			'scrolling'		: 'auto',
			'titleShow'		: false,
			'hideOnContentClick' : false
		});
	return false;
});


$('#susana img').hide();
$('#susana img').imagesLoaded(function () {$(this).fadeIn(500, 'swing');});



/*$('.lermais a:not(.selected)').live('mouseover mouseout', function(event) {
  if (event.type == 'mouseover') {
    $(this).stop().animate({backgroundColor: '#89898a'}, 300);
  } else {
    $(this).stop().animate({backgroundColor: '#a61c20'}, 300);
  }
});*/

$('#discografia li a').live('mouseenter mouseleave', function(event) {
  if (event.type == 'mouseenter') {
    $(this).children('.bg').stop(true,true).fadeTo(200, 0.7, 'swing');
	$(this).children('.slide').css( {'marginTop': "-5px"} ).stop(true,true).animate({"marginTop": "0px", "opacity": "toggle"}, 200);
  } else {
    $(this).children('.bg').stop(true,true).fadeTo(400, 0, 'swing');
	$(this).children('.slide').stop(true,true).animate({"marginTop": "10px", "opacity": "toggle"}, 600);
  }
});

/*$('.ver_album a, .albuns li img, .fotos li img').live('mouseenter mouseleave', function(event) {
  if (event.type == 'mouseenter') {
	  if($(this).parent().hasClass('ver_album')){
		$(this).parent().parent().find('img').stop(true,true).animate({"opacity": 1}, 500);
		$(this).stop().animate({backgroundColor: '#89898a'}, 300);
	  }else{
		$(this).stop(true,true).animate({"opacity": 1}, 500);
		$(this).parent().parent().find('.ver_album a').stop().animate({backgroundColor: '#89898a'}, 300);
	  }
  } else {
	  if($(this).parent().hasClass('ver_album')){
    	$(this).parent().parent().find('img').stop(true,true).animate({"opacity": .6}, 600);
		$(this).stop().animate({backgroundColor: '#a61c20'}, 300);
	}else{
		$(this).stop(true,true).animate({"opacity": .6}, 600);
		$(this).parent().parent().find('.ver_album a').stop().animate({backgroundColor: '#a61c20'}, 300);
	  }
  }
});*/
$(".lupa img").live('mouseenter mouseleave', function(event) {
	if (event.type == 'mouseenter') {							  
		$(this).stop().animate({
		opacity: .30
		}, 300);
	}else{		
		$(this).stop().animate({
		opacity: 1.0
		}, 600);
	}
	}); 


$('#menu a:not(.activo)').css({backgroundPosition: '100% 35px'}).live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).stop().animate({color: '#7ea831',backgroundPosition:"(100% 0px)"}, 300);
		} else {
			$(this).stop().animate({color: '#000000',backgroundPosition:"(100% 35px)"}, 200);
		}
});

$('.pt:not(.selected_lang), .en:not(.selected_lang)').css({backgroundPosition: '0 0'}).mouseover(function(){
		$(this).stop().animate({
			backgroundPosition:"(0 -18px)"
			}, 200)}).mouseout(function(){
		$(this).stop().animate({
			backgroundPosition:"(0 0)"
			}, 200)});





	$("#jquery_jplayer").jPlayer({
		swfPath: '/inc/jplayer/',
		supplied: "mp3",
		ready: function() {			
			playListChange(currentTrack);
		},
		ended: function (event) {
			playListNext();
		}
	});

	
	//$("#next").click(function() { playListNext(); });
	//$("#previous").click(function() { playListPrev(); }); 
	$("#jp-pause").click(function() { $("#jquery_jplayer").jPlayer("pause"); });
	$("#jp-play").click(function() { $("#jquery_jplayer").jPlayer("play"); });
	
	function playListChange(track, title, album) {		
		if (typeof track === 'number') {			
			currentTrack = track;
		} else {	
			var i = 0;
			var found = false;
			for (i=0; i < playList.length; i++) {
				if (playList[i].file === track) {
					currentTrack = i;
					found = true;
					break;
				}
			}
			
			if (found === false) {
				var info = [];
				info.title = title;
				info.album = album;
				info.file = track;
				playList.push(info);
				currentTrack = (playList.length - 1);
			}
		}
		$("#jquery_jplayer").bind($.jPlayer.event.play, function(event) {
		  $("#jp-play").addClass('on');
		  $("#jp-pause").removeClass('on');
		});
		$("#jquery_jplayer").bind($.jPlayer.event.pause, function(event) { 
		  $("#jp-play").removeClass('on');
		  $("#jp-pause").addClass('on');
		});

		$('#jquery_jplayer').jPlayer("setMedia", {mp3: playList[currentTrack].file});
		$('#jquery_jplayer').jPlayer("play");
		
		if (playList[currentTrack].album.length > 0)
			$('#jp-info').html('<span class="jp-title">' + playList[currentTrack].title + 
				'</span> - <span class="jp-album">' + playList[currentTrack].album + '</span>');
		else
			$('#jp-info').html('<span class="jp-title">' + playList[currentTrack].title + '</span>');
			
		//showMessage('<small>'+lang_playing+'  <strong><em>&quot;' + playList[currentTrack].title + '&quot;</em></strong></small>');
	}
	
	function playListNext() {
		var index = (currentTrack + 1 < playList.length) ? currentTrack + 1 : 0;
		playListChange(index);
	}
	
	function playListPrev() {
		var index = (currentTrack - 1 >= 0) ? currentTrack - 1 : playList.length-1;
		playListChange(index);
	}	

	function showMessage(message) {
		var messageBox = $('#message');
		
		if (messageBox.length > 0) {
			clearInterval(messageTimerID);
			messageBox.html(message);
		} else {
			$('<div id="message" style="display: none;">' + message + '</div>').appendTo('#player');		
			$('#message').show(500);			
		}

		messageTimerID = setInterval(hideMessages, 5000);
	}
	
	function hideMessages() {
		clearInterval(messageTimerID);
		$('#message').hide(500, deleteMessages);
	}
	
	function deleteMessages() {
		$('#message').remove();
	}


$.address.change(function(event) {  
		var toLoad = event.value;				
		
			/*if ( toLoad === '/' && firstLoad === true) {
				firstLoad = false;
				return; 
			}*/
			toLoad = toLoad.substring(1);
			
hrefMatch = toLoad.split('&');			
$('#menu a.activo').stop().animate({color: '#000000',backgroundPosition:"(100% 35px)"}, 300).removeClass('activo');
if ( toLoad === '') {
	$('#menu a:first').addClass('activo').stop().animate({color: '#7ea831',backgroundPosition:"(100% 0px)"}, 300);	
}else{
$('#menu a[href*="'+hrefMatch[0]+'"]').addClass('activo').stop().animate({color: '#7ea831',backgroundPosition:"(100% 0px)"}, 300);
}

			$('<div class="loading-ajax">'+lang_loading+'</div>').appendTo('body').stop(true,true).slideDown(100);
			
			$('#left_content').stop(true,true).fadeOut(300,function(){
			$.ajax({
				type:	'GET',
				url:	'content.php'+toLoad,
				dataType:	'html',
				timeout:	5000,
				success: function(d,s){
						$('.loading-ajax').stop(true,true).fadeOut(800,function(){ 
							$(this).remove();
						});
						$('#left_content').html(d).stop(true,true).animate({"height": "toggle", "opacity": "toggle"}, 500);
						//$('#left_content img').imagesLoaded(function () {$(this).hide().fadeIn(500, 'swing');});
						$("a[rel=lightbox-gal]").fancybox({
							'transitionIn'		: 'elastic',
							'transitionOut'		: 'elastic',
							'titlePosition' 	: 'over',
							'overlayColor'		: '#fff',
							'overlayOpacity'	: 0.8,
							'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
								return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
							}
						});
						$("a.lb-letras").click(function() {
							var url = $(this).attr("href");
								$.fancybox({
									'type' : 'iframe',
									'href' : url,
									'width': 450,
									'height': 460,
									'transitionIn'	:	'fade',
									'transitionOut'	:	'fade',
									'speedIn'		:	600, 
									'speedOut'		:	200, 
									'overlayColor'		: '#fff',
									'overlayShow'	:	true,
									'scrolling'		: 'auto',
									'titleShow'		: false,
									'hideOnContentClick' : false
								});
							return false;
						});
						$('a:urlExternal').attr('target', '_blank');
						$('a[href*="uploads"]').attr('target', '_blank');
						$.address.title(/>([^<]*)<\/title/.exec(d)[1]);
						},
				error: function(o,s,e){
							window.location = 'index.php'+toLoad;
						}
			});
		});
	});  

$('#left_content').hide();

$('a[name!="lang"][rel!="lightbox-gal"][class!="lb-letras"][href!="lb-letras"][target!="_blank"]:urlInternal').live('click', function(){
		var toLoad = $(this).attr('href');
		toLoad = toLoad.split('?');
		$.address.value('?'+toLoad[1]);
		return false;
	});

$(".form").live("submit", function() {
           var optionsContactos = {
               target: "#update",
               url: "inc/process_mail.php",
               type: "post",
			   beforeSubmit:  function(resposta) {
				   	$('#submit_bt2').disabled=true;
					$("#update").html("<img src=\"imagens/imgs_loader.gif\" />").fadeIn('fast');
               },
               success: function(resposta) {
			   		$('#submit_bt2').disabled=false;
					$("#update").html(resposta).fadeTo(1000, 0.70);
               }
           }
           $(this).ajaxSubmit(optionsContactos);
           return false;
       });	
	   
$(".form-newsletter").live("submit", function() {
           var optionsContactos = {
               target: "#update-newsletter",
               url: "inc/process_news.php",
               type: "post",
			   beforeSubmit:  function(resposta) {
				   	$('#bt-newsletter').disabled=true;
					$("#update-newsletter").html("<img src=\"imagens/imgs_loader.gif\" />").fadeIn('fast');
               },
               success: function(resposta) {
			   		$('#bt-newsletter').disabled=false;
					$("#update-newsletter").html(resposta).fadeTo(1000, 0.70).delay(4000).fadeOut(1000);
               }
           }
           $(this).ajaxSubmit(optionsContactos);
           return false;
       });			
});// fim ready

$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'),
      len = elems.length;
      
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,this); }
  }).each(function(){
     // cached images don't fire load sometimes, so we reset src.
     if (this.complete || this.complete === undefined){
        var src = this.src;
        // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
        // data uri bypasses webkit log warning (thx doug jones)
        this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
        this.src = src;
     }
  });
  return this;
};


/* background plugin */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('(i($){c(!C.B||!C.B.Z){e p=u.t;u.t=i(a,f,o){c(f===\'n-m\'){f=\'7\'}c(f!==\'7\'||!a.D||a.D[f]){k p.z(x,y)}e h=a.h;c(!o&&h&&h[f]){k h[f]}k p(a,\'T\',o)+\' \'+p(a,\'S\',o)}}e G=$.E.A;$.E.A=i(8){c(\'n-m\'F 8){8.7=8[\'n-m\'];N 8[\'n-m\']}c(\'7\'F 8){8.7=\'(\'+8.7}k G.z(x,y)};i v(b){b=b.q(/W|X/g,\'w\');b=b.q(/Y|12/g,\'11%\');b=b.q(/([0-9\\.]+)(\\s|\\)|$)/g,"$V$2");e j=b.U(/(-?[0-9\\.]+)(H|\\%|M|I)\\s(-?[0-9\\.]+)(H|\\%|M|I)/);k[J(j[1],10),j[2],J(j[3],10),j[4]]}$.5.P.7=i(5){c(!5.L){e 6=$.t(5.a,\'7\');c(!6){6=\'w w\'}6=v(6);5.6=[6[0],6[2]];e d=v(5.O.Q.7);5.d=[d[0],d[2]];5.r=[d[1],d[3]];5.L=R}e l=[];l[0]=((5.d[0]-5.6[0])*5.K)+5.6[0]+5.r[0];l[1]=((5.d[1]-5.6[1])*5.K)+5.6[1]+5.r[1];5.a.h.7=l[0]+\' \'+l[1]}})(u);',62,65,'|||||fx|start|backgroundPosition|prop||elem|strg|if|end|var|name||style|function|res|return|nowPosX|position|background|force|oldCurCSS|replace|unit||curCSS|jQuery|toArray|0px|this|arguments|apply|animate|defaultView|document|currentStyle|fn|in|oldAnim|px|pt|parseFloat|pos|bgPosReady|em|delete|options|step|curAnim|true|backgroundPositionY|backgroundPositionX|match|1px|left|top|right|getComputedStyle||100|bottom'.split('|'),0,{}))
/* fim background plugin */
function PrintThisPage(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popUp(windowUri, windowName, windowWidth, windowHeight, scrollbars){
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;
    window.open(windowUri, windowName, 'toolbar=0,scrollbars='+ scrollbars +',location=0,statusbar=0,menubar=0,resizable=1,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);
}







