/*
 * Project: International Enexco Limited
 * Author: Rudy Affandi
 * Created: 10/06/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'International Enexco Limited';

// 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);

// Cufon usage in main navigation
var cufon_nav = 'no';

// jQuery initialization and CSS settings, waiting for DOM tree to initialize
$(document).ready(function(){
	// Preload images from CSS
	$.preloadCssImages();

   // Set language information, default to English
   $('html').attr('lang', 'en');

	// Set h tag margin
   $('.content_body h2:first, .content_body h3:first').not('.col h2').css('margin-top', '0');

	// Financials, check if PDF exist
	$('.fs_format div.link a').each(function() {
		if	( $(this).attr('href').length <= 0 )
		{
			$(this).hide();
		}
	});

	// Technical Reports, check if PDF exist
/*
   if ($("li.pdf a[href$='.pdf']"))
   {
	   //$('a.pdf').attr('href', '#');
   } else {
	   //$('a.pdf').attr('rel', 'pdf exist');
	}
*/

	// Banner slide show
	$('.header_slideshow').cycle({
		fx: 'fade',
		speed: 'slow',
		random: '1',
		timeout: 7000
	});

	// Front news date
	$('div.date').addClass('rounded_all_8px');

	// Set up Subscribe button
	$('.header_subscribe button').addClass('rounded_all_4px');

   // Home page only
   var path = $(location).attr('href');
   var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];
   filename = filename.toLowerCase();
   if (filename == 'home')
   {
		// Projects map tooltip using imagemap
		$('.front_text area').each(function(){
			$(this).qtip(
			{
				content: $(this).attr('alt'), // Use the ALT attribute of the area map
				style: {
					color: '#000',
					background: '#fff',
					border: {
						width: 0,
						radius: 4,
						color: '#005696'
					},
					tip: true // Apply a tip at the default tooltip corner
				},
				position: { corner: { target: 'center', tooltip: $(this).attr('rel') } },
				hide: { when: 'mouseout', fixed: true }
			});
		});
   }

   // News releases only
   var path = $(location).attr('href');
   var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];
   filename = filename.toLowerCase();
   if (filename == 'news_releases')
   {
		$('ul#s0').show();
	}

	// Experimental: IE6 stuff
	if ($.browser.msie  && parseInt($.browser.version) <= 6)
	{
   }

	// Make sure news release sub is open when active
	$('has_sub.active').find('ul').show();

   // Fix Cufon refresh issue with navigation colour
   if (cufon_nav == 'yes')
   {
		$('.dropdown li a').ready(function(){
			Cufon.refresh();
		});

		$('.dropdown li').mouseout(function(){
			Cufon.refresh();
		});
   }

	// Add drop shadow
	$('.header_tagline').addClass('drop_shadow');

	// Image thumbnail processing
	$('ul.image_grid_format li').each(function(){
		var _this = $(this);
		$(this).find('img').load(function(){
			_this.css('width', $(this).width() + 'px');
		});
	});

	$('.img_thumb').each(function(){
		var _this = $(this);
		$(this).find('img').load(function(){
			_this.css('width', $(this).width() + 'px');
		});
	});


	// Set right column height
	var page_height = $('div.col1wrap').outerHeight();
	$('.content_side_box').css({'height': page_height + 'px', 'border': '1px solid #474747', 'border-top': 'none'});

   // Initiate shadowbox
    Shadowbox.init();
});
