
//----------------------------------------------------------
//    DOM HTML
//    Ver 0.9.2
//----------------------------------------------------------
//  Get elements by class name
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) {
			retnode.push(elem[i]);
		}
	}
	return retnode;
}

var DomHTML = {

	//-------------------------------------------------------
	//    Document width
	//-------------------------------------------------------
	getDocumentWidth: function (_document) {
		if (!_document) { _document = document;}
		if(_document.body) {
			if(_document.body.scrollWidth || _document.body.scrollWidth == 0) {
				return _document.body.scrollWidth;
			}
			if(_document.documentElement) {
				return _document.documentElement.offsetWidth;
			}
			return _document.body.offsetWidth;
		}
	
		if(_document.width || _document.width == 0) {
			return _document.width;
		}
		return 0;
	},


	//-------------------------------------------------------
	//    Get scroll top
	//-------------------------------------------------------
	getScrollTop: function() {
		if(window.scrollY) { return window.scrollY;}
		if(window.pageYOffset) { return window.pageYOffset;}
		if(document.documentElement && document.documentElement.scrollTop){
			return document.documentElement.scrollTop;
		} else if(document.body && document.body.scrollTop) {
			return document.body.scrollTop;
		}
		return 0;
	},


	//-------------------------------------------------------
	//    Document height
	//-------------------------------------------------------
	getDocumentHeight: function () {
		if(document.body) {
			if(document.body.scrollHeight || document.body.scrollHeight == 0) {
				return document.body.scrollHeight;
			}
			if(document.documentElement) {
				return document.documentElement.offsetHeight;
			}
			return document.body.offsetHeight;
		}	
		if(document.height || document.height == 0) {
			return document.height;
		}
		return 0;
	},


	//-------------------------------------------------------
	//    Effects
	//-------------------------------------------------------
	effects: {

		//-----------------------
		//  Set width
		//-----------------------
		width: function(_target, _width, _fade) {
			var current = _target.offsetWidth;
			if (!_fade) {
				var width = _width;
			} else {
				var width = current + ((_width - current) / _fade);
				if (width != current) {
					setTimeout(function() { DomHTML.effects.width(_target, _width, _fade / 1.25)}, 50);
				}
			}
			_target.style.width = width + "px";
		},

		//-----------------------
		//  Set opacity
		//-----------------------
		opacity: function(_target, _opacity, _fade, _fadetype) {
			var current = _target.style.opacity * 100;
			if (!_fade) {
				var opacity = _opacity;
			} else {
				var opacity = Math.round(current + ((_opacity - current) / _fade));
				if (opacity != current) {
					setTimeout(function() { DomHTML.effects.opacity(_target, _opacity, _fade / 1.25)}, 50);
				}
			}
			_target.style.zoom = 1;
			_target.style.filter = 'alpha(opacity=' + (opacity) + ')';
			_target.style.MozOpacity = opacity / 100;
			_target.style.opacity = opacity / 100;
		}
	},


	//-------------------------------------------------------
	//    Add event
	//-------------------------------------------------------
	addEvent: function(elemObj, eventType, funcName, useCapture) {
		if (!elemObj) { return false;}
		if (elemObj.addEventListener){
			elemObj.addEventListener(eventType, funcName, useCapture);
		} else if (elemObj.attachEvent){
			elemObj.attachEvent("on"+eventType, funcName);
		} else {
			return false;
		}
		return true;
	}

};

//----------------------------------------------------------
//    New window
//     Ver 1.0.0 [ 2008.3.18 ]
//     <a rel="newWindow[args...]" title="[Name]">
//     Charset=UTF-8
//----------------------------------------------------------
var NewWindow = {

	//-------------------------------------------------------
	//    Set
	//-------------------------------------------------------
	set: function() {
		var links = document.getElementsByTagName("a");
		var imax = links.length;
		for (var i=0;i<imax;i++) {
			if (!links[i].rel) { continue;}
			if (!links[i].rel.match(/newWindow/)) { continue;}
			var args = links[i].rel.replace("newWindow", "").split(" ");
			args.unshift(links[i].title);
			args.unshift(links[i].href);
			links[i].onclick = NewWindow.setOpen (args);
		}
	},


	//-------------------------------------------------------
	//    Window open
	//-------------------------------------------------------
	setOpen: function(URL) {
		var func = function() {
			NewWindow.open(URL);
			return false;
		}
		return func;
	},
	open: function(_args) {
		URL = _args[0];
		NAME = _args[1] || "NewWindow";
		WIDTH = _args[2] || 300;
		HEIGHT = _args[3] || 450;
		SCROLL = _args[4] || "yes";
		RESIZE = _args[5] || "yes";
		TOOLBAR = _args[6] || "no";
		LOCATION = _args[7] || "no";
		DIRECTORIES = _args[8] || "no";
		STATUS = _args[9] || "no";
		MENUBAR = _args[10] || "no";
	    var win;
	    win = window.open(
			URL,
			NAME,
			"toolbar=" + TOOLBAR +
			",location=" + LOCATION +
			",directories=" + DIRECTORIES +
			",status=" + STATUS +
			",menubar=" + MENUBAR +
			",scrollbars=" + SCROLL +
			",resizable=" + RESIZE +
			",width="+ WIDTH +
			",height=" + HEIGHT
		);
		win.focus();
		return false;
	}
};
DomHTML.addEvent(window, "load", NewWindow.set);
