
$(document).ready( function() {

	// Fix IE 6
	if( IE6 ) {
		// cached background images
		document.execCommand("BackgroundImageCache",false,true);

		// PNGs
		$("img[src$='.png']").each(function() {
			var src = '/' + $(this).attr('src');
			$(this).attr("src", "http://www.dynamit.us/img/spacer.gif").attr("style", "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "');");
		});
	}

	
	// Forms and Stuff.
	$('input, textarea').focus( function() {
		if( $(this).val() == $(this).attr('title') ) {
			$(this).val('');
		}
	}).blur( function() {
		if( $(this).val() == '' ) {
			$(this).val( $(this).attr('title') );
		}
	});


	// Hover class for <li> in main nav (li:hover backup)
	$('ul#nav li').hover(
		function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		}
	);
	
	
	// Init home page carousel
	if($('ul#carouselitems li').length > 1) {
		$('ul#carouselnav li').click(function(){
			clearTimeout(carouselTO);
			index = $(this).index();
			$(this).siblings().removeClass('active');
			$(this).addClass('active');
			$('ul#carouselitems li').removeClass('active');
			$('ul#carouselitems li').eq(index).addClass('active');
			carouselTO = setTimeout('nextCarousel()', 7000);
			return false;
		});
		carouselTO = setTimeout('nextCarousel()', 7000);
	}


});


// Home page carousel
function nextCarousel() {
	$activeitem = $('ul#carouselitems li.active');
	var activeindex = $activeitem.index();
	var lastindex = $('ul#carouselitems li:last-child').index();
	var nextindex = 0;
	if(activeindex < lastindex) nextindex = activeindex + 1;
	$nextitem = $('ul#carouselitems li').eq(nextindex);
	
	$nextitem.css('left', '0px');
	$activeitem.animate({
		opacity: 0
	}, 1000, function(){
		$activeitem.css('left', '-99999px');
		$activeitem.removeClass('active');
		$nextitem.addClass('active');
		$('ul#carouselitems li').removeAttr('style');
		$('ul#carouselnav li').removeClass('active');
		$('ul#carouselnav li').eq(nextindex).addClass('active');
	});
	
	carouselTO = setTimeout('nextCarousel()', 7000);
};

