/*
 * Project: Monument Mining Limited
 * Author: Rudy Affandi
 * Created: 05/02/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'Monument Mining Limited';

// Main navigation drop down, 3rd level settings (please enter 'yes' or 'no')
var allow_main_3rd_level = 'yes';

// 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_top_nav ul li.en').addClass('ca_16');
      // Translate elements to German
   }
   else if (lang_selector == 's'){
      $('html').attr('lang', 'en');
      $('.header_top_nav ul li.de').addClass('de_16');
   }

   else {
      $('html').attr('lang', 'en');
      $('.header_top_nav ul li.de').addClass('de_16');
   }

   var path = $(location).attr('href');
   var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];
   filename = filename.toLowerCase();
   if (filename == 'home')
   {
		// Home page slide show (fade in/out style)
		$('.tabs').tabs('.panes > div', {
			// enable "cross-fading" effect
			effect: 'fade',
			fadeOutSpeed: 'slow',
			// start from the beginning after the last tab
			rotate: 'true'

		// use the slideshow plugin. It accepts its own configuration
		}).slideshow({autoplay: true, interval: 5000});
   }

   // Set element to semi transparent
   $('.tag_bg, .label_wrapper').fadeTo('slow', 0.5);

   // Annual Reports formatting
   $('div.ar_format:nth-child(5)').addClass('clear margin_top');
   $('div.ar_format, div.event_format').addClass('ui-corner-all');

   // Financials formatting, hide empty files
   $('div.fs_format div span a').not('[href$=pdf]').hide();


if (!jQuery.browser.mozilla) {
		// Initialize table sorter
		$('#eventtable').tablesorter({
			headers: {
				4: { sorter: false }
				}
		});

		$('#analysttable').tablesorter({
			headers: {
				2: { sorter: false }
				},
			sortList: [[1,0],[0,0]]
		});
	}
   // Projects map tooltip
   $('area').each(function(){
      $(this).qtip(
      {
         content: $(this).attr('alt'), // Use the ALT attribute of the area map
         style: {
            color: '#000',
            background: '#fdb825',
            border: {
               width: 2,
               radius: 4,
               color: '#424242'
            },
            tip: true // Apply a tip at the default tooltip corner
         },
         position: { corner: { target: 'leftMiddle', tooltip: 'rightMiddle' } },
         hide: { when: 'mouseout', fixed: true }
      });
   });

   // 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
   if (lang_selector == 'en')
   {
		var caption = $(this).attr('title');
	}
	else
	{
		var caption = '';
	}
   $('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();

});

// Set up Flowplayer video player
//flowplayer('player', '/cc/lib/flowplayer/flowplayer-3.2.7.swf');

