// JavaScript Document
$(document).ready(function() {
   	//$('.scrollAreaSmall').jScrollPane({dragMaxHeight: 24, scrollbarWidth: 12 }); !! Mudado para homeContent.php para ser carregado no instante a seguir à div.
	$('.playTrack').click(function(){callAlbum(this.id, "miniPlayer"); return false;});
        $('#moreTweets').live('click',function(event){
            $('#tweetfeed-div').fadeIn(250);
            $('#home-div').hide();
            $('#ourTweets').jScrollPane({dragMaxHeight: 24, scrollbarWidth: 12 });
            return false;
        });
        
        $('#backBtn').live('click',function(event){
            $('#tweetfeed-div').hide();
            $('#home-div').show();
            return false;
        });

        $(function() { 
            $('.latestReleaseBlock').ContentSlider({ 
                width : '300px', 
                height : '200px', 
                speed : 400
            }); 
        });
});

(function($) {
  $.fn.ContentSlider = function(options)
  {
    var defaults = {
      leftBtn : 'images/cs_leftImg.jpg',
      rightBtn : 'images/cs_rightImg.jpg',
      width : '300px',
      height : '200px',
      speed : 400,
      easing : 'easeOutQuad',
      textResize : false
    }
    var defaultWidth = defaults.width;
    var o = $.extend(defaults, options);
    var w = parseInt(o.width);
    var n = this.children('.cs_wrapper').children('.cs_slider').children('.cs_article').length;
    var x = -1*w*n+w; // Minimum left value
    var p = parseInt(o.width)/parseInt(defaultWidth);
    var inuse = false; // Prevents colliding animations

    function moveSlider(d, b)
    {
      var l = parseInt($('.cs_wrapper').children('.cs_slider').css('left'));
      if(isNaN(l)) {
        var l = 0;
      }
      var m = (d=='left') ? l-w : l+w;
      if(m<=0&&m>=x) {
        $('.cs_wrapper')
            .children('.cs_slider')
              .animate({ 'left':m+'px' }, o.speed, function() {
                inuse=false;
              });

        if(b.attr('class')=='cs_leftBtn') {
          var thisBtn = $('.cs_leftBtn');
          var otherBtn = $('.cs_rightBtn');
        } else {
          var thisBtn = $('.cs_rightBtn');
          var otherBtn = $('.cs_leftBtn');
        }
        if(m==0||m==x) {
            thisBtn.animate({ 'opacity':'0' }, 0, function() { thisBtn.css('visibility','hidden') ; });
        }
        if(otherBtn.css('opacity')=='0') {
            otherBtn.css('visibility','visible') ;
            otherBtn.show().animate({ 'opacity':'1' }, { duration:0 });
        }
      }
    }

    return this.each(function() {
      $(this)
        // Set the width and height of the div to the defined size
        .css({
          width:o.width,
          height:o.height
        })
        // Dig down to the article div elements
        .find('.cs_article')
          // Set the width and height of the div to the defined size
          .css({
            width:o.width,
            height:o.height
          })
          .end();

      // Store a copy of the button in a variable to pass to moveSlider()
      var leftBtn = $(".cs_leftBtn");
      leftBtn.css('visibility','hidden').css({ opacity: 0 });;
      leftBtn.bind('click', function() {
        if(inuse===false) {
          inuse = true;
          moveSlider('right', leftBtn);
        }
        return false; // Keep the link from firing
      });

      // Store a copy of the button in a variable to pass to moveSlider()
      var rightBtn = $('.cs_rightBtn');
      rightBtn.bind('click', function() {
        if(inuse===false) {
          inuse=true;
          moveSlider('left', rightBtn);
        }
        return false; // Keep the link from firing
      });

    });
  }
})(jQuery)
