/* div.utility css after+content for IE
--------------------------------------------------*/
/*
div.utility{ /*IE-expression (after + content) * /
behavior: expression(
this.style.behavior || (
this.innerHTML += '<div class="after"><\/div>', 
this.style.behavior = "none"
)
);
}
*/


function ieUtilityAreaBottom(){
	
		if (document.all && !window.opera){
	
		div = document.getElementsByTagName("div");
		
		for(i=0;i<div.length;i++){
			if (/\utility\b/.exec(div[i].className)){
				
				after = document.createElement("div");
				after.className = "after";
				
				div[i].appendChild(after);
				
			}
		}
	}
}

addEvent(window, "load", ieUtilityAreaBottom);


/* change edit mode display
  (for mon-5 comment)
--------------------------------------------------*/

function changeDisplay(id1,id2){
var id1 = document.getElementById(id1);
var id2 = id2 ? document.getElementById(id2):"";

if(id1.style.display){
id1Display=id1.style.display;
}
else if(document.defaultView){
id1Display=document.defaultView.getComputedStyle(id1, '').getPropertyValue("display");
}
else{
id1Display=id1.currentStyle.getAttribute("display");
}

if((id1Display=='none')||(id1Display=='')){
id1.style.display="block";
id2 ? id2.style.display='none':"";
}
else if(id1.style.display!='none'){
id1.style.display='none';
id2 ? id2.style.display="block":"";
}


}


/* 
----------------------------------------------------------------------------------------------------*/


/*
 Author : http://www.yomotsu.net
 Licensed under the GNU Lesser General Public License version 2.1
*/



/* rollover
----------------------------------------*/

function yomotsuRollover() {
	if (!document.getElementById) return
	
	var img = document.getElementsByTagName("img");
	
	for(i=0;i<img.length;i++){

		var src   = img[i].getAttribute("src");
		var ftype = src.substring(src.lastIndexOf("."), src.length);
		
		if(new RegExp("_n"+ ftype + "\\b").exec(src)) {
			
			img[i].onmouseover = function() {
				var curSrc   = this.getAttribute("src");
				var curFtype = curSrc.substring(curSrc.lastIndexOf("."), curSrc.length);
				this.setAttribute("src", curSrc.slice(0, -1*(curFtype.length + 2)) + "_r" + curFtype);
			}	
			
			img[i].onmouseout = function() {
				var curSrc   = this.getAttribute("src");
				var curFtype = curSrc.substring(curSrc.lastIndexOf("."), curSrc.length);
				this.setAttribute("src", curSrc.slice(0, -1*(curFtype.length + 2)) + "_n" + curFtype);
			}
			
		}
	}
}

addEvent(window, "load", yomotsuRollover);

/* altenation table
----------------------------------------*/
function yomotsuAlternationTable(){
	var table = document.getElementsByTagName("table");

	for(i=0;i<table.length;i++){
		var tr = table[i].getElementsByTagName("tr");
		
		if (tr.length == 0) {
			return null;
		}
		var hasThead="yes";
		for(ii=0;ii<tr[0].childNodes.length;ii++){
			if(tr[0].childNodes[ii].tagName=="TD"){
				hasThead="no";
			}
		}
		
		if(hasThead=="no"){
			for(ii=0;ii<tr.length;ii++){
				if(ii%2==0){
					tr[ii].className += " odd";
				}
				else{
					tr[ii].className += " even";
				}
			}
		}
		
		else{
			for(ii=1;ii<tr.length;ii++){
				if(ii%2==1){
					tr[ii].className += " odd";
				}
				else{
					tr[ii].className += " even";
				}
			}
		}
	}
}

addEvent(window, 'load', yomotsuAlternationTable);


/* Replace hr elements
   http://www.yomotsu.net/lab/javascripts/replacehr#article
----------------------------------------*/

function yomotsuReplaceHr(){
	if (document.all && !window.opera){
	
		hr = document.getElementsByTagName("hr");
		
		for(i=hr.length;i>0;i--){
			if (/\bseparator\b/.exec(hr[i-1].className)){
				
				div = document.createElement("div");
				div.className = hr[i-1].className;
				
				hr[i-1].parentNode.replaceChild(div,hr[i-1]);	
			}
		}
	}
}

addEvent(window, 'load', yomotsuReplaceHr);


/* IE BG png
----------------------------------------*/

function yomotsuIeBgPng(){
	if ((typeof document.documentElement.style.filter != "undefined")&&(typeof document.documentElement.style.msInterpolationMode == "undefined"))/* IE5.5&6*/ {
		element = document.getElementsByTagName("*");
		for(i=0;i<element.length;i++){
			bgImg = element[i].currentStyle.getAttribute("backgroundImage");
			bgRepeat = element[i].currentStyle.getAttribute("backgroundRepeat");
			bgRepeat="repeat"?"scale":"crop";
			
			if(bgImg.lastIndexOf(".png")!=-1){
				bgSrc = bgImg.slice(5,-2);
				element[i].style.backgroundImage = "none";
				element[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod="+bgRepeat+",src='"+bgSrc+"')";

			}
		}
	}
}

addEvent(window, 'load', yomotsuIeBgPng);

/* backToTop
----------------------------------------*/

backToTopBootConf = {
	topFlag : "#document"
}

function yomotsuBackToTopBoot(){
	var a = document.getElementsByTagName("a");
	for(i=0;i<a .length;i++){
		if(new RegExp(backToTopBootConf.topFlag + "\\b").exec(a[i].getAttribute("href"))) {
			
			a[i].onclick = function(){
				this.removeAttribute("href")
				backToTop();
				this.setAttribute("href",backToTopBootConf.topFlag);
				return false;
			}
		}
	}
}


function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;

	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}

	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}

	x3 = window.scrollX || 0;
	y3 = window.scrollY || 0;

	var x = Math.max(x1, Math.max(x2, x3));
	var y = Math.max(y1, Math.max(y2, y3));

	window.scrollTo(Math.floor(x / 1.3), Math.floor(y / 1.3));

	if (x > 0 || y > 0) {
		window.setTimeout("backToTop()", 25);
	}
	else if (navigator.userAgent.indexOf("AppleWebKit") == -1){
		location.href = backToTopBootConf.topFlag;
	}
		
}

addEvent(window, 'load', yomotsuBackToTopBoot);


/* add event
----------------------------------------*/

function addEvent(obj, evType, fn){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	}
	else {
		return false;
	}
}

