$(document).ready(function()
{
    $('#home-main-menu').appendTo('#content-container');

    $(window).resize(function()
    {
       $('#overlay').css("width", $(document).width());
       $('#overlay').css("height", $(document).height());
    });

    $('.external-link').css("cursor", "pointer");
    $('#exitWarning').find("a.btn-lbwhite").bind("click", function()
    {
        closeExitPopup();
    });

    $('#exitWarning').find("a.btn-bgb").bind("click", function()
    {
        closeExitPopup();
    });

    $('a.external-link').bind("click", function()
    {

       var link = $(this).attr('rel');
       $('<div id="overlay"></div>').appendTo('#container');
       $('#overlay').css("position", "absolute");
       $('#overlay').css("top", "0px");
       $('#overlay').css("left", "0px");
       $('#overlay').css("width", $(document).width());
       $('#overlay').css("height", $(document).height());
       $('#overlay').css("opacity", "0");
       $('#overlay').css("background-color", "rgb(51, 51, 51)");
       $('#overlay').css("z-index", "9998");
       $('#overlay').css("cursor", "pointer");

       $("#overlay").animate({

            opacity: 0.8
        }, 900 );

       $("#overlay").bind("click", function()
        {
            closeExitPopup();
        }
        );
       $("#exitWarning").css("visibility", "visible");
       $("#exitWarning").fadeIn('slow');
       $("#exitWarning").find("a.btn-bgb").attr('href', link);
    }
    );



   $('#exitWarning').css("display", "none");
   $('#home-articles').jScrollPane({showArrows:true, scrollbarWidth:22, scrollbarMargin:10});

   $('.jScrollPaneDrag').css("width", "14px");
   $('.jScrollPaneDrag').css("height", "50px" );
   $('.jScrollPaneDragBottom').css("top", "40px");

   $('.bread-crumb').append($('.bread-crumb-content'));

   $('.update').each( function ()
   {

       var link = $(this).find('a').attr('href');

       if (link)
        {

       $(this).css('cursor', 'pointer');
       $(this).bind("click", function ()
       {
           window.open(link, '_self');
        });
        }
   });



   $('.gallery').each( function ()
   {

       var link = $(this).find('a').attr('href');

       if (link)
        {

       $(this).css('cursor', 'pointer');
       $(this).bind("click", function ()
       {
           window.open(link, '_self');
        });
        }
   });


   


   $('.video').each( function ()
   {
       $(this).css('cursor', 'pointer');
       var link = $(this).attr('href') || $(this).find('a').attr('href');
       var title = $(this).attr('data-display') ||  $(this).find('a').attr('data-display');
       $(this).data("caption", title);
       $(this).bind("click", function (e)
       {
           e.preventDefault();
		   var obj = new Object();
           obj.content = link;
           obj.player = 'swf';
           obj.title = title;
           obj.height = '330';
           obj.width = '533';
		   obj.options = {onFinish: sbFinish};
          Shadowbox.open(obj);
			$('#sb-si-close').hide();
       });
   });

});

function closeExitPopup()
{
       $("#overlay").animate({
            opacity: 0
        }, 900, function()
        {
            $("#overlay").remove();
        } );

        $("#exitWarning").fadeOut('slow');
}
