/* ****************************************************
Since : 2007-12-01
**************************************************** */

/* Definition of ...
=================================
1: Utility
2: BasicFunctions

=================================*/

/* 1: Utility
=================================*/
/*-------------------------------------------------------------------
BROWSER OBJECT
-------------------------------------------------------------------*/

function UserAgentDetection(){
	var ua = navigator.userAgent;
	this.ua = {};
	this.ua.isWin     = ua.match(/Win/);
	this.ua.isMac     = ua.match(/Mac/);
	this.ua.isGecko   = (ua.match(/Gecko\//) && ua.indexOf('KHTML') == -1);
	this.ua.isFirefox = (this.ua.isGecko && ua.match(/Firefox/))
	this.ua.isSafari  = ua.match(/AppleWebKit/);
	this.ua.isOpera   = window.opera;
	this.ua.isIE      = (document.all && !this.ua.isOpera);
	this.ua.ver       = navigator.appVersion;
	this.ua.majorver  = parseInt(navigator.appVersion);
;
}
var env = new UserAgentDetection();

/*-------------------------------------------------------------------
DILATATION ARRAY OBJECT
-------------------------------------------------------------------*/
if(!Array.prototype.pop) {
	Array.prototype.pop = function() {
		if(!this.length) {
			return null;
		}
		else {
			var last = this[this.length - 1];
			--this.length;
			return last;
		}
	}
}
if(!Array.prototype.push) {
	Array.prototype.push = function() {
		for (var i = 0, n = arguments.length; i < n; i++) {
			this[this.length] = arguments[i];
		}
		return this.length;
	}
}
if(!Array.prototype.shift) {
	Array.prototype.shift = function() {
		if(!this.length) {
			return null;
		}
		else {
			this.reverse();
			var ret = this.pop();
			this.reverse();
			return ret;
		}
	}
}
if(!Array.prototype.unshift) {
	Array.prototype.unshift = function() {
		this.reverse();
		for (var i = arguments.length - 1; i >= 0; i--) {
			this.push(arguments[i]);
		}
		this.reverse();
		return this.length;
	}
}
if( !Array.prototype.forEach ){
	Array.prototype.forEach = function( callback,thisObject ){
		for(var i=0,len=this.length;i<len;i++) {
			callback.call(thisObject,this[i],i,this);
		}
	}
}
if( !Array.prototype.shuffle ){
	Array.prototype.shuffle = function() {
		var i = this.length;
		while(i)
		{
			var j = Math.floor(Math.random()*i);
			var t = this[--i];
			this[i] = this[j];
			this[j] = t;
		}
		return this;
	}
}

/*-------------------------------------------------------------------
UTILITY MANAGER
-------------------------------------------------------------------*/
function Util(){}

Util.prototype = {
	$: function(el){
		return typeof el == 'string' ? document.getElementById(el) : el;
	},
	getStyle: function(o,s){
		var res;
		try{
			if(document.defaultView && document.defaultView.getComputedStyle){
				res = document.defaultView.getComputedStyle(o, null).getPropertyValue(s);
			} else {
				if(o.currentStyle){
					var camelized = s.replace(/-([^-])/g, function(a,b){return b.toUpperCase()});
					res = o.currentStyle[camelized];
				}
			}
			return res;
		} catch(e){}
		return "";
	},
	setStyle: function( element, styles ){
		if(!element) return;
		for( var key in styles ){
			element.style[key] = styles[key];
		}
	},
	addClassName: function( el, className ){
		el = this.$(el);
		if( !this.hasClassName( el, className ) )
			el.className += ( el.className? " " : "" ) + className;
	},
	removeClassName: function(el, className){
		el = this.$(el);
		if(el.className == null) return;
		var newList = [];
		var curList = el.className.split(/\s+/);

		for(var i = 0; i < curList.length; i++)
			if(curList[i] != className)
				newList[newList.length] = curList[i];
				//newList.push(curList[i]);
		el.className = newList.join(" ");
	},
	hasClassName: function(el, className){
		el = this.$(el);
		if(!el.className) return false;
		return new RegExp("(^|\\s)" + className + "(\\s|$)" ).test( el.className );
	},
	foreach: function( array,callback ){
		var len = array.length;
		for(var i=0;i<len;i++){
			callback(array[i],i,array)
		}
	},
	getCommonDirPath: function(){
		var dirName = arguments.length? arguments[0] : 'common';
		var links = document.getElementsByTagName('LINK');
		var reg = new RegExp( "(.*\/?" + dirName + "\/).+$" );
		if( links ){
			for( var i=0; i<links.length; i++ ){
				if( links[i].getAttribute("rel") && links[i].getAttribute("rel").indexOf("stylesheet") != -1 ) {
					if( links[i].href && links[i].href.match( reg ) )
						return RegExp.$1;
				}
			}
		}
		return '/'+ dirName +'/';
	},
	isContainerWith: function(el, tagName, className) {
		while (el != null)
		{
			if (el.tagName != null && el.tagName == tagName && u.hasClassName(el, className))
				return true;
			else
				el = el.parentNode;
		}
		return false;
	},
	getContainerWith: function(el, tagName, className) {
		while (el != null)
		{
			if (el.tagName != null && el.tagName == tagName && u.hasClassName(el, className))
				return el;
			else
				el = el.parentNode;
		}
		return el;
	}
}
var u = new Util();


/* 2: BasicFunctions
=================================*/

/* Definition of onload functions
---------------------------------------------*/
$(document).ready(function(){
	$("#localNavi .slider").click(function(){
		$targetChild=$(this).parent().children(".child");
		if($targetChild.size()){
			if($targetChild.css("display")=='none'){
				$(this).children("img").attr("src", $(this).children("img").attr("src").split(".")[0]+"on.gif");
				$targetChild.slideDown('slow');
			}
			else{
				$(this).children("img").attr("src", $(this).children("img").attr("src").split("on.")[0]+".gif");
				$targetChild.slideUp('slow');
			}
		}
	});
});
$(document).ready(function(){
	$("#contents .slider").click(function(){
		$targetChild=$(this).parent().children(".child");
		if($targetChild.size()){
			if($targetChild.css("display")=='none'){
				$(this).children("img").attr("src", $(this).children("img").attr("src").split(".")[0]+"on.gif");
				$targetChild.slideDown('slow');
			}
			else{
				$(this).children("img").attr("src", $(this).children("img").attr("src").split("on.")[0]+".gif");
				$targetChild.slideUp('slow');
			}
		}
	});
});


	
/* page top link */
function anchorTop(){
	var targetY = 0;
	var nowY = getNowY();
	distance = nowY - targetY;
	pageUp(targetY,nowY,distance);
}

/* subFunction for pageTopLink function */
var timerId;
function pageUp(_tY, _nY, _d){
	_nY = _nY - Math.ceil(_d*0.1);
	scrollTo(0, _nY);
	//alert(_tY+', '+_nY+', '+_d);
	_d = _nY - _tY;
	if(_d > 0){
		timerId = setTimeout("pageUp("+_tY+","+_nY+","+_d+")", 10);
	}else{
		clearTimeout(timerId);
	}
}
/* subFunction for pageTopLink function */
function getNowY(){
	var _nowY;
	if(document.body.scrollTop){ //
		_nowY = document.body.scrollTop;
	}
	else if(document.documentElement.scrollTop){ //IE6/7/Fx
		_nowY = document.documentElement.scrollTop;
	}
	else{ //N6
		_nowY = window.pageYOffset;
	}
	
	if(!_nowY){
		_nowY = 0;
	}
	return _nowY;
}


/* Definition of RightColumnBannerFunction
---------------------------------------------*/
function RCBanner(){
	var bnSource = new String();
	if(!bannerObj.length){
		$("#includeBnr").parent().children("h2").css("display","none");
	}
	else{
		for(i=0;i<bannerObj.length;i++){
			if(bannerObj[i].type == 'image'){
				if(!bannerObj[i].param){
					bannerObj[i].param = "";
				}
				bnSource += '<dl><dt><a href="'+bannerObj[i].URL+''+bannerObj[i].param+'" target="'+bannerObj[i].target+'"><img src="'+bannerObj[i].src+'" alt="'+bannerObj[i].alt+'" width="185" height="'+bannerObj[i].height+'" /></a></dt><dd>'+bannerObj[i].cap+'</dd></dl>';
			}else if(bannerObj[i].type == 'flash'){
				bnSource += '<dl><dt><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="185" height="'+bannerObj[i].height+'"><param name="movie" value="'+bannerObj[i].src+'"><param name="quality" value="high"><embed src="'+bannerObj[i].src+'"  quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="185" height="'+bannerObj[i].height+'"></embed></object></dt><dd>'+bannerObj[i].cap+'</dd></dl>';
			}
		}
		$("#includeBnr").append(bnSource);
	}
}


/* Definition of background image chache for IE6
---------------------------------------------*/
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}