// JavaScript Document

/*

	imageOverChange JS
	inputAutoEdit JS
	pageScroller JS
	zebra efect JS
	fadeImageGallery JS

*/
	
/*---------------------------------------------------------

	imageOverChange JS

---------------------------------------------------------*/
(function($) {
	$.fn.imageOverChange = function(options) {
		var element = this;
		// Option
		var conf = $.extend({
			animate:		false,
			animateOpacity: 0.4,
			animateSpeed: 	800,
			hoverImage: 	"_on",
			// ImageOver Cancel 
			changeCance: 	"activeImg"
		}, options);
		
		element.each(function(){
			var thisSrc = this.src;
			// image Preload
			if(thisSrc.indexOf("_off.") > 1){
				var hoverSrc = thisSrc.replace("_off.",conf.hoverImage + '.');
				var preloadImages = $("<img>").attr("src", hoverSrc);
			}
			// Hover Event
			$(this).hover(function(){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",hoverSrc);
				}
				if(conf.animate){
					$(this).css({opacity: 1});
					// $(this).stop().animate({opacity: conf.animateOpacity}, 0).animate({opacity: 1}, conf.animateSpeed);
					$(this).stop().animate({opacity: conf.animateOpacity}, conf.animateSpeed);
				}
			},function (){
				if(!$(this).hasClass(conf.changeCance)){
					$(this).attr("src",thisSrc);
				}
				if(conf.animate){
					$(this).stop().animate({opacity: 1}, conf.animateSpeed);
				}
			});
		});
		return this;
	}
})(jQuery);

$(function(){
	$("a img, input.imgover").imageOverChange({
		animate: true,
		animateOpacity: 0.7,
		animateSpeed: 150
	});
});
/*---------------------------------------------------------

	 inputAutoEdit JS

---------------------------------------------------------*/
(function($) {
	$.fn.inputAutoEdit = function(options) {
		var element = this;
		// Option
		var conf = $.extend({
			targetInput:	"clearTarget",
			hasvalClass:	"hasval",
			submitBtClass:	"submitBt"
		}, options);

		// load Edit
		$("input:text,textarea",element).each(function(){
			if(!this.title == ""){
				$(this).val($(this).attr("title")).addClass(conf.targetInput);
			}

			// Foucus Event
			$("." + conf.targetInput,element).focus(function() {
				if($(this).val() == $(this).attr("title")) {
					$(this).val("").addClass(conf.hasvalClass);
				}
			});
	
			// Blur Event
			$("." + conf.targetInput,element).blur(function() {
				if($(this).val() === '') {
					$(this).val($(this).attr("title")).removeClass(conf.hasvalClass);
				}else {
					$(this).addClass(conf.hasvalClass);
				}
			});
		});

		// Click Event
		$("." + conf.submitBtClass,element).click(function(){
			$("." + conf.targetInput,element).not("." + conf.hasvalClass).val("");
		});

		return this;
	}
})(jQuery);

$(function() {
	$("#siteSarch form").inputAutoEdit();
});
/*---------------------------------------------------------

	pageScroller JS

---------------------------------------------------------*/
(function($) {
	$.fn.pageScroller = function(options){
		var element = this;
		// Option
		var conf = $.extend({
			ScrollSpeed:		800
		}, options);
		
		// Quart Easing
		jQuery.easing.quart = function (x, t, b, c, d) {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		};
		
		// Chrome hack
		$("a[name]").each(function(){
			var contents = $(this).html();
			if(jQuery.browser.webkit && contents == ""){
				$(this).css({
					display: "block"
				});
			}
		});
		
		// Click Event
		$("a[href^=#]",element).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;
					var bodyHeight = $("body").height();
					var flameHeight = $(window).height();

					if(bodyHeight < targetOffset + flameHeight){
						var targetOffset = bodyHeight - flameHeight;
					}

					$("html,body").animate({ scrollTop: targetOffset },{
						duration: conf.ScrollSpeed,
						easing: "quart",
						// mousewheel Event bind
						step:function(){
							$(document).bind("DOMMouseScroll mousewheel",function() {
								$("html,body").stop();
								wheelUnbind();
							});							
						},
						complete:function(){
							wheelUnbind();
						}
					});
					// mousewheel Event UnBind
					var wheelUnbind = function(){
						$(document).unbind("DOMMouseScroll mousewheel");
					}
					return false;
				}
			}
		});
		
	return this;
	};
})(jQuery);

$(function(){
	$(".toPageTop").pageScroller();
	$("#container").pageScroller();
});
/*---------------------------------------------------------

	 zebraEffect

---------------------------------------------------------*/
(function($) {
	$.fn.zebraEffect = function(options){
		var element = this;
		// Option
		var conf = $.extend({
			nttchildClass:		"zebra"
		}, options);
		
		$(element).each(function(){
			var tagname = $(this).get(0).tagName;
			if(tagname == "TABLE"){
				$("tr:nth-child(even)",element).addClass(conf.nttchildClass);
			}
			if(tagname == "UL"){
				$("li:nth-child(even)",element).addClass(conf.nttchildClass);
			}
		});
	return this;
	};
})(jQuery);

$(function(){
	$(".zebraList").zebraEffect();
});
/*---------------------------------------------------------

	 zebraEffect

---------------------------------------------------------*/
(function($) {
	$.fn.addChildClass = function(options){
		var element = this;
		// Option
		var conf = $.extend({
			firstChildClass:		"firstChild",
			lastChildClass:			"lastChild"
		}, options);
		
		$(element).each(function(){
			$(element).children("li").last().addClass("lastChild");
		});


	return this;
	};
})(jQuery);

$(function(){
	$("#locNav").addChildClass();
});
