// JavaScript Document

function preloadImages( $array, $path ){
	$( $array ).each( function( key, value )
	{
		var img = new Image();
		$(img).attr( 'src', $path + value )
		.error( function()
						 { alert('Error preloading image' + value);  
						 });
	});
	
}

function openSiteContents(){
	$("#pageMiddleBodyBtm").height();
	$("#pageMiddleBodyBtm").hover(function(event){
 
			 	$("#pageMiddleBodyBtm").stop().animate({
					height: "80"
				}, 500 );
			 
			}, function(event){
				
			 	$("#pageMiddleBodyBtm").stop().animate({
					height: "28"
				}, 500 );
		});	
	$("#siteContentsLink").toggle(function(event){
 
			 	$("#pageMiddleBodyBtm").stop().animate({
					height: "80"
				}, 500 );
			 
			}, function(event){
				
			 	$("#pageMiddleBodyBtm").stop().animate({
					height: "28"
				}, 500 );
		});	
}

function validateForm(){

	$("#login").validate({
		submitHandler: function( form ) {
			//debug:true
			location.reload(); 
		},
		rules:{
			username:{
				required: true,
				email: true
			},
			password:{
				required: true
			}
		},
		messages:{
			username: "",
			password: ""
		}
	});

}

function setupRedDot( $btn ){
	
	var theBtn = "#" + $btn;
	$(theBtn).hover(function(event){
 
			 	$(theBtn).stop().animate({
					backgroundColor: "#c70000"	
				}, 350 );
				
				$('h2', theBtn).stop().animate({
					color: "#ffffff"	
				}, 350 );
			 
			}, function(event){
				
			 	$(theBtn).stop().animate({
					backgroundColor: "#f0f0f0"	
				}, 350 );
				
				$('h2', theBtn).stop().animate({
					color: "#c70000"	
				}, 350 );
		});	
}

function resizeWindow( e ) 
{
	var h = $("body").height() + 80;
	var winW = $(window).width();
	var winH = $(window).height();
	var imgH = $("#bgImage").height();
	
	if( h > winH ){	$( "#bodyContainer" ).css( "height", h ); }	else { $( "#bodyContainer" ).css( "height", winH ); }
	$( "#bgImageContainer" ).css( "width", winW );		
	$( "#bgImageMask" ).css( "width", winW );
	$( "#bgImage" ).css( "width", winW );	
	$( "#bgImageContainer" ).css( "height", h );
	
	if( winH > 500 && winW > imageMinW )
	{ 
		if( (winW * ratio - 160) <= winH - 360 )
		{
			$( "#pageTop" ).css( "height", winW * ratio - 160 ); 
		}
		else
		{
			if( winH - 360 > 290 )
			{
				$( "#pageTop" ).css( "height", winH - 360 ); 
			}
			else
			{
				$( "#pageTop" ).css( "height", 290 ); 
			}
		}
	} 
	else
	{ 
		//alert( winH );
		$( "#pageTop" ).css( "height", 290 ); 
	}
	
	if( winW >= imageMinW  )
	{	
		$( "#bgImage img" ).css( "width", winW );	
		//var tempHeight = $( "#bgImage img" ).height();
		
		$( "#bgImageMask" ).css( "height", winW * ratio );
		//alert( w*ratio);
	}
	else
	{
		$( "#bgImage img" ).css( "width", "1200px" );	
		$( "#bgImageMask" ).css( "height", "450px" );
	}
}

