/* core.js */
/* created by Valentin Agachi - http://agachi.name/ */

var brIE = ( /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent) );


function loadScript(path) {
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = path;
	document.getElementsByTagName('head')[0].appendChild(script); 
}


function ImgPre() {
	var d=document; 
	if(!d.imgp) d.imgp=new Array();
	var i, j=d.imgp.length, a=ImgPre.arguments; 
	for (i=0; i<a.length; i++) {
		if (a[i].indexOf("#")!=0) { 
			d.imgp[j]=new Image(); d.imgp[j++].src=a[i];
		}
	}
}

/**
 * Browser detect
 */

function is() {
	var agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible')==-1)));
	this.ns2 = (this.ns && (this.major == 3));
	this.ns3 = (this.ns && (this.major == 3));
	this.ns4b = (this.ns && (this.minor < 4.04));
	this.ns4 = (this.ns && (this.major == 4));
	this.ns6 = (this.ns && (this.major >= 5));
	this.opera = (agent.indexOf("opera") != -1);
	this.ie = ((agent.indexOf("msie") != -1) && !this.opera);
	this.ie3 = (this.ie && (this.major == 2));
	this.ie4 = (this.ie && (this.major == 4));
	this.ie5 = (this.ie && (this.major >= 5));
	this.moz = (agent.indexOf('Gecko')!=-1);
	this.win = (agent.indexOf("win")!=-1);
	this.mac = (agent.indexOf("mac")!=-1);
	this.unix = (agent.indexOf("x11")!=-1);
}
var br = new is();



/**
 * Location functions
 */

function go(link, target) {
	if (target == '_blank') {
		popup(link, 700, 550, 'go_win');
	} else {
		if (!target) {
			target = document;
		}
		target.location = link;
	}
}

function popup(link, width, height) {
	var left = (screen.width - width - 20) / 2;
	var top = (screen.height - height - 30) / 2;
	var date = new Date();
	var sName = 'win' + date.getHours() + date.getMinutes() + date.getSeconds();
	window.open(link, sName, 'width='+width+',height='+height+',left='+left+',top='+top+',toolbar=yes,location=yes,status=yes,resizable=yes,scrollbars=yes');
	return false;
}

function win_new(link, width, height) {
	var settings = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width='+width+',height='+height;
	cms = window.open(link, 'popup', settings);
}


function popupImg(sPath, sPicURL, sTitle) { 
	window.open(sPath + "lib/image.popup.htm?" + sPicURL + '?' + sTitle, "", "resizable=1,height=200,width=200"); 
}


/**
 * Page onload functions handling
 */

var load = {
	funcs: new Array(),
	register: function(f) {
		if (typeof(f) != 'function') return;
		load.funcs.push(f);
	},
	execute: function() {
		for (var i = 0; i < load.funcs.length; i++) {
			load.funcs[i]();
		}
	}
};
window.onload = load.execute;


/*
Array.prototype.toString = function() {
	var s = '['+"";
	for (var i in this) {
		if (typeof(this[i]) != 'function') s += i + ': ' + this[i] + ' - ';
	}
	s += ']';
	return s;
}
*/



function doPage(o, link, page) {
	if (typeof(o) == 'string') o = document.getElementById(o);
	var i = o.options[o.selectedIndex].value;
	var s = link;
	if (i != 1) s = link + '?' + page + '=' + i;
	go(s);
}




/* IE :hover */
sfHover = function() {
	var sfEls = document.getElementById("pageMenu").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			if (this.className == 's') this.className += 'hover hover';
			else this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			if (this.className == 'shover hover') this.className='s';
			else this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
//if (brIE) icd_onload_register(sfHover);



// DF1.1 :: domFunction 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html

//DOM-ready watcher
function domFunction(f, a) {
	var n = 0;
	var t = setInterval(function() {
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)) {
			c = false;
			if (typeof a == 'object') {
				for (var i in a) {
					if ( (a[i] == 'id' && document.getElementById(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1) ) { 
						c = true;
						break; 
					}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}
		if(n >= 60) {
			clearInterval(t);
		}
	}, 250);
};


