var $$ = jQuery.noConflict();
var AllImages;
var CurrentImage = -1;
var Slideshow;

$$(document).ready(function()
{
	initializeFrontPage();
});


function initializeFrontPage()
{
	var AddButton = $$("<div class='Label'></div>");
	wireFalseButtons();
	AddButton.append($$('<div class="GlowText"></div>'));
	for (var top=-1;top<2;top++)
	{
		for (var left=-1;left<2;left++)
		{
			var Shadow=$$('<div class="Aura"></div>');
			$$(Shadow).css("left", left);
			$$(Shadow).css("top", top);
			AddButton.append(Shadow);
		}
	}
	AllImages = $$('div.Rotator img');
	$$('div.Rotator').append(AddButton);
	$$('div.Rotator img').hide();
	wireAnimationsToButton($$('div.Rotator button'));
	NextImage();
	$$('div.Overlay').fadeOut();
	Slideshow = setInterval('NextImage();', 2000);
	$$('div.Rotator button').click(function()
	{
		clearInterval(Slideshow);
		NextImage();
	});
	
}

function wireAnimationsToButton(buttons)
	{
		buttons.mouseenter(function()
		{
			$$(this).not('.DoNotAnimate').animate({ backgroundColor: "#CAAE92" }, 250).animate({ backgroundColor: "#AA8E72" }, 250);
		});
		buttons.mouseleave(function()
		{
			$$(this).not('.DoNotAnimate').stop(true, false).animate({ backgroundColor: "#816f47" }, 300);
		});
	} 

function NextImage()
	{
		$$(AllImages[CurrentImage]).fadeOut();
		CurrentImage += 1;
		if (!AllImages[CurrentImage])
		{
			CurrentImage = 0;
		}
		$$(AllImages[CurrentImage]).fadeIn();
		setImageLabelToValue();
	}

function setImageLabelToValue()
{
	$$('div.Rotator div.Label div').html((CurrentImage+1) + "/" + AllImages.length);
}

function wireFalseButtons()
{
	$$('<img/>')[0].src = 'graphics/ButtonPressed.jpg';

	$$('a.FrontPageSpecialButton').mousedown(function()
	{
		$$(this).css('background-image', "url('graphics/ButtonPressed.jpg')");
		$$(this).children('span').css('left', '1px');
		$$(this).children('span').css('top', '86px');
		$$(this).children('img').css('left', '10px');
		$$(this).children('img').css('top', '11px');
	});
	$$('a.FrontPageSpecialButton').mouseup(function()
	{
		$$(this).css('background-image', "url('graphics/ButtonUnpressed.jpg')");
		$$(this).children('span').css('left', '0px');
		$$(this).children('span').css('top', '85px');
		$$(this).children('img').css('left', '9px');
		$$(this).children('img').css('top', '10px');
	});
}
