$(document).ready(function(){
	//FADE
	$('#fade').innerfade({
		speed: 1500,
		timeout: 4000,
		type: 'sequence',
		containerwidth: '350px',
		containerheight: '260px'
	});
	
	$('#fade2').innerfade({
		speed: 1500,
		timeout: 4000,
		type: 'sequence',
		containerwidth: '263px',
		containerheight: '193px'
	});
	
	//INPUT ELEMENTS	
		var st = '#4c4c4c';
		var en = '#9a9a9a';
		
		$('input[type=hidden]').each(function(){
			$(this).css('display', 'none');
		});
			
		$(':input').focus(function(){
			if($(this).val() == $(this).attr('rel')){
				$(this).css('color', en);
				$(this).keydown(function(){
					if($(this).val() == $(this).attr('rel')){					
						$(this).val('');
						$(this).css('color', st);
					}
				});
			}
		}).blur(function(){
			if($(this).val() == '' || $(this).val() == $(this).attr('rel')){
				var atty = $(this).attr('rel');
				$(this).val(atty).css('color', st);
			}
		});
		
		//CHECKBOX
		$('input[type=checkbox]').each(function(){
			$(this).css({'display' : 'inline', 'width' : 'auto', 'padding' : '0px', 'margin-right' : '5px'});
		});
	//INPUT ELEMENTS
	
	//FIND LOGO
	$('#logo').css('cursor', 'pointer').bind({
		click: function(){
			window.location = './?page=home';	
		}
	});
	
	$('#foot_logo').css('cursor', 'pointer').bind({
		click: function(){
			window.location = './?page=home';	
		},
		mouseenter: function(){
			$(this).fadeTo(500, 0.5);
		},
		mouseleave: function(){
			$(this).fadeTo(500, 1.0);
		}
	});
	
	//CLEANING UP MARGINS AND JUNK
	$('#navbar a:last').css('margin-right', '0px');
	$('#navbar a:first').css('margin-left', '0px');
	
	//HOME CAL
	$('.cal').bind({
		click: function(){
			if($(this).attr('rel') == undefined){
				window.location = './?page=calendar';	
			}else{
				window.location = './?page=calendar&'+$(this).attr('rel');	
			}			
		},
		mouseenter: function(){
			fC = $(this).css('color');
			$(this).css('color', '#000000');
		},
		mouseleave: function(){
			$(this).css('color', fC);
		}
	});
	
	//CALENDAR SHOW
	$('.showDescription').toggle(function(){
		$(this).next().show(1000);
		$(this).css('font-weight', 'bold');
	},function(){
		$(this).next().hide('slow');
		$(this).css('font-weight', 'normal');
	});
	
	//CENTER BUTTONS
	fw = 0;
	zw = 0;
	$('#navbar a').each(function(){
		mW = $(this).width();
		mL = parseFloat($(this).css('margin-left'));
		mR = parseFloat($(this).css('margin-right'));
		pL = parseFloat($(this).css('padding-left'));
		pR = parseFloat($(this).css('padding-right'));
		bW = parseFloat($(this).css('border-width'));
		
		if(isNaN(mW))mW=0;
		if(isNaN(mL))mL=0;
		if(isNaN(pL))pL=0;
		if(isNaN(pR))pR=0;
		if(isNaN(bW))bW=0;
		
		if(bW == 0)bW=2;
		
		zw = mW+mL+mR+pL+pR+bW;
		fw = zw+fw;
	});
	
	bod = $('#body').width();
	dd = bod - fw;
	fd = dd/2;
	fin = (Math.floor(fd));
	$('#navbar').css('margin-left', fin+'px');
	
	//PRELOAD IMAGES
	(function($){
		var cache = [];
		// Arguments are image paths relative to the current page.
		$.preLoadImages = function() {
			var args_len = arguments.length;
			for (var i = args_len; i--;) {
				var cacheImage = document.createElement('img');
				cacheImage.src = arguments[i];
				cache.push(cacheImage);
			}
		}
	})(jQuery)
	
	$.preLoadImages('images/nav_bg.png', 'images/inner_bg_alt.png');

	
	//GET LINE HEIGHT
	var h1 = $('#left').height();
	var h2 = $('#right').height();
	if(h1 > h2){
		$('#line').css('height', h1+'px');
	}else{
		$('#line').css('height', h2+'px');	
	}
});
