/* common.js require jQuery */

$(function(){
	
	//
	// Smart Rollover
	//
	
	(function(){
		var tags = ["img","input"];	
		for(var i=0; i<tags.length; i++){
			$(tags[i]).each(function(){
				if (!this.src.match(/^(.*_)out(\..*)$/)) return;
				var out = this.src;
				var over = RegExp.$1+"over"+RegExp.$2;
				var img = $("<img/>").attr("src", over);
				var onOver = (function(_over){
					return function(e){
						if (!this.src.match(/^(.*_)out(\..*)$/)) return;
						var img = e.target || window.event.srcElement;
						img.src = _over;
					}
				})(over);
				
				var onOut = (function(_out){
					return function(e){
						if(e.target || window.event.srcElement){
							var img = e.target || window.event.srcElement;
							img.src = _out;
						}
					}
				})(out);
				
				$(this).hover(onOver, onOut);
				$(this).unload(onOut);
			});
		}
	})();

	//
	// Smooth Scroll
	//
	
	$("a[href*=#]").click(function(){
		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
			&& location.hostname == this.hostname)
		{
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length){
				var targetOffset = $target.offset().top;
				$("html,body").animate({scrollTop: targetOffset}, 500, "easeOutExpo");
				return false;
			}
		}
	});
});

