/* preset */
var oID = document.getElementById;
var IE = /*@cc_on!@*/false;
var IE6 = (IE && (navigator['appVersion'].indexOf('MSIE 6') > 0)) ? true : false;
/* /preset */



/* event handlers */
function addEvent(o, sEvent, fFunc) {
	if (window.attachEvent) {
		o.attachEvent('on' + sEvent, fFunc);
	} else if (window.addEventListener) {
		o.addEventListener(sEvent, fFunc, false);
	}
}

function addLoadEvent(fFunc) {
	addEvent(window, 'load', fFunc);
}

function addDOMLoadEvent(func) {
	if (!window.__load_events) {

		var init = function () {
			if (arguments.callee.done) return; // quit if this function has already been called
			arguments.callee.done = true; // flag this function so we don't do the same thing twice
			if (window.__load_timer) { // kill the timer
				clearInterval(window.__load_timer);
				window.__load_timer = null;
			}
			for (var i=0; i<window.__load_events.length; i++) { // execute each function in the stack in the order they were added
				window.__load_events[i]();
			}
			window.__load_events = null;
		};

		// for Mozilla/Opera9
		if (document.addEventListener) {
			document.addEventListener('DOMContentLoaded', init, false);
		}

		// for Internet Explorer
		/*@cc_on @*/
		/*@if (@_win32)
			document.write('<scr'+'ipt id=__ie_onload defer src=//0><\/scr'+'ipt>');
			var script = document.getElementById('__ie_onload');
			script.onreadystatechange = function() {
				if (this.readyState == 'complete') {
					init(); // call the onload handler
				}
			};
		/*@end @*/

		// for Safari
		if (/WebKit/i.test(navigator.userAgent)) { // sniff
			window.__load_timer = setInterval(function() {
				if (/loaded|complete/.test(document.readyState)) {
					init(); // call the onload handler
				}
			}, 10);
		}

		// for other browsers
		window.onload = init;

		// create event function stack
		window.__load_events = [];
	}

	// add function to event stack
	window.__load_events.push(func);
}
/* /event handlers */



/* get elements by className */
getElementsByClassName = function(parentNode, className) {
	var result = [];
	if (!className) {
		if (typeof(parentNode) == 'string') {
			var className = parentNode;
			parentNode = document;
		} else {
			return result;
		}
	}
	var obj = parentNode.getElementsByTagName('*');
	for (var i=0; i<obj.length; i++) {
		if (obj[i].className.match(new RegExp('\\b' + className + '\\b'))) {
			result.push(obj[i]);
		}
	}
	return result;
}
/* /get elements by className */



/* QWEswfobj */
// disable the blinking when set outerHTML, may need to load external css file, where only flash objects have display: none property
if (IE) document.writeln('<style type="text/css">object {display: none;}</style>');
// rewrite satay swf objects
function QWEswfobj() {
	var swf = '';
	var obj = document.getElementsByTagName('object');
	for (var i=0; i<obj.length; i++) {
		if ((obj[i].getAttribute('type') == 'application/x-shockwave-flash') || (obj[i].getAttribute('classid') == 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000')) {
			swf = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			swf += (obj[i].getAttribute('id')) ? ' id="' + obj[i].getAttribute('id') + '"' : '';
			swf += (obj[i].getAttribute('width')) ? ' width="' + obj[i].getAttribute('width') + '"' : '';
			swf += (obj[i].getAttribute('height')) ? ' height="' + obj[i].getAttribute('height') + '"' : '';
			swf += '>' + "\n";
			for (var j=0; j<obj[i].childNodes.length; j++) {
				if ((obj[i].childNodes[j].nodeName) && (obj[i].childNodes[j].nodeName.toLowerCase() == 'param')) {
					swf += '<param name="'+obj[i].childNodes[j].getAttribute('name')+'" value="'+obj[i].childNodes[j].getAttribute('value')+'" />'+"\n";
				} else if ((obj[i].childNodes[j].nodeName) && (obj[i].childNodes[j].nodeName.toLowerCase() == 'div')) {
					swf += '<div>' + obj[i].childNodes[j].innerHTML + '</div>' + "\n";				
				}
			}
			swf += '</object>'+"\n";
			obj[i].outerHTML = swf;
		}
		obj[i].style.display = 'block';
	}
}
/* /QWEswfobj */



/* :hover */
function hover(obj) {
	obj.onmouseover = function() {
		this.className += ' hover';
	}
	obj.onmouseout = function() {
		this.className = this.className.split('hover').join('');
	}
}
/* /:hover */



/* show picture in popup */
var popup = null;
function showpic(pic, label, w, h) {
	if ((popup) && (!popup.closed)) {
		popup.close();
	}
	popup = window.open('','popup','directories=0,location=0,menubar=0,personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,width='+String(w)+',height='+String(h)+',left='+String(Math.floor((screen.width-w)/2))+',top='+String(Math.floor((screen.height-h)/2)-22));
	with (popup.document) {
		open('text/html');
		writeln('<html>');
		writeln('<head>');
		writeln('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
		writeln('<title>' + ((label != '') ? label + ' ' : '') + '</title>');
		writeln('<style>');
		writeln('html, body {margin: 0px; padding: 0px; background-color: #666; overflow: hidden;}');
		writeln('a, img {display: block; border: none 0px; margin: 0px; padding: 0px;}');
		writeln('</style>');
		writeln('</head>');
		writeln('<body>');
		writeln('<a href="javascript:;" onclick="self.close();"><img src="'+pic+'" alt="' + ((label != '') ? label + ' ' : '') + '" /></a>');
		writeln('</body>');
		writeln('</html>');
		close();
	}
	popup.focus();
}
/* /show picture in popup */



/* initialization */
function DOMLoadInit() {

	if (IE) {
		QWEswfobj();
	}
	
	if (IE6) {
	}

	/* modify links */
	var a = document.getElementsByTagName('a');
	for (var i=0; i<a.length; i++) {
		/* target="_blank" */
		if (a[i].className.indexOf('_blank') >= 0) {
			a[i].onclick = function() {
				this.blur();
				window.open(this.href);
				return false;
			}
		}
		/* /target="_blank" */
		/* popup image */
		if (a[i].className.indexOf('_popup') >= 0) {
			a[i].label = a[i].title;
			a[i].title = '';
			a[i].onclick = function() {
				this.blur();
				var wh = this.className.split('_popup(')[1].split(')')[0].split(',');				
				showpic(this.href, this.label, parseInt(wh[0], 10), parseInt(wh[1], 10));
				return false;
			}
		}
		/* /popup image */
	}
	/* /modify links */

}

function onLoadInit() {
}

addDOMLoadEvent(DOMLoadInit);

addLoadEvent(onLoadInit);
/* /initialization */



