/*
 * Project: Fission Energy Corp.
 * Author: Rudy Affandi
 * Created: 02/15/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'Fission Energy Corp.';

// Main navigation drop down, 3rd level settings (please enter 'yes' or 'no')
var allow_main_3rd_level = 'no';

// Side navigation drop down, 3rd level settings (please enter 'yes' or 'no')
var allow_side_3rd_level = 'yes';

//Grab language selector from scripts alias
if (jQuery().url){// Check if plugin loaded
   var lang_selector = jQuery.url.segment(0);
}

// jQuery initialization and CSS settings, waiting for DOM tree to initialize
jQuery(document).ready(function(){
   // Set language information, default to English
   $('html').attr('lang', 'en');

   // Preload images from CSS
   $.getScript('/cc/lib/jquery/plugins/preloadCssImages.jQuery_v5.js',function(){
      $.preloadCssImages();
   });

   // Maps gallery settings (Grid format)
    jQuery('a[href*="_sm"]').each(function(){
       var href = jQuery(this).attr('href').replace('_sm', '');
       jQuery(this).attr('href', href);
   });

   $('ul.acitem li.gallery:eq(4)').css('clear', 'left');

   // Management and Directors bio slider
   $('.mgmt_info').hide();
   $('h3.trigger').click(function () {
      $(this).toggleClass('active').next().next().slideToggle('slow');
      return false;
   });

   // Rounded corners
   $('.header_feed').addClass('ui-corner-bottom');

   // Add text shadow to Legal disclaimer footer
   if ($.browser.msie) {
       $('ul.menu li a h3').textShadow();
   }

   // Tabbed interface
   if ($('ul.tabs').length > 0){
      $.getScript('/cc/lib/jquery/plugins/jquery.tools.min.js',function(){
         $('ul.tabs').tabs('div.panes > div', { effect: 'fade' });
         $('.tab_name').unbind('click.jumpnm').bind('click.jumpnm', function(e){
            e.preventDefault();
            var tab_name = $(this).attr('href');
            $('.tabs').data('tabs').click(tab_name);
         });
      });
   }

   // Projects map tooltip using imagemap
   if ($('.content area').length > 0){
      $.getScript('/cc/lib/jquery/plugins/jquery.qtip-1.0.0-rc3.min.js',function(){
         $('area').each(function(){
            $(this).qtip(
            {
               content: $(this).attr('alt'), // Use the ALT attribute of the area map
               style: {
                  color: '#fff',
                  background: '#00a634',
                  border: {
                     width: 0,
                     radius: 4,
                     color: '#83a7bd'
                  },
                  tip: true // Apply a tip at the default tooltip corner
               },
               position: { corner: { target: 'topLeft', tooltip: 'bottomLeft' } }
            });
         });
      });
   }

   // Photo gallery settings
   // add Gallery title from REL tag
   var galleryTitle = $('.items span.gallerytitle a').attr('rel');
   $('h3.gallery_title').text(galleryTitle);

   // Divide list of thumbs into 5 (or any arbitrary number set in the variable
   var itemindex = 0;
   var maxThumbs = 5;
   var Jlistobj = null;
   $('span.biglist img').each(function(){
      if (itemindex % maxThumbs == 0)
      {
         Jlistobj = $("<div></div>");
      }
      Jlistobj.append($(this));
      $('.items').append(Jlistobj);
      itemindex++;
   });
   $('span.biglist').remove();

   $('.scrollable').scrollable();
   $('#image_wrap, .scrollable, .scrollable img').addClass('ui-corner-all');
   $('.items img').click(function() {

   // see if same thumb is being clicked
   if ($(this).hasClass('active')) { return; }

   // Get the large image filename from thumbnail
   var url = $(this).attr('src').replace('_sm', '');

   // add caption from TITLE tag
   var caption = $(this).attr('title');
   $('div.gallery_format h4').text(caption);

   // get handle to element that wraps the image and make it semi-transparent
   var wrap = $('#image_wrap').fadeTo('medium', 0.5);

   // the large image from CMS
   var img = new Image();

      // call this function after it's loaded
   img.onload = function() {

      // make wrapper fully visible
      wrap.fadeTo('fast', 1);

      // change the image
      wrap.find('img').attr('src', url);
   };

   // begin loading the image from source folder/path
   img.src = url;

   // activate item
   $('.items img').removeClass('active');
   $(this).addClass('active');

   // when page loads simulate a "click" on the first image
   }).filter(':first').click();
});
