// JavaScript Document

$(document).ready(function(){
								
	main_nav(); // call dropdown menu function
	
	jQuery(".main_banner_holder").css({height: minResizedHeight});
	
	jQuery(".main_banner_holder img").css({width: jQuery(document).width()});
	
	jQuery.PictureSlides.init();
	
	/*Misc*/
	
	jQuery("tbody tr:nth-child(odd)").addClass("odd"); // zebra table
	
	//fade buttons
	jQuery(".main_banner_thumbnails li").fadeTo("slow", 0.5);
	jQuery(".main_banner_thumbnails li").hover(function(){
		jQuery(this).fadeTo("slow", 1.0);
	},function(){
		jQuery(this).fadeTo("slow", 0.5);
	});
	
	// Window Resizer Variables
	var originalBgWidth = jQuery(".main_banner_holder img").width();
	var originalBgHeight = jQuery(".main_banner_holder img").height();
	var bgRatio = originalBgWidth/originalBgHeight;
	var headerHeight = jQuery("#main_menu li").height();
	var footerHeight = jQuery(document).height() - headerHeight;
	var theWidth;
	var theHeight;
	var bgHeight;
	
	function getDimensions() {
		// window dimensions
		if (window.innerWidth)
			theWidth=window.innerWidth;
		else if (document.documentElement && document.documentElement.clientWidth)
			theWidth=document.documentElement.clientWidth;
		else if (document.body)
			theWidth=document.body.clientWidth;
	
		if (window.innerHeight)
			theHeight=window.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight)
			theHeight=document.documentElement.clientHeight;
		else if (document.body)
			theHeight=document.body.clientHeight;
	
		bgHeight = theHeight - (headerHeight+footerHeight);
		// bgHeight has a maximum of 850 pixels
		if (bgHeight > originalBgHeight) {
			bgHeight = originalBgHeight;
		}
		if (bgHeight < minResizedHeight) {
			bgHeight = minResizedHeight;
		}
	}
	
	function resizeContent() {
		jQuery(".main_banner_holder").css({height: bgHeight+"px"});
		//calculate static image dimensions
		if (Math.round(theWidth/bgRatio) < bgHeight) {
			imgWidth = Math.round(bgHeight*bgRatio);
			imgHeight = bgHeight;
		} else if (Math.round(theWidth/bgRatio) > bgHeight) {
			imgWidth = theWidth;
			imgHeight = Math.round(theWidth/bgRatio);
		} else {
			imgWidth = theWidth;
			imgHeight = bgHeight;
		}
	
		// resize still image if used
		if (jQuery(".main_banner_img")) {
			jQuery(".main_banner_img").css({height: imgHeight+"px"});
			jQuery(".main_banner_img").css({width: imgWidth+"px"});
			// center image
			if (imgWidth > theWidth) {
				posLeft = Math.round((imgWidth-theWidth)/2);
				jQuery(".main_banner_img").css({left: "-"+posLeft+"px"});
			} else {
				jQuery(".main_banner_img").css({left: 0});
			}
		}
	}
	
	jQuery(window).resize(function(){
		getDimensions();
		resizeContent();
	});
	
});

// Premade Functions

$(function(){ //smoothscroll
	jQuery(".smooth_scroll").click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
			&& location.hostname == this.hostname) {
				var $target = $(this.hash);
				$target = $target.length && $target || $("[name=" + this.hash.slice(1) +"]");
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$("html,body").animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
});

function main_nav(){ //dropdown menu

	var the_nav = "#main_menu"; // menu ID or CLASS

	jQuery(the_nav + " ul").css({display: "none"}); // Fix for Opera Browser

	jQuery(the_nav).find("ul:first").addClass("first_drop_down");
	
	jQuery(the_nav).find("ul:last").addClass("last_drop_down");
	
	jQuery(the_nav).find("li").addClass("fix_png");
	
	jQuery(the_nav + " li").hover(function(){
	jQuery(this).find("ul:first").css({visibility: "visible", display: "none"}).slideDown(350);
	},function(){
	jQuery(this).find("ul:first").css({visibility: "hidden"});
	});
  
}


