/*
 * Project: Burnstone Ventures Inc.
 * Author: Rudy Affandi
 * Created: 08/23/2011
 * File name: functions.js
 */

// Basic settings
var companyName = 'Burnstone Ventures Inc.';

// 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
if (jQuery().url){// Check if plugin loaded
	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/main_bg.jpg', '/i/common/header_bg.png');

   // 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 map
	$('.map, .prj').maphilight({
		fill: true,
		fillColor: 'ffffff',
		fillOpacity: 0.2,
		stroke: true,
		strokeColor: '0c5753',
		fade: true
	});

	// Set h tag margin
   $('.content_body h2:first, .content_body h3:first').css('margin-top', '0');

	// Financials, check if PDF exist
	$('.fs_format div.link a').each(function() {
		if	( $(this).attr('href').length <= 0 )
		{
			$(this).hide();
		}
	});

	// Image thumbnail processing
	$('img').load(function(){
		 var $this = $(this),
			  img_width = $this.width();
			  img_height = $this.height();
		 $this.closest('.img_thumb').css('width', img_width + 'px');
		 $this.closest('ul.image_grid_format li').css('width', img_width + 'px');
	});

	// Add back to top icon
	$('.top a').append('<div class="top_arrow">');

   // Photo gallery settings (Grid format)
 	$('ul.image_grid_format li a[href*="_sm"]').each(function(){
 	   var href = $(this).attr('href').replace('_sm', '');
 	   $(this).attr('href', href);
   });

});
