/* !javascript Information *****************************
* 
* @Auther cyocun
*
***************************************************** */

$(function() {

	//swap images button
	var postfix = '_o';
	$('.swap').not('[src*="'+ postfix +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.')) + postfix + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(function() {img.attr('src', src_on);},function() {img.attr('src', src);});});
	
	$(".blank").click(function(){
		window.open(this.href,'_blank');
	return false;
	});



	//smooth scroll
	$('a.scroll').click(
		function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname)
				var target = $(this.hash);
				target = target.length && target;
				
				if (target.length)
					var sclpos = 30;
					var scldurat = 1200;
					var targetOffset = target.offset().top - sclpos;
					$('html,body').animate({scrollTop: targetOffset}, {duration: scldurat, easing: "easeOutExpo"});
					return false;
		}
	);
	$('input').keypress(function (e) {
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			return false;
		}
	});


	
	//fadeTo button
	$(document).ready(
	function(){
		$("#header #inquiry img,#bunner img,#pageTop img,#footer ul li a,#confirm,#reset,#imageCont ul li").hover(function(){
			$(this).fadeTo("fast", 0.5); 
		},function(){
			$(this).fadeTo("fast", 1.0); 
		});
	});
});


$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input',this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea')
      this.value = '';
    else if (type == 'checkbox' || type == 'radio')
      this.checked = false;
    else if (tag == 'select')
      this.selectedIndex = -1;
  });
};
