$(function() {
	
	/* Navigation Tabs */
    $("#example-one").organicTabs();
    
    $("#example-two").organicTabs({
        "speed": 200
    });
    /* End Navigation Tabs */
    
    /* View Video */
    $("a.iframe").fancybox({
		 		'transitionIn'	:	'elastic',
		 		'transitionOut'	:	'elastic',
		 		'speedIn'		:	600, 
		 		'speedOut'		:	200, 
		 		'overlayShow'	:	true
		 	});		
		 	
		 	$.extend({
				jYoutube: function( url, size ){
    		if(url === null){ return ""; }

    		size = (size === null) ? "big" : size;
		    var vid;
		    var results;

		    results = url.match("[\\?&]v=([^&#]*)");

		    vid = ( results === null ) ? url : results[1];

	    	if(size == "small"){
		      return "http://img.youtube.com/vi/" + vid + "/2.jpg";
		    }else {
		      return "http://img.youtube.com/vi/" + vid + "/0.jpg";
		    }
  		}
	});	
	/* End View Video */
	
	/* View Discography */
	var onMouseOutOpacity = 0.67;
	$('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
		.hover(
			function () {
				$(this).not('.selected').fadeTo('fast', 1.0);
			}, 
			function () {
				$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
			}
		);
	
	var gallery = $('#gallery').galleriffic('#thumbs', {
		delay:                  2000,
		numThumbs:              13,
		preloadAhead:           10,
		enableTopPager:         true,
		enableBottomPager:      true,
		imageContainerSel:      '#slideshow',
		controlsContainerSel:   '#controls',
		captionContainerSel:    '#caption',
		loadingContainerSel:    '#loading',
		renderSSControls:       true,
		playLinkText:           'Play',
		pauseLinkText:          'Pause',
		prevLinkText:           'Anterior',
		nextLinkText:           'Pr&oacute;xima',
		nextPageLinkText:       'Next &rsaquo;',
		prevPageLinkText:       '&lsaquo; Prev',
		enableHistory:          true,
		autoStart:              false,
		onChange:               function(prevIndex, nextIndex) {
			$('#thumbs ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onTransitionOut:        function(callback) {
			$('#slideshow, #caption').fadeOut('fast', callback);
		},
		onTransitionIn:         function() {
			$('#slideshow, #caption').fadeIn('fast');
		},
		onPageTransitionOut:    function(callback) {
			$('#thumbs ul.thumbs').fadeOut('fast', callback);
		},
		onPageTransitionIn:     function() {
			$('#thumbs ul.thumbs').fadeIn('fast');
		}
	});
	/* End View Discography */
	
	/* Gallery Photos */
	$('img.image1').data('ad-desc', '');
	$('img.image1').data('ad-title', '');
	$('img.image4').data('ad-desc', '');
	$('img.image5').data('ad-desc', '');
	var galleries = $('.ad-gallery').adGallery();
	$('#switch-effect').change(
	  function() {
	    galleries[0].settings.effect = $(this).val();
	    return false;
	  }
	);
	$('#toggle-slideshow').click(
	  function() {
	    galleries[0].slideshow.toggle();
	    return false;
	  }
	);
	$('#toggle-description').click(
	  function() {
	    if(!galleries[0].settings.description_wrapper) {
	      galleries[0].settings.description_wrapper = $('#descriptions');
	    } else {
	      galleries[0].settings.description_wrapper = false;
	    }
	    return false;
	  }
	);
	/* End Gallery Photos */
	
});
/* Player Music */
$(document).ready(function(){

	var playItem = 0;

	var myPlayList = [
		{name:"Tempered Song",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-01-Tempered-song.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-01-Tempered-song.ogg"},
		{name:"Hidden",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-02-Hidden.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-02-Hidden.ogg"},
		{name:"Lentement",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-03-Lentement.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-03-Lentement.ogg"},
		{name:"Lismore",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-04-Lismore.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-04-Lismore.ogg"},
		{name:"The Separation",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-05-The-separation.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-05-The-separation.ogg"},
		{name:"Beside Me",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-06-Beside-me.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-06-Beside-me.ogg"},
		{name:"Bubble",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-07-Bubble.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-07-Bubble.ogg"},
		{name:"Stirring of a Fool",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-08-Stirring-of-a-fool.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-08-Stirring-of-a-fool.ogg"},
		{name:"Partir",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-09-Partir.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-09-Partir.ogg"},
		{name:"Thin Ice",mp3:"http://www.miaowmusic.com/audio/mp3/Miaow-10-Thin-ice.mp3",ogg:"http://www.miaowmusic.com/audio/ogg/Miaow-10-Thin-ice.ogg"}
	];

	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");

	$("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
		},
		swfPath: base_path + "swf/",
		oggSupport: true,
		nativeSuport: true
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		$(this).blur();
		return false;
	});

	$("#jplayer_next").click( function() {
		playListNext();
		$(this).blur();
		return false;
	});

	function displayPlayList() {
		$("#jplayer_playlist ul").empty();
		for (i=0; i < myPlayList.length; i++) {
			var listItem = (i == myPlayList.length-1) ? "<li class='jplayer_playlist_item_last'>" : "<li>";
			listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1'>"+ myPlayList[i].name +"</a></li>";
			$("#jplayer_playlist ul").append(listItem);
			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$("#jquery_jplayer").jPlayer("play");
				}
				$(this).blur();
				return false;
			});
		}
	}

	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		$("#jquery_jplayer").jPlayer("play");
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}
  
  // Alert
  setTimeout(hideAlert,4000);
		$("#alert-message").click(function(){
			hideAlert();
		});
		function hideAlert(){
			if ($("#alert-message")[0]) { $("#alert-message").slideUp('fast'); }
		}
  
		
	/* Twitter */
	jQuery(document).ready(function($) {
	  $(".tweet").tweet({
	    join_text: "auto",
	    username: "silveriopessoa",
	    avatar_size: 48,
	    count: 2,
	    auto_join_text_default: "", 
	    auto_join_text_ed: "we",
	    auto_join_text_ing: "we were",
	    auto_join_text_reply: "we replied",
	    auto_join_text_url: "we were checking out",
	    loading_text: "loading tweets..."
	  });
	  $("#query").tweet({
	    avatar_size: 32,
	    count: 4,
	    query: "tweet.silveriopessoa.com",
	    loading_text: "searching twitter..."
	  });
	  $("#userandquery").tweet({
	    count: 3,
	    query: "from:silveriopessoa http",
	    loading_text: "searching twitter..."
	  });
	  $("#fromtwo").tweet({
	    avatar_size: 32,
	    count: 4,
	    username: ["silveriopessoa", "laughingsquid"],
	    loading_text: "searching twitter...",
	    refresh_interval: 10
	  });
	  $("#list").tweet({
	    avatar_size: 32,
	    count: 4,
	    username: "twitter",
	    list: "team",
	    loading_text: "loading list..."
	  });
	  $("#empty").tweet({
	    avatar_size: 32,
	    count: 4,
	    query: "cieR8oog",
	    loading_text: "searching twitter..."
	  }).bind("empty", function() { $(this).append("No matching tweets found"); });
	})
	/* End Twitter */
});
/* End Player Music */

$(function() {
  var v = $("#contact-form").jcheck({language: 'pt-br'});
  v.validates("nome", {presence: true});
  v.validates("email", {format: {"with": "email", message: "Utilize um e-mail válido"}});
  v.validates("mensagem", {length: {minimum: 1, maximum: 2550}});
});
