
// Returns string Ex: "1.3.1"
var minHeight = 700;
var minHeightShort = 200;
var $curImgH;
var $curImgHShort;
var $imgTop;
var $imgTopShort;
var imgH = 800;// $('.source-image img').height();
var imgW = 1400; //$('.source-image img').width();
var imgHShort = 800; //$('.source-image-short img').height();

$(document).ready(function() {	 
						  
				   
	initFonts();
			   
	
	
	var $winwidth = $(window).width();
	var ratio = imgW/imgH;
	var ratioShort = imgW/imgHShort;
	var minImgW = ratio*minHeight;
	var minImgWShort = ratioShort*minHeightShort;
	//alert(imgH+" "+imgW+" "+ratio+" "+$winwidth+" "+minImgW);
	
	var pathname = window.location.pathname;
	
	if ($winwidth-100 < 982){
		$winwidth = 1082;	
	}
	
	// Adjust Always 
	$(".main_image_container").width($winwidth-100);
	$(".main_menu_bg").width($winwidth-130);
	$(".main_menu_bg-short").width($winwidth-130);
	
	$(".main_image_container-short").width($winwidth-100);
	
	

	// Adjust based on window width
	if (($winwidth-130) < (minImgW)) {
		$(".source-image img").attr({ width: minImgW });
		var $imgLeft = 0-((minImgW - ($winwidth-130))/2) ;
		
		if (pathname == '/' && !_short)
		{
			
			$(".source-image img").css({left:$imgLeft+"px"});
			$(".source-image-holder").attr({ width: $winwidth-500 });
			//alert(imgH+" "+imgW+" "+ratio+" "+minImgW+" "+$imgLeft+" "+$winwidth);
		}
		else 
		{
			$(".source-image-short img").attr({ width: minImgW });
			$(".source-image-short img").css({left:$imgLeft+"px"});
			$(".source-image-holder-short").attr({ width: $winwidth-500 });
		}
		
		if (pathname == '/' && !_short)
		{
					// Adjust Image Height
			$(".source-image img").css({top:0+"px"});
		}
		else 
		{
			// Adjust Image Height
			$curImgHShort = imgHShort ;//$('.source-image-short img').height();
			$imgTopShort = 0-(($curImgHShort - minHeightShort)/4);
			$(".source-image-short img").css({top:$imgTopShort+"px"});
		}
	}
	else 
	{
		if (pathname == '/' && !_short)
		{
			$(".source-image img").attr({ width: $winwidth-130});
			$(".source-image").attr({ width: $winwidth-130});
		} else 
		{	
			$(".source-image-short img").attr({ width: $winwidth-130});
			$(".source-image-short").attr({ width: $winwidth-130});
		}

		if (pathname == '/' && !_short)
		{
			// Adjust Image Height
			$curImgH = imgH; //$('.source-image img').height();
			$imgTop = 0-(($curImgH - minHeight)/2);
			$(".source-image img").css({top:$imgTop+"px"});
		}
		else 
		{
			$curImgHShort = imgHShort;//$('.source-image-short img').height();
			$imgTopShort = 0-(($curImgHShort - minHeightShort)/4);
			$(".source-image-short img").css({top:$imgTopShort+"px"});
		}
	 }
	
	// RESIZE
	$(window).bind("resize", function(){
		//var pathname = window.location.pathname;
		var $winwidth = $(window).width();

	if ($winwidth-100 < 982){
		$winwidth = 1082;
	}
		// Adjust Always 
		
			$(".main_image_container").width($winwidth-100);
			$(".main_menu_bg").width($winwidth-130);

			$(".main_menu_bg-short").width($winwidth-130);	
			$(".main_image_container-short").width($winwidth-100);
	
		
		// Adjust based on window width
		if (($winwidth-130) < (minImgW)) {
			$(".source-image img").attr({ width: minImgW });
			var $left = 0-((minImgW - ($winwidth-130))/2);
			
			if (pathname == '/' && !_short) 
				$(".source-image img").css({left:$left+"px"});
			else {
				$(".source-image-short img").attr({ width: minImgW });
				$(".source-image-short img").css({left:$left+"px"});
			}
			
			// Adjust Image Height
			if (pathname == '/' && !_short) 
				$(".source-image img").css({top:0+"px"});
			else 
			{ 
				// Adjust Image Height
				$curImgHShort = imgHShort;// $('.source-image-short img').height();
				$imgTopShort = 0-(($curImgHShort - minHeightShort)/4);
				$(".source-image-short img").css({top:$imgTopShort+"px"});
			}
		}
		else 
		{
			if (pathname == '/' && !_short)
			{
				$(".source-image img").attr({ width: $winwidth-130 });
				$(".source-image img").css({ left:0+"px" });
			}
			else 
			{
				$(".source-image-short img").attr({ width: $winwidth-130 });
				$(".source-image-short img").css({ left:0+"px" });
			}
			
			if (pathname == '/' && !_short)
			{
				// Adjust Image Height
				$curImgH = imgH;//$('.source-image img').height();
				$imgTop = 0-(($curImgH - minHeight)/2);
				$(".source-image img").css({top:$imgTop+"px"});
			}
			else 
			{
				$curImgHShort = imgHShort ;//$('.source-image-short img').height();
				$imgTopShort = 0-(($curImgHShort - minHeightShort)/4);
				$(".source-image-short img").css({top:$imgTopShort+"px"}); 
			}
		}
	
	 });
});
	
	
function initFonts()
{
	Cufon.set('fontFamily', 'Trade Gothic LT Std');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('#footer .footercontent');
	Cufon.replace('.view-about-page .field-content .title');
	Cufon.replace('.view-contact-page .field-content .title');
	
	// Cufon.replace($('h2'), { fontFamily: 'Trade Gothic LT Std' });		
	
}

	
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {x.src=x.oSrc;}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ 
	if(!d.MM_p) {d.MM_p=[];}
   		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++) {
    		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image(); d.MM_p[j++].src=a[i];}
		}
	}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) {d=document;} if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) {x=d.all[n];} for (i=0;!x&&i<d.forms.length;i++) {x=d.forms[i][n];}
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) {x=d.getElementById(n);} return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   {if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}}
}

