
// EDITABLE AREA
// ==============================================================

$(document).ready(function () {

    // Auto Lightbox
    // ------------------------------------------------------------  
    auto_lightbox();

    // prettyPhoto
    // ------------------------------------------------------------

    // light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default
    // If set to true, a gallery will overlay the fullscreen image on mouse over
    if ($.isFunction($.fn.prettyPhoto)) {
        $("a[class^='lightbox']").prettyPhoto({
            theme: 'pp_default',
            overlay_gallery: false,
            social_tools: '<div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=pt_BR&href={location_href}&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=24" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:24px;" allowTransparency="true"></iframe></div>'
        });
        //colocar na url ?iframe=true
        $("a[class^='iframes']").prettyPhoto({
            theme: 'pp_default',
            overlay_gallery: false,
            social_tools: '<div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=pt_BR&href={location_href}&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=24" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:24px;" allowTransparency="true"></iframe></div>'
        });
    }

    $('.scroll-pane').jScrollPane();

    // Lightbox Overlay
    // ------------------------------------------------------------

    $("a[class^='lightbox'] img").lightbox_overlay();  
});

// Functions
// ============================================================

// Auto Lightbox
// ------------------------------------------------------------

function auto_lightbox() {
  $('#content').find(
    'a[href$=jpg], '  + 
    'a[href$=jpeg], ' + 
    'a[href$=png], '  + 
    'a[href$=gif], '  +
    'a[href*="vimeo.com"], '   + 
    'a[href*="youtube.com"], ' +
    'a[href$=".swf"], ' +
    'a[href$=".mov"]').each(function()
  {
  	if(!jQuery(this).attr('class').match(/\lightbox/) && !jQuery(this).hasClass('no-lightbox') && $.isFunction($.fn.prettyPhoto)) {
  		jQuery(this).find('img').lightbox_overlay();
  		jQuery(this).addClass('lightbox[content]').prettyPhoto({
      	theme:           'pp_default', // light_rounded / dark_rounded / light_square / dark_square / facebook / pp_default
    		overlay_gallery: false         // If set to true, a gallery will overlay the fullscreen image on mouse over
    	});
    }
  });
}


// PLUGINS
// ============================================================
(function($)
{	
  // Lightbox Overlay
  // ------------------------------------------------------------
  
  $.fn.lightbox_overlay = function(options) {
    
    var defaults = {
      opacity: 0.5,
      animation_speed: 200,
      class_name: 'lightbox-image'
    };
    
    var options = $.extend(defaults, options);
    
    return this.each(function() {
      var img  = $(this);
      var link = $(this).parent();
      var bg   = $("<span class='"+ options.class_name +"'></span>").appendTo(link);
  		
  		link.bind('mouseenter', function() {
  		  var margin_top     = parseInt(img.css("margin-top"));
  		  var margin_bottom  = parseInt(img.css("margin-bottom"));
  		  var padding_left   = parseInt(img.css("padding-left"));
  		  var padding_top    = parseInt(img.css("padding-top"));
  		  var padding_right  = parseInt(img.css("padding-right"));
  		  var padding_bottom = parseInt(img.css("padding-bottom"));
  		  var border_left    = parseInt(img.css("border-left-width"));
  		  var border_top     = parseInt(img.css("border-top-width"));
  		  var border_right   = parseInt(img.css("border-right-width"));
  		  var border_bottom  = parseInt(img.css("border-bottom-width"));
  			var width    = img.width() + padding_left + padding_top + border_left + border_right;
  			var height   = img.height() + margin_top + margin_bottom + padding_top + padding_bottom + border_top + border_bottom;
  			var position = img.position();
  			bg.css({ width:width, height:height, top:position.top, left:position.left });
  		});
    
      link.hover(
        function() { bg.show(); img.stop().animate({ opacity: options.opacity }, options.animation_speed); },
    	  function() { bg.hide(); img.stop().animate({ opacity: 1 }, options.animation_speed); }
      ); 
    });
    
  };       
  
})(jQuery);
