var lastElementName = '#about_studio_buffalo_content';
var menuIsOpen = false;
var prevMenuItemColor = '';
var prevSliderMenuItemColor = '';

$(document).ready(function()
{
	popupStatus = 0;
	
	$('div.single_image').hover(
		function()
		{
			$(this).css({ 'z-index': 100 });

			$(this).find('img').addClass("hover").stop().animate(
			{
				marginTop: '-19px',
				marginLeft: '-19px',
				top: '9px',
				left: '9px',
				width: '212px',
				height: '182px',
				padding: '9px'
			}, 200);
		},
		function()
		{
			$(this).find('img').removeClass("hover").stop().animate(
			{
				marginTop: '0px',
				marginLeft: '0px',
				top: '0px',
				left: '0px',
				width: '192px',
				height: '162px',
				padding: '0px'
			}, 200);
			
			$(this).css({ 'z-index': 1 });
		}
	);

	$('div.popup_background').click(
		function()
		{
			$('div.popup_background').fadeOut("slow");
			$(shownBackgroundElem).fadeOut("slow");

			popupStatus = 0;
		}
	);

	$('div#slider_head').click(
		function()
		{
			if(menuIsOpen == false)
			{
				$('div#slider_menu').stop().animate({ 'width' : '650px' }, 1000);
				menuIsOpen = true;
			}
			else
			{
				$('div#slider_menu').stop().animate({ 'width' : '50px' }, 1000);
				menuIsOpen = false;
			}
		}
	);
	
	$('div.menu_text_hover').hover(
		function()
		{
			if(!$(this).is('.clicked'))
			{
				prevMenuItemColor = $(this).css('color');
				$(this).css({ 'color' : '#FFFFFF' });
			}
		},
		function()
		{
			if(!$(this).is('.clicked'))
			{
				$(this).css({ 'color' : prevMenuItemColor });
			}
		}
	);
	
	$('div.slider_menu_text_hover').hover(
		function()
		{
			if(!$(this).is('.clicked'))
			{
				prevSliderMenuItemColor = $(this).css('color');
				$(this).css({ 'color' : '#9F9E9E' });
			}
		},
		function()
		{
			if(!$(this).is('.clicked'))
			{
				$(this).css({ 'color' : prevSliderMenuItemColor });
			}
		}
	);
	
	$('div.menu_text_click').click(function()
	{
		$('div.clicked').css({ 'color' : prevMenuItemColor });
		$('div.clicked').removeClass('clicked');
		$(this).addClass('clicked');
		$('div.clicked').css({ 'color' : '#FFFFFF' });
	});
	
	// Some images do not need the hover effect, like the flash movie.
	$('.no_hover').parent('.single_image').unbind('mouseenter mouseleave');
});

function centerPopup(element)
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(element).height();
	var popupWidth = $(element).width();
	
	$(element).css(
	{
		"position": "absolute",
		"top": windowHeight/2 - popupHeight/2,
		"left": windowWidth/2 - popupWidth/2
	});
}

function showContent(elementName, openPopup)
{
	if(openPopup == true)
	{
		showInfoScreen();
		
		menuItemElementName = elementName.substr(0, (elementName.length - '_content'.length));
		
		$('div.clicked').css({ 'color' : prevMenuItemColor });
		$('div.clicked').removeClass('clicked');
		$(menuItemElementName).find('div.menu_text_click').addClass('clicked');
		$('div.clicked').css({ 'color' : '#FFFFFF' });
	}
	
	if(elementName != lastElementName)
	{
		$(lastElementName).hide();
		$(elementName).show();
		lastElementName = elementName;
	}
}
