jQuery(document).ready(function(){

	// Horizontal scroller.
//	var width = jQuery("#scrollerWindow dl dd").outerWidth(true);	//This can only be used with later versions of jQ as in the one in wp26.
	var width = jQuery("#scrollerWindow dl dd").width() + 20;
	var count = jQuery("#scrollerWindow dl dd").size();
	var previousPost = 0;
	var scrollChangeRate = 7000; // 7 seconds
	var scrollChangeInterval = setInterval(nextPost,scrollChangeRate);

	jQuery("#scrollerWindow dl").css({width:count * width})			// Set the width of the container

	function nextPost() {
		scrollToPost((previousPost + 1) % count);
	}

	function scrollToPost(i){
		clearInterval(scrollChangeInterval);

		if (previousPost != i)
			jQuery("#scrollerWindow dl").stop();

		jQuery("#scrollerLinks").children("li").removeClass("active");
		jQuery("#scrollerLinks li a.bob:eq("+i+")").parent("li").addClass("active");
		jQuery("#scrollerWindow dl").animate({left:"-"+i*width+"px"},{duration:1000});

		scrollChangeInterval = setInterval(nextPost,scrollChangeRate);

		previousPost = i;
		return true;
	}

	jQuery("#scrollerLinks li a.bob").each(function(i){
		jQuery(this).click(function() {
			scrollToPost(i);
			return false;
		})
	});

	// Pause on mouse over scrollerWindow.
	jQuery("#scrollerWindow").hover(function(){
		clearInterval(scrollChangeInterval);
		jQuery("#scroller .pause").fadeIn(500);
	},function(){
		clearInterval(scrollChangeInterval);
		scrollChangeInterval = setInterval(nextPost,scrollChangeRate);
		jQuery("#scroller .pause").fadeOut(500);
	});

	//Search Widget
	var theText = "Enter text";
	jQuery(".widget_search form input[name=s]").each(function(){
		if (jQuery(this).attr("value") == "" || jQuery(this).attr("value") == undefined) {
			jQuery(this).attr({value:theText})
		}

		jQuery(this).focus(function(){
			if (jQuery(this).attr("value") == theText){
				jQuery(this).attr({value:""})
			}
			jQuery(this).addClass("focused");
		});

		jQuery(this).blur(function(){
			if (jQuery(this).attr("value") == "" || jQuery(this).attr("value") == undefined)
				jQuery(this).attr({value:theText});
			jQuery(this).removeClass("focused");
		});
	})

	jQuery(".widget_search form").submit(function(){
		currentValue = jQuery(this).find("input[name=s]").attr("value");

		if (currentValue == "" || currentValue == theText || currentValue == undefined) {
			jQuery(this).append('<p class="errorMessage">Oops! Try again.</p>');

			errorMessage = jQuery(this).children(".errorMessage").hide();
			errorMessage.fadeIn(500).fadeOut(1000,function(){jQuery(this).remove();});

			return false;
		} else {
			return true;
		}
	});

	jQuery("input[type='submit']").addClass("submit");

	// Zebra stripe tables the easy way.
	jQuery(".postBody table tr:odd").addClass("alternate");

	jQuery(".postBody li").hover(function(){jQuery(this).addClass("highlight");},function(){jQuery(this).removeClass("highlight");});

	// Fix some IE 6 problems. The sooner ie6 dies the better
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie" && val == true && jQuery.browser.version.substr(0,1) == 6){
			jQuery("#navList li").hover(function(){jQuery(this).addClass("over");},function(){jQuery(this).removeClass("over");});
			jQuery("#importantPages li").hover(function(){jQuery(this).addClass("over");},function(){jQuery(this).removeClass("over");});
		}
		if(!jQuery.boxModel){
			theBody = document.getElementsByTagName("BODY");
			theBody[0].className+=" quirky";
		}
	});

	jQuery("#commentForm").submit(function(){
		var blankFields = false;
		jQuery(this).find(".vital").each(function(){
			value = jQuery(this).attr("value");
			if (value == undefined || value ==  "") {
				blankFields = true;
				jQuery(this).css({borderColor:"#f00"}).fadeOut(250).fadeIn(250);
			} else {
				jQuery(this).css({borderColor:"#ccc"});
			}
		});

		if (blankFields) {
			return false;
		} else
			return true;
	});

});
