$(document).ready(function()
{	
	if ( $('#banner_home').length != 0 )
	{
		$('#banner_home').cycle({
			fx: 'none',
			cleartype: true,
			cleartypeNoBg: true,
			requeueOnImageNotLoaded: true,
			before: CycleOnBefore
		});
		
		$('#banner_home').mouseenter(function(){
			$('#banner_home').cycle('pause');
		});
		
		$('#banner_home').mouseleave(function(){
			$('#banner_home').cycle('resume');
		});
	}
	
	$('#eight_days_of_christmas')
		.mouseover(function() {
			$(this).css("cursor", "pointer");	
		})
		.click(function(){ window.location.href='http://www.stmauction.com'; });
		
	$('#bid_o_luck')
		.mouseover(function() {
			$(this).css("cursor", "pointer");	
		})
		.click(function(){ window.location.href='http://events.constantcontact.com/register/event?llr=yzoc8zdab&oeidk=a07e5igqrmq6ae06eb3'; });
		
	$('.main_menu_link').mouseenter(function(){
		$('.main_menu_drop_down').stop(true, true).hide();

		//var id = $(this).text().toLowerCase();
		var id = $(this).attr('title').toLowerCase();
		
		var regExp = /\s+/g;
		id = id.replace(regExp,'_');
	
		var submenu = $('#menu_' + id);
		
		submenu.css({
			position:'absolute',
			top: $(this).parent().offset().top + 'px',
			//left: $(this).offset().left + 146 + 'px',
			left: $(this).parent().offset().left + 200 + 'px',
			zIndex:1000
		});
		
		submenu.stop().slideDown(300);

		submenu.mouseleave(function(){
			$(this).slideUp(300);
		});
		
	});
	
	$('.main_menu_link').mouseleave(function(){
		$('.main_menu_drop_down').stop(true, true).delay(500).slideUp(300);
	});
	
	$('.main_menu_drop_down').mouseenter(function(){
		 $('.main_menu_drop_down').stop(true, true);
	});
});

$(window).load(function() {
	$('.container').css('display','block');
	$('#loading').css('display','none');
	
});

function CycleOnBefore ( )
{
	if (this.alt != '')
	{
		$('#banner_home_quote').show();
		$('#banner_home_quote').html(this.alt);
	}
	else
	{
		$('#banner_home_quote').hide();
	}
}

function FixColumnHeight ( )
{
	var newHeight = 0;
	var minHeight_menu = 433;
	var minHeight_content = 240;
	
	$('#menu_container').css('height', 0);
	
	var menuHeight = $('#menu_container').height();
	var contentHeight = $('#content').height();

	//alert('menuHeight = ' + $('#menu_container').height() + '\n' + 'contentHeight = ' + $('#content').height() + '\n');

	if (contentHeight != null) 
	{		
		if (menuHeight < minHeight_menu && contentHeight < minHeight_content) {
			$('#menu_container').css('height', minHeight_menu + 25);
			$('#content').css('height', minHeight_content);
		}
		else 
			if (menuHeight < minHeight_menu && contentHeight > minHeight_content) {
				var contentHeightDifference = contentHeight - minHeight_content;
				newHeight = menuHeight + contentHeightDifference + minHeight_menu;
				$('#menu_container').css('height', newHeight + 25);
			}
			else 
				if (menuHeight > minHeight_menu && contentHeight < minHeight_content) {
					var menuHeightDifference = menuHeight - minHeight_menu;
					newHeight = menuHeight + menuHeightDifference + minHeight_content;
					$('#content').css('height', newHeight);
				}
	}
	else
	{
		$('#menu_container').css('height', minHeight_menu + 38);
	}
	
	//alert('menuHeight = ' + $('#menu_container').height() + '\n' + 'contentHeight = ' + $('#content').height() + '\n');
}

function Menu_Over (obj)
{
	$(obj).parent().css("background-image", "url('http://www.stmartinsj.org/images/main_nav_mouse_over.png')")
				   .css("background-position", "top left")
				   .css("background-repeat", "repeat-x");
}

function Menu_Out (obj)
{
	$(obj).parent().css("background-image", "url('http://www.stmartinsj.org/images/main_nav_border_2.png')")
				   .css("background-position", "bottom left")
				   .css("background-repeat", "no-repeat");
}

function SubMenu_Out (obj)
{
	$(obj).parent().css("background-image", "")
				   .css("background-color", "#eeeeee");
}

function Random_Homepage_Banner (objArray)
{
	var randomNumber = rand(objArray.length);
	$('#banner_home').css('background-image','url(\'' + objArray[randomNumber] + '\')');
}

function rand ( n )
{
	return ( Math.floor( Math.random() * n ) );
}

function changeFrame ( username )
{
	var obj = document.getElementById( "the_iframe" );
	
	if ( username == "middle_matters" )
	{
		obj.src = 'http://www.stmartinsj.org/content/shared/middle_matters.php';
	}
	else
	{
		obj.src = 'http://pages.stmartin.org/~' + username;
	}
}


