/**---------------------------------
 * common.js
 * 
 * ...
 * author	: takaaki koyama
 * url 		: http://www.sph62.net
 * mail		: sph62.net@gmail.com
 *
 * @use jQuery 1.2.6 later
 ---------------------------------*/
$(document).ready(function(){
//rollover	
// switching image xxx_off.xxx -> xxx_on.xxx
// if image name is bnr_xxxx or btn_xxx which don't has neme _off , _on
// fade effect on mouse over.
	$("a img[src*='_on']").addClass("current");
	
	$("a img").mouseover(function(){
		if ($(this).attr("src").match(/_off./)){
			$(this).attr("src",$(this).attr("src").replace("_off.", "_on."));
			return;
		}else if($(this).attr("src").match(/btn_/) || $(this).attr("src").match(/bnr_/) ){
			$(this).fadeTo("50",0.6);
			return;
		}
	});

	$("a img[class!='current']").mouseout(function(){
		if ($(this).attr("src").match(/_on./)){
			$(this).attr("src",$(this).attr("src").replace("_on.", "_off."));
			return;
		}else if($(this).attr("src").match(/btn_/) || $(this).attr("src").match(/bnr_/) ){
			$(this).fadeTo("50",1);
			return;		
		}
	});
// pingfix
	//$(this).pngFix();

// popup
// class="popup400x600" -> window.open(this.href,"popup","width=400,height=600,...)
	$("a[class^='popup']").click(function(){
		var className = $(this).attr("class").match(/^popup([0-9]{1,})x([0-9]{1,})/);				
		var width = RegExp.$1;
		var height = RegExp.$2;
		var state = "width="+width+",height="+height+",";
		state += "location=no,toolbar=no,directories=no,";
		state += "status=yes,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes";
		window.name = "root";
		window.open(this.href,className[0],state);
		return false;
	});
	// open in popup parent window.
	// add class="openParentWin" on a-tag in a popup window.
	$("a.openParentWin").click(function(){
		window.open(this.href,"root");
		return false;
	});
	
// target _blank auto add
	var domains = [document.domain,"www.hivkensa.com","hivkensa.com"];
	var domain_selector = ""
	var left_str= ":not([@href^=http://";
	var left_str_https= ":not([@href^=https://";
	var right_str = "])";
	domain_selector = left_str+domains.join(right_str+left_str)+right_str;
	domain_selector+= left_str_https+domains.join(right_str+left_str_https)+right_str;
	$("a[@href^=http]:not([@class^=popup])"+domain_selector+", area[@href^=http]:not([@class^=popup])"+domain_selector)
	.addClass("external");
	
	//if has class .extenal -> open _blank window
	$("a.external").click(function(){
		window.open(this.href,"_blank");
		return false;
	});
	
//Smooth Scroll
	$('a[href^=#]').click(function() { 
		var target = $(this.hash); 
		if(target.size()) { 
			var top = target.offset().top;
			$($.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 800, 'swing'); 
		} 
		return false; 
	}); 
	
});