// JavaScript Document

// INPUT FOCUS/CLEAR
function clearText(input){
	if(input.defaultValue==input.value){input.value=''};
}

function restoreText(input){
	if(input.value==''){input.value=input.defaultValue;}
}


// POPUP FUNCTIONALITY
$(function()
{
	$('.popupWrapper').each(function()
	{

		var distance = 10;
		var time = 250;
		var hideDelay = 500;
		var showDelay = 500;
		var showDelayTimer = null;
		var hideDelayTimer = null;

		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);

		var info = $('.popup', this).css('opacity', 0);


		$([trigger.get(0), info.get(0)]).mouseover(function()
		{
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown)
			{
				// don't trigger the animation again
				return;
			} else
			{
				// reset position of info box
				if (showDelayTimer) clearTimeout(showDelayTimer);
				showDelayTimer = setTimeout(function()
				{
					beingShown = true;
	
						info.css({
							top: -110,
							left: -45,
							display: 'block'
						}).animate({
							top: '-=' + distance + 'px',
							opacity: 1
						}, time, 'swing', function()
						{
							beingShown = false;
							shown = true;
						}, hideDelay);
				}, showDelay);
			}

			return false;
		}).mouseout(function()
		{
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (showDelayTimer) clearTimeout(showDelayTimer);
			hideDelayTimer = setTimeout(function()
			{
				hideDelayTimer = null;

					info.animate({
						top: '-=' + distance + 'px',
						opacity: 0
					}, time, 'swing', function()
					{
						shown = false;
						info.css('display', 'none');
					});


			}, hideDelay);

			return false;
		});
	});
});

$(function() {
	$('.archive').each(function() {
	//if(Browser.Engine.trident){
		var zIndexNumber = 1000;
		var itemCount = 0;
		$('li', this).each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
			itemCount++;
			if(itemCount % 6 == 0)
			{
				//alert(itemCount);
				zIndexNumber += 1000;
			}
		});
	});
});



// EVENTS PAGE HIDE/SHOW DIVS
$(function()
{
	$('#calendar li.desc_wrapper').each(function()
	{
		var content = $('.desc', this);
		var trigger = $('.trigger', this);
		
		$(trigger).click(function() {
			$(content).slideToggle();
		});
		
	});
	$('#expand').click(function() {
		$('.desc').slideDown('fast');
	});
	$('#collapse').click(function() {
		$('.desc').slideUp('fast');
	});
});



// TOP NAVIGATINO DROP-DOWN
$(function() {
	$('.mainNav li').each(function() {
		
		var trigger = $('.trigger', this);
		var menu = $('ul', this);
		var arrow = $('span', this);
		var timer;
		
		$(menu).mouseover(function() {
			clearTimeout(timer);
		}).mouseout(function() {
			timer = setTimeout(hideNav, 250)
		});
		
		$(trigger).mouseover(function() {
			clearTimeout(timer);
			$(menu).slideDown();
			$(arrow).css('background-position', '0 -6px');
		}).mouseout(function() {
			timer = setTimeout(hideNav, 250)
		});
		
		function hideNav()
		{
			$(menu).slideUp();
			$(arrow).css('background-position', '0 0');
		}
	});
});


// ON DOCUMENT LOADED:
$(document).ready(function() {
						   
	$('.desc').hide();
	
});
