/*

Main Javascript file
Author: John K.
Version: 1.0

*/

var base_url = window.location.host;

jQuery(document).ready(function($){

	Cufon.replace('#contact-sitemap, #copyright, .stylish, #header ul, #content h2, fieldset h3',{
		hover: true,
		textShadow: '0 1px rgba(0, 0, 0, 0.6)'
	});
	
	initBackgroundGalleryTable();
	
	// Reveal Bg
	jQuery('#bg-box img').css('opacity', 0);
	if ($.browser.msie){
		jQuery('#bg-box img').animate({opacity: 1}, 1500);
	}
	else{
		jQuery('#bg-box img').load(function(){
			jQuery(this).animate({opacity: 1}, 1500);
		});
	}
	
	$('.tab-content').hide()
	$('.tab-content.visible').show()
	
	fixOverviewList();
	
	// Open all external links and PDF in new window
	$("a[href^='http:']:not([href*='" + base_url + "']), a[href$='.pdf']:not([href*='" + base_url + "']), a[href$='.pdf']").live('click', function() {
		$(this).attr('target','_blank');
	});
	
})

function initBackgroundGalleryTable(){
	var body = $('body')
		
	// appending background images based on body class
	$('body').append('<div id="bg"><div><table cellspacing="0" cellpadding="0"><tr><td id="bg-box"></td></tr></table></div></div>');	
	if(body.hasClass('index')){
		$('#bg-box').html('<img src="http://'+base_url+'/images/background/home.jpg" alt=""/>');
	} else{
		// random 1 of 2	
		r = Math.floor(Math.random()*4)
		$('#bg-box').html('<img src="http://'+base_url+'/images/background/bg'+r+'.jpg" alt=""/>');
	}
}

function fixOverviewList(){
	items = $('ul.models-overview li')
	for(i=3;i<items.length;i+=4){
		$(items[i]).addClass('no-border');
	}
}