/*
 * Project: Scorpio Gold Corporation
 * Author: Rudy Affandi
 * Created: 06/29/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'Scorpio Gold Corporation';

// 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
var lang_selector = jQuery.url.segment(0);

// jQuery initialization and CSS settings, waiting for DOM tree to initialize
$(document).ready(function(){
   // Set language information and retrieve associated content
   if (lang_selector == 'de'){
      $('html').attr('lang', 'de');
      $('.header_lang a[href*="/de/"]').addClass('active');
      // Translate elements to German
   }
   else {
      $('html').attr('lang', 'en');
      $('.header_lang a[href*="/s/"]').addClass('active');
   }

   // Front page slideshow
   if ( path == 's/home.asp' || path == 's/Home.asp' )
   {
      $('#s3slider').s3Slider({timeOut: 4000});  
   }   

   // Front news update 
   $('.front_news ul li:first').addClass('first');
   $('.front_news ul li:last').addClass('last');

	// Add text shadow to Legal disclaimer footer
	if ( $.browser.msie ) {
	 	$('.front_feat ul li h3').textShadow();
	}

   $('.content_body h2:first').css('margin', '0');

   // Projects map tooltip using imagemap
   $('area').each(function(){
      $(this).qtip(
      {
         content: $(this).attr('alt'), // Use the ALT attribute of the area map
         style: {
            name: 'dark', // Give it the preset dark style
            color: '#000',
            background: '#be8404',
            border: {
               width: 0,
               radius: 4,
               color: '#000'
            }, 
            tip: true // Apply a tip at the default tooltip corner
         }, 
         position: { corner: { target: 'center', tooltip: 'bottomMiddle' } }
      });
   });

   // 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();
});
