/*
Author: Joe Tan (joetan54@gmail.com)

THIS FILE MAY NOT BE DISTRIBUTED WITHOUT PERMISSION.
*/

jQuery(function($) {
	$('#searchform input[type=text]').focus(function() {
		if ($(this).attr('defaultValue') == $(this).val()) $(this).val('')
	}).blur(function() {
		if ($(this).val() == '') { $(this).val($(this).attr('defaultValue'))}
	});
});

// featured
jQuery(function($) {
	$('#featured #next').click(function() {
		if ($('#featured').data('timer')) {
			clearTimeout($('#featured').data('timer'))
			$('#featured').data('timer', false)
		}
		gotoNext()
		return false;
	});
	$('#featured #prev').click(function() {
		if ($('#featured').data('timer')) {
			clearTimeout($('#featured').data('timer'))
			$('#featured').data('timer', false)
		}
		gotoPrev()
		return false;
	});
	$('#featured .imageElement:not(:first)').hide()
	$('#featured').data('timer', setTimeout(autoScroll, 9000))
});

function autoScroll() {
	var $ = jQuery
	gotoNext()	
	$('#featured').data('timer', setTimeout(autoScroll, 9000))
}

function gotoNext() {
	var $ = jQuery
	var slide = $('#featured .imageElement:visible')
	var next = slide.next()
	if (next.length > 0) {
		gotoSlide(next)
	} else {
		gotoSlide($('#featured .imageElement:first'))
	}
}
function gotoPrev() {
	var $ = jQuery
	var slide = $('#featured .imageElement:visible')
	var next = slide.prev()
	if (next.length > 0) {
		gotoSlide(next)
	} else {
		gotoSlide($('#featured .imageElement:last'))
	}

}

function gotoSlide(slide) {
	var $ = jQuery
	if (slide.length > 0) {
		slide.fadeIn('fast').siblings().fadeOut('fast')
	}
}
