/* 
==================================================================================================== */
$.fn.rollOver = function(){
	return this.each(function(){
		var offReg = new RegExp(/(.+)_off\.(gif|jpg|jpeg|png)$/);
		var onReg = new RegExp(/(.+)_on\.(gif|jpg|jpeg|png)$/);
		if($(this).attr("src").match(offReg)){
			$("<img>").attr("src",$(this).attr("src").replace(/(.+)_off\.(gif|jpg|jpeg|png)$/,"$1_on.$2"));
			$(this).bind(
				"mouseover",function(){ $(this).attr("src",$(this).attr("src").replace(/(.+)_off\.(gif|jpg|jpeg|png)$/,"$1_on.$2")); }
			);
			$(this).bind(
				"mouseout", function(){ $(this).attr("src",$(this).attr("src").replace(/(.+)_on\.(gif|jpg|jpeg|png)$/,"$1_off.$2")); }
			);
		}
	});
};





/* 
==================================================================================================== */
$.fn.keywordBox = function(){
	return this.each(function(){
		if(this.value!="") $(this).addClass("entered");
		$("<img>").attr("src","/common/images/search_field_on.gif");
		$(this).bind(
			"focus",function(){ $(this).addClass("entered"); }
		).bind(
			"blur",function(){ if(this.value=="") $(this).removeClass("entered"); }
		);
	});
};





/* 
==================================================================================================== */
$.fn.checkKeywordBox = function(){
	return this.each(function(){
		$(this).bind("submit",function(){ return ($("#footer .keyword").attr("value")!=""); });
	});
};





/* 
==================================================================================================== */
$.fn.pagetop = function(){
	return this.each(function(){
		var pos = function(){
			var st = $(this).scrollTop();
			var ct = $("div#contents").offset().top;
			var fp = (this.innerHeight|document.documentElement.clientHeight) - 190;
			var bh = $("p#pageTop img").attr("height");
			var ch = $("div#container").height();
			var adjTop    = 0;
			var adjBottom = 0;
			if($("body#sitemap").size()>0){
				adjTop = $("div#pageList").offset().top - $("div#contents").offset().top;
				adjBottom = 67;
			}
			var ypos = st + fp - ct - bh;
			if(ch-ypos-adjBottom<bh)	ypos = ch - bh - adjBottom;
			if(ypos<adjTop) ypos = adjTop;
			return ypos;
		};
		var fix = function(){
			$("p#pageTop").stop().animate({ top:pos()+"px" },"slow");
		};
		$(this).css("top",pos()+"px");
		$(window).scroll(fix);
		$(window).resize(fix);
		$(this).bind("click",function(e){
			window.scroll(0,0);
			e.preventDefault();
		});
	});
};




/* 
==================================================================================================== */
$.fn.develop = function(){
	return this.each(function(){
		
		/*
		$("a[href=#]").css("border","solid #FF0000 2px");
		$("div#wrapper").bind("click",function(){
			$("a[href=#]").css("border","none");
		});
		*/
		
		/*
		$("<div>").attr("id","message")
		.css("width",20)
		.css("height",20)
		.css("background","#FFDDDD")
		.css("position","fixed")
		.css("top",0)
		.css("left",0)
		.appendTo($("body"));
			*/
			
	});
};


/* 
==================================================================================================== */
$(function(){
 $("img.rollover,input.rollover").rollOver();
	$("#footer .keyword").keywordBox();
	$("#siteSearch").checkKeywordBox();
	$("p#pageTop").pagetop();
	//$("body").develop();
});
