$(function() {	
	OTD.init();
	$("a.rollover img, input.rollover").mouseover(
		function() { 
			this.src = this.src.replace(".png", "-over.png");
		}).mouseout(
		function() {
			this.src = this.src.replace("-over", "");
		}).each(
			function(i) {
				(new Image()).src = this.src.replace(".png", "-over.png");				
			}
		);		
	$("#searchText").val("search").focus(
		function() {
			if(this.value == "search") {
				this.value = ""
			}			
		}).blur(
		function() {
			if(this.value == "") {
				this.value = "search"
			}			
		});
	$("a.rollover").each(
		function(i) {			
			if(window.location.href.startsWith(this.href)) {
				var img = $(this).find("img")[0];				
				img.src = img.src.replace(".png", "-over.png");
				$(img).unbind();				
			}
		});	
	$("#subnav li").each(
		function(i) {
			var a = this.href ? this : $(this).find("a")[0];			
			if(window.location.href.startsWith(a.href)) {								
				$(this).addClass("selected");		
			}
		});
	$("#vLookupForm").bind("submit",
		function() {
			var dv = $("#deliveryVerify");
			$("#dvLoading").slideDown("fast");
			dv.slideUp("fast");				
			$.post(this.action.toAjaxPath(), $(this).formSerialize(), OTD.displayVerifyResults);
			return false;
		});
	$("#deliveryVerify").before('<p id="dvLoading"><img src="' + webroot + 'img/loading4.gif" /> Checking...</p>');
	$("#dvLoading").hide();
});



var OTD = {
	init:
		function() {
			String.prototype.toAjaxPath = function() {return this + "_ajax";};
		},
	displayVerifyResults: 
		function(c) {
			var dvr = $("#deliveryVerifyResults");
			$("#dvLoading").slideUp("fast");			
			dvr.html(c + "<p><a href='javascript:OTD.displayVerifyForm();'>Search Again</a></p>");						
			dvr.slideDown("fast");
		},
	displayVerifyForm:
		function() {			
			$("#deliveryVerify").slideDown("fast");
			$("#deliveryVerifyResults").slideUp("fast");
		}
};