// Setup JS events when the DOM is ready
$(document).ready(function(){
	$(".search_box").focus(clearbox);
	$(".search_box").blur(clearbox);
	if ($("#banners").length > 1) $.slideshow('banners', 4000);	
});

// jQuery fader
// Based on: http://portfolio.gizone.co.uk/applications/slideshow/
$.slideshow = function (containerId, timeout) {
	var current = 0;
	var id = '#' + containerId;
	$(id).css({position:'relative'});
	var slides = $(id).children().get();
	for ( var i = 0; i < slides.length; i++ ) {
		$(slides[i]).css({zIndex:(slides.length - i), position:'absolute', top:'0', left:'0'});
	}
	setTimeout((function(){$.slideshow.next(slides, timeout, current);}), timeout);
}
$.slideshow.next = function (slides, timeout, current) {
	for (var i = 0; i < slides.length; i++) {
		var slide = slides[(current + i) % slides.length];
		$(slide).css({zIndex:(slides.length - i)});
	}
	// IE doesn't seem to support .show() after it has been faded out, so we use .fadeIn("fast")
	$(slides[current]).fadeOut('slow', 
			function(){$(slide).css({zIndex:'0', opacity:1}).fadeIn("fast");}
			);
	
	current = (current + 1) % slides.length;
	setTimeout((function(){$.slideshow.next(slides, timeout, current);}), timeout);
}


// Reset default text in input box
function clearbox()
{
    if (!this.default_value) this.default_value = this.value;
    
    if (this.value == '') {
        this.value = this.default_value;
    } else if (this.value == this.default_value) {
        this.value = '';
    }
}

// Jump to url
function jump_to_url(url)
{
	if (url == "") return false;
	location.href = "/" + url;
}

// Show admin popup window
function admin_popup(url)
{
	var win = window.open(url,'_adminedit','height=650,width=675,resizable=yes,dependent,scrollbars=yes');
	win.focus();
}