/*
 * Project: International Lithium Corporation
 * Author: Rudy Affandi
 * Created: 07/26/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'International Lithium Corporation';

// 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);

// Cufon usage in main navigation
var cufon_nav = 'yes';

// jQuery initialization and CSS settings, waiting for DOM tree to initialize
$(document).ready(function(){
	// Preload images
	$.preLoadImages('/i/common/header_bg.jpg', '/i/common/content_header_bg.jpg', '/i/common/front_content_header_bg.jpg', '/i/common/front_img_1.jpg', '/i/common/front_img_2.jpg', '/i/common/front_img_3.jpg', '/i/common/front_img_4.jpg', '/i/common/front_img_5.jpg', '/i/common/front_img_6.jpg');

	// Initialize Cufon
	Cufon.set('fontFamily', 'Gill Sans');
		Cufon.replace('.content_side > ul > li > a', { hover: true });
		Cufon.replace('.content_header h2', { hover: true });
		Cufon.replace('.content_side h2', { hover: true });
		Cufon.replace('.content_body h2', { hover: true });
		Cufon.replace('.side_feat li h3', { hover: true });
		Cufon.replace('.header_symbol h3', { hover: true });
		Cufon.replace('.front_content h2', { hover: true });
		Cufon.replace('.dropdown > li > a', { hover: true });
	$('.cufonized').removeClass('cufonized');
	Cufon.refresh();

	// Fade in front image
	$('.front_content_header_bg').delay(500).fadeTo('slow', 1);

   // 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');
   }

   $('.content_body h2:first').css('margin-top', '0');

	// Remove alternating row color if less than 3 rows
	var tr_count = $('table.table2').length;
	if ( tr_count <= 2 )
	{
		$('table.table2 tr:nth-child(odd)').css('background', 'none')
	}

	// Financials, check if PDF exist
	$('.fs_format div.link a').each(function() {
		if	( $(this).attr('href').length <= 0 )
		{
			$(this).hide();
		}
	});

	// Front page rollover effect
	if($('body#front').length) {
		$('ul.side_feat li').removeClass('double_line');
		$('.dropdown li a').each(function() {

		/* Bind version, need to work on sensitivity handling a'la hoverIntent */
			$('a#n1').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_2'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_2'); }
			});

			$('a#n2').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_3'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_3'); }
			});

			$('a#n3').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_4'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_4'); }
			});

			$('a#n4').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_5'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_5'); }
			});

			$('a#n5').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_6'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_6'); }
			});

			$('a#n6').bind({
				mouseenter: function() { $('#front_img').addClass('front_img_2'); },
				mouseleave: function() { $('#front_img').removeClass('front_img_2'); }
			});
		});
	}
});
