// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// iScript - Ikeris easy useful functions v0.1
// This file contains common utilities and basic javascript functions
// Some functions are carried out by other authors and contain appropriate description
// Use this free for any non-commercial and commercial products
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

// Add, remove and find event
function fixEvent(event){
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
}
fixEvent.preventDefault = function(){
	this.returnValue = false;
};
fixEvent.stopPropagation = function(){
	this.cancelBubble = true;
};
function handleEvent(event){
	event = event || fixEvent(window.event);
	var returnValue = true;
	var handlers = this.events[event.type];

	for (var i in handlers){
		if (!Object.prototype[i]){
			this.$$handler = handlers[i];
			if (this.$$handler(event) === false) { returnValue = false; }
		}
	}
	if (this.$$handler) { this.$$handler = null; }
	return returnValue;
}
function addEvent(element, type, handler){
	if (element.addEventListener){ element.addEventListener(type, handler, false); }
	else {
		if (!handler.$$guid) { handler.$$guid = addEvent.guid++; }
		if (!element.events) { element.events = {}; }
		var handlers = element.events[type];
		if (!handlers){
			handlers = element.events[type] = {};
			if (element['on' + type]) { handlers[0] = element['on' + type]; }
			element['on' + type] = handleEvent;
		}
		handlers[handler.$$guid] = handler;
	}
}
addEvent.guid = 1;

function removeEvent(element, type, handler){
	if (element.removeEventListener){ element.removeEventListener(type, handler, false); }
	else if (element.events && element.events[type] && handler.$$guid){
		delete element.events[type][handler.$$guid];
	}
}

function eventTarget(event){
	var elem;
	if (window.event){ elem = window.event.srcElement; }
	else if (event){ elem = event.target; }
	if (elem.nodeType == 3){ elem = elem.parentNode; }
	return elem;
}

// This little snippet fixes the problem that the onload attribute on the body-element will overwrite
// previous attached events on the window object for the onload event
if (!window.addEventListener){
	document.onreadystatechange = function(){
		if (window.onload && window.onload != handleEvent){
			addEvent(window, 'load', window.onload);
			window.onload = handleEvent;
		}
	};
}

// Cookies functions

// Sets a Cookie with the given name and value.
// name       Name of the cookie
// value      Value of the cookie
// [expires]  Expiration date of the cookie (default: 1.01.2023)
// [path]     Path where the cookie is valid (default: path of calling document)
// [domain]   Domain where the cookie is valid (default: domain of calling document)
// [secure]   Boolean value indicating if the cookie transmission requires a secure transmission
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie= name + "=" + escape(value) +
	((expires) ? "; expires=" + new Date("January 1, 2023").toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}

// Gets the value of the specified cookie.
// name  Name of the desired cookie.
// Returns a string containing value of specified cookie or null if cookie does not exist.
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin !== 0){ return null; }
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(decodeURI(dc.substring(begin + prefix.length, end))).split("+").join(" ");
}

// Deletes the specified cookie.
// name      name of the cookie
// [path]    path of the cookie (must be same as path used to create cookie)
// [domain]  domain of the cookie (must be same as domain used to create cookie)
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

// ***************************
// ** Some useful functions **

// Function create element
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}
// Function add dynamically stylesheet
function addStyleSheet(href, media){
	var headElement = document.getElementsByTagName('head')[0];
	var linkElement = document.createElement('link');
	media = (media === undefined ? 'all' : media);
	linkElement.setAttribute('type','text/css');
	linkElement.setAttribute('rel','stylesheet');
	linkElement.setAttribute('href', href);
	linkElement.setAttribute('media', media);
	headElement.appendChild(linkElement);
}

// Find label by ID element
function findLabel(inputElementID){
	findLabels = document.getElementsByTagName('label');
	for (var i=0; i<findLabels.length; i++) {
		if (findLabels[i].getAttributeNode("for") && findLabels[i].getAttributeNode("for").value == inputElementID) {
			return findLabels[i];
		}
	}
	return false;
}

// Trim function
function trim(str) {
	if (String(str) == "undefined" || str == "") {
		return "";
	}
	return str.replace(/^\s*/, "").replace(/\s*$/, "");
}

// Emulate PHP's htmlspecialchars
function htmlspecialchars (s){
    if(typeof s != 'string'){ return; }
    return s.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\&/g, '&amp;').replace(/"/g, '&quot;'); // "
}

// Cross browser detect internet browser name and version
var Browser = {
	userAgent : navigator.userAgent,
	appName : navigator.appName,

	IE : !!(window.attachEvent && !window.opera),
	OP : !!window.opera,
	FF : navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("KHTML") == (-1) && navigator.userAgent.indexOf("Firefox") > 0,
	NN : navigator.appName == "Netscape",
	SF : navigator.userAgent.indexOf("Safari") > 0,
	Gecko : navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("KHTML") == (-1),

	// Get name
	getBrowserName : function() {
		if(this.IE) { return "IE"; }
		else if(this.OP) { return "OP"; }
		else if(this.FF) { return "FF"; }
		else if(this.SF) { return "SF"; }
		else if(this.Gecko) { return "GK"; }
		return false;
	},
	// IE version
	getIEVersion : function() {
		if(this.IE) {
			var IEVer = this.userAgent.substring(this.userAgent.indexOf("MSIE ", 0));
			IEVer = IEVer.substring(5, IEVer.indexOf(";"));
			return parseFloat(IEVer);
		} else {
			return false;
		}
	}
};

// getElementById returns incorrect objects in IE and Opera
// fix both IE and Opera (adjust when they implement this method properly)
// http://www.sixteensmallstones.org/ie-javascript-bugs-overriding-internet-explorers-documentgetelementbyid-to-be-w3c-compliant-exposes-an-additional-bug-in-getattributes
if((this.Browser.getBrowserName() == 'OP') || (this.Browser.getBrowserName() == 'IE')){
	document.nativeGetElementById = document.getElementById;
	document.getElementById = function(id){
		var elem = document.nativeGetElementById(id);
		if(elem){
			//make sure that it is a valid match on id
			if(elem.attributes.id.value == id){
				return elem;
			}
			else{
				//otherwise find the correct element
				for(var i=1;i<document.all[id].length;i++){
					if(document.all[id][i].attributes.id.value == id){
						return document.all[id][i];
					}
				}
			}
		}
		return null;
	};
}

// **** CSS functions ****
// Check if object have class name
function hasClass(e, name){
	return (!e || !e.className) ? false : new RegExp('\\b' + name + '\\b').test(e.className);
}
// Remove class name from object
function delClass(e, name){
	return e && (e.className = e.className.replace(new RegExp('^' + name + '\\b\\s*|\\s*\\b' + name + '\\b', 'g'), ''));
}
// Add class name to object
function addClass(e, name){
	delClass(e, name);
	return e && (e.className += (e.className ? ' ' : '') + name);
}
// Swap class name in object
function replaceClass(e, class1, class2){
	if (typeof e == 'string') { e = document.getElementById(e); }
	if (hasClass(e, class1)) {
		delClass(e, class1);
		addClass(e, class2);
		return true;
	} else {
		return false;
	}
}
// Toggle class in object
function toggleClass(e, nameOfClass){
	if (typeof e == 'string') { e = document.getElementById(e); }
	if (hasClass(e, nameOfClass)){
		delClass(e, nameOfClass);
	} else {
		addClass(e, nameOfClass);
	}

	return true;
}

// Function getElementsByClassName
function getElementsByClassName( oElm, strTagName, strClassName ){
	var arrElements = ( strTagName == "*" && oElm.all ) ? oElm.all : oElm.getElementsByTagName( strTagName );
	var arrReturnElements = [];
	strClassName = strClassName.replace( /-/g, "\-" );
	var oRegExp = new RegExp( "(^|\s)" + strClassName + "(\s|$)" );
	var oElement;
	for( var i = 0; i < arrElements.length; i++ ){
		oElement = arrElements[i];
		if( oRegExp.test( oElement.className ) ){
			arrReturnElements.push( oElement );
		}
	}
	return ( arrReturnElements );
}
// get Window height
function getWindowHeight() {
	if (self.innerHeight)
	return self.innerHeight; // browsers
	else if (document.documentElement && document.documentElement.clientHeight)
	return document.documentElement.clientHeight;
	else if (document.body)
	return document.body.clientHeight; // other IE
	return false;
}

// get Body height
function getBodyHeight() {
	if (window.innerHeight && window.scrollMaxY)
	return window.innerHeight + window.scrollMaxY;
	else if (document.body.scrollHeight > document.body.offsetHeight)
	return document.body.scrollHeight;
	else
	return document.body.offsetHeight;
	return false;
}

// get Body scroll
function getBodyScroll() {
	if (self.pageYOffset)
	return self.pageYOffset; // browsers
	else if (document.documentElement && document.documentElement.scrollTop)
	return document.documentElement.scrollTop; // strict mode IE6
	else if (document.body)
	return document.body.scrollTop; // other IE
	return false;
}

// Initialise font size from cookies, if exists
function setInitTextSize(){
	if (!document.body  || !document.body.style) { return; }
	if(getCookie("fontvalue") !== null && getCookie("fontsize") !== null){
		document.getElementsByTagName('body')[0].style.fontSize = getCookie("fontvalue") + getCookie("fontsize");
	}
}
// Resize body text
function textSize(size){

	if (!document.body  || !document.body.style) { return; }
	var SizeCurrent;
	var CurrentValue;
	var CurrentUnit;
	var x;
	var body = document.getElementsByTagName('body')[0];

	if (body.style && body.style.fontSize){
		SizeCurrent = body.style.fontSize;
	}
	else if (typeof(getComputedStyle) != 'undefined'){
		SizeCurrent = getComputedStyle(body,'').getPropertyValue('font-size');
	}
	else if (body.currentStyle){
		SizeCurrent = body.currentStyle.fontSize;
	}

	x = /([\d.]+)(.+)/.exec(SizeCurrent);
	CurrentValue = x[1];
	CurrentUnit = x[2];

	// Zoom in
	if (size == "bigger") {
		switch(CurrentUnit){
			case '%': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'em': CurrentValue = parseFloat(CurrentValue) + 0.1; break;
			case 'ex': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'pc': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'pt': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'px': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'in': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'mm': CurrentValue = parseFloat(CurrentValue) + 1; break;
			case 'cm': CurrentValue = parseFloat(CurrentValue) + 1; break;
		}
	}
	if (size == "smaller") {
		switch(CurrentUnit){
			case '%': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'em': CurrentValue = parseFloat(CurrentValue) - 0.1; break;
			case 'ex': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'pc': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'pt': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'px': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'in': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'mm': CurrentValue = parseFloat(CurrentValue) - 1; break;
			case 'cm': CurrentValue = parseFloat(CurrentValue) - 1;	break;
		}

	}
	// Save font settings: value and size
	deleteCookie("fontvalue");
	deleteCookie("fontsize");
	setCookie("fontvalue", CurrentValue);
	setCookie("fontsize", CurrentUnit);

	body.style.fontSize = CurrentValue + CurrentUnit;
	return;
}

// Function to make text size increase and decrease
function textplus() {
	var tp;
	tp = document.getElementById('text-increase');
	if(!tp || !document.body  || !document.body.style) { return; }
	tp.onclick = function() {
		textSize('bigger');
		return false;
	};
}
function textminus() {
	var tm;
	tm = document.getElementById('text-decrease');
	if(!tm || !document.body  || !document.body.style) { return; }
	tm.onclick = function() {
		textSize('smaller');
		return false;
	};
}

// Keeping Compact Forms Accessible
// http://www.456bereastreet.com/
function hideLabel (field_id, hide) {
	var field_for;
	var labels = document.getElementsByTagName('label');
	for (var i = 0; i < labels.length; i++) {
		field_for = labels[i].htmlFor || labels[i].getAttribute('for');
		if (field_for == field_id) {
			labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
			return true;
		}
	}
	return false;
}

function overFocus(){
	hideLabel(this.getAttribute('id'), true);
}
function overBlur() {
	if (this.value === '') {
		hideLabel(this.getAttribute('id'), false);
	}
}
function overHandleClick() {
	var id, field;
	id = this.getAttribute('for');
	if (id && (field = document.getElementById(id))) {
		field.focus();
	}
}

function initOverLabels() {
	if (!document.getElementById) { return; }

	var labels, id, field;

	// Set focus and blur handlers to hide and show
	// LABELs with 'overlabel' class names.
	labels = document.getElementsByTagName('label');
	if(!labels){ return false; }
	for (var i = 0; i < labels.length; i++) {

		if (hasClass(labels[i],"overlabel")) {

			// Skip labels that do not have a named association
			// with another field.
			id = labels[i].htmlFor || labels[i].getAttribute('for');
			if (!id || !(field = document.getElementById(id))) {
				continue;
			}

			// Change the applied class to hover the label
			// over the form field.
			addClass(labels[i],"overlabel-apply");
			// Hide any fields having an initial value.
			if (field.value !== '') {
				hideLabel(field.getAttribute('id'), true);
			}
			// Set handlers to show and hide labels.
			field.onfocus = overFocus;
			field.onblur = overBlur;

			// Handle clicks to LABEL elements (for Safari).
			labels[i].onclick = overHandleClick;
		}
	}
}

// External links
// Set attribute and value to element to make site open in new window, for example <a rel="external" href="...">Open in new window</a> */
var externalLinks = {
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) { return true; }
		else {
			var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) {
					oWin.focus();
				}
			}
			return false;
		}
		oWin = null;
		return true;
	},
	init: function(attr,val) {
		var d=document;
		if(!d.getElementById||!d.createElement||!d.appendChild) { return; }
		var strAttr = ((typeof attr == 'undefined') || (attr === null)) ? 'class' : attr;
		var strVal = ((typeof val == 'undefined') || (val === null)) ? 'non-html' : val;
		var arrLinks = document.links;
		var oLink;
		var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
		for (var i = 0; i < arrLinks.length; i++) {
			oLink = arrLinks[i];
			if ((strAttr == 'class') && oRegExp.test(oLink.className) || oRegExp.test(oLink.getAttribute(strAttr))) {
				oLink.onclick = externalLinks.openWin;
			}
		}
	}
};

// Zebra tables
// Find elements table with "zebra" class and make zebra styles on table
// In CSS specify class even for even tr color
function zebraTables() {
	var d=document;
	if(!d.getElementById||!d.getElementsByTagName) { return; }
	var tables = document.getElementsByTagName("table");

	for(var x=0;x!=tables.length;x++){
		var table = tables[x];

		if(hasClass(tables[x],"zebra")) {
			var tbodies = table.getElementsByTagName("tbody");
			for (var h = 0; h < tbodies.length; h++) {
				var even = true;
				var trs = tbodies[h].getElementsByTagName("tr");
				for (var i = 0; i < trs.length; i++) {
					if(even){
						if(!hasClass(trs[i],"even")){ addClass(trs[i],"even"); }
					}
					even = !even;
				}
			}
		}
	}
}

// Zebra lists
// Find elements ol, ul with "zebralist" class and make zebra styles on list
// In CSS specify class even for even li color
function zebraLists(){
	var d=document;
	if(!d.getElementById||!d.getElementsByTagName) { return; }

	var lists = getElementsByTagNames('ol,ul');
	for (var i=0;i<lists.length;i++) {

		if(hasClass(lists[i],"zebralist")){
			var items = lists[i].childNodes;
			var counter = 1;
			for (var j=0;j<items.length;j++) {
				var even = true;
				if (items[j].nodeName.toLowerCase() == 'li' && !items[j].getElementsByTagName('li').length) {
					if(even){
						if(!hasClass(items[j],"even")){ addClass(items[j],"even"); }
					}
					even = !even;
				}
			}
		}
	}
}

// Add unobtrusive print link
// Give target element (targetEl) and target (targetText) text for print button
// The function generate <li><a href="#">Print text</li>
function addPrintLink(targetEl,targetText) {
	if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
	if (!document.getElementById(targetEl)) {return;} // Check that the target element actually exists
	if(!window.print && (typeof window.print != "function")) {return;} // Check that the browser supports window.print
	var targetElement = document.getElementById(targetEl).getElementsByTagName("li")[0];

	var li = document.createElement('li');
	var oLink = document.createElement('a');
	var oB = document.createElement('b');
	var oB2 = document.createElement('b');
	oLink.id = 'printbutton'; // Give the link an id to allow styling
	oLink.href = '#'; // Make the link focusable for keyboard users

	oLink.appendChild(oB2);
	oB2.appendChild(oB);
	oB.appendChild(document.createTextNode(targetText));

	oLink.onclick = function() {
		window.print();
		return false;
	}; // Return false prevents the browser from following the link and jumping to the top of the page after printing
	li.appendChild(oLink);
	targetElement.parentNode.insertBefore(li,targetElement);
}

// Given an element, this function attempts to give that element the browser's focus.
function focusOn(elm){
	if ( elm === null ) { return; }

	try{
		elm.focus();
	}
	catch ( ex ){
		// Catch Mozilla exception when new focus field has autocomplete data.
	}
}

// Toggle classes on specified element with href
// The function find element with href, then element with id="from href"
function toggle_element() {
	var elem = this;
	if (elem && (elem.getAttribute("href")!== null)) {
		elem.blur();
		var getid = elem.href.split('#');
		var id = document.getElementById(getid[1]);
		if(hasClass(id,"hide")){ replaceClass(id,"hide","view"); }
		else { replaceClass(id,"view","hide"); }
	}
	return false;
}
// Initialisation Toggle classes
function toggle_init() {
	var i, ids, targetURL;
	var anchors = document.getElementsByTagName('*');
	for (i = 0; i<anchors.length; i++) {
		if(hasClass(anchors[i],"toggle") && (anchors[i].getAttribute("href")!== null)){
			ids = anchors[i].href.split("#");
			targetURL = document.getElementById(ids[1]);
			if(!hasClass(targetURL,"hide")){ addClass(targetURL,"hide"); }
			anchors[i].onclick = toggle_element;
		}
	}
}

// Pullquote function. Use "pullquote" class name to generale pullquote
// Function by Roger Johansson, www.456bereastreet.com
var pullquote = {
	init : function() {
		// Check that the browser supports the methods used
		if (!document.getElementById || !document.createElement || !document.appendChild){ return false; }
		var oElement, oPullquote, oPullquoteP, oQuoteContent, i, j;
		// Find all span elements with a class name of pullquote
		var arrElements = document.getElementsByTagName('span');
		var oRegExp = new RegExp("(^|\\s)pullquote(\\s|$)");
		for (i=0; i<arrElements.length; i++) {
			// Save the current element
			oElement = arrElements[i];
			if (oRegExp.test(oElement.className)) {
				// Create the blockquote and p elements
				oPullquote = document.createElement('blockquote');
				oPullquote.className = oElement.className;
				oPullquoteP = document.createElement('p');
				// Insert the pullquote text
				for(j=0;j<oElement.childNodes.length;j++) {
					oPullquoteP.appendChild(oElement.childNodes[j].cloneNode(true));
				}
				oPullquote.appendChild(oPullquoteP);
				// Insert the blockquote element before the span elements parent element
				oElement.parentNode.parentNode.insertBefore(oPullquote,oElement.parentNode);
			}
		}
	}
};

// Go to top - scrolling version
// Remember to se id="gototop" for link provide to top of page
var intervalID;

function goToTop (){
	if(!document.getElementById('gototop')){ return false; }
	document.getElementById('gototop').onclick = 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 / 2), Math.floor(y / 2));

		window.clearInterval(intervalID);
		if (x > 0 || y > 0) {
			intervalID = window.setInterval(backToTop, 60);
		}
		return false;
	};
}

// asynchroniczny sposob wywolywania trackera GA, tj. ogolnie odnoszenie sie do ich skryptow bez opozniania ladowania strony przez ladowanie zewnetrznego pliku JS.
// http://mgorny.jogger.pl/2008/01/12/asynchroniczne-wywolanie-nowego-trackera-google-analytics/
function addGoogleStats() {
	var GAID = 'UA-3176057-1';
	var head = document.getElementsByTagName('head')[0];
	var scr = document.createElement('script');
	scr.type = 'text/javascript';
	scr.src = (location.protocol == 'http:' ? 'http://www.' : 'https://ssl.') + 'google-analytics.com/'+'ga.js';
	var once = 0;

	function runMe() {
		if (scr.readyState == 'loading' || _gat === undefined || once) { return; }
		clearInterval(timer);
		once++;

		var pageTracker = _gat._getTracker(GAID);
		pageTracker._initData();
		pageTracker._trackPageview();
	}

	var timer = setInterval(runMe, 2000);
	scr.onload = runMe;
	scr.onreadystatechange = runMe;
	head.appendChild(scr);
}

// Get key code
function GetKeyCode(event) {
	var code;
	if (event.keyCode) {
		code = event.keyCode;
	} else if (event.which) {
		code = event.which;
	}
	return code;
}

// *************************************
// Make nice titles for title="" element
var lightTitles = {
	posX : 0,								// x pixel value of current cursor position
	posY : 0,								// y pixel value of current cursor position
	obj : Object,							// element that of which you're hovering over
	tip : Object,							// element the actual toolTip itself
	init : function() {
		if ( !document.getElementById || !document.createElement || !document.getElementsByTagName ) { return; }
		var i;
		this.tip = document.createElement('div');
		this.tip.setAttribute("id","toolTip");
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		var elems = document.getElementsByTagName("*");
		for ( i=0; i<elems.length; i++ ) {
			if((elems[i].getAttribute("title")!== null) && (elems[i].getAttribute("title").length !== 0)){
				addEvent(elems[i],'mouseover',this.tipOver);
				addEvent(elems[i],'mouseout',this.tipOut);
				elems[i].setAttribute('tip',elems[i].getAttribute("title"));
				elems[i].removeAttribute('title');
			}
		}
	},
	getPosition : function(e) {
		if ( document.captureEvents ) {
			lightTitles.posX = e.pageX;
			lightTitles.posY = e.pageY;
		} else if ( window.event.clientX ) {
			lightTitles.posX = window.event.clientX+document.documentElement.scrollLeft;
			lightTitles.posY = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed-10);
		if ( newOpac > 0 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityOutID = window.setTimeout("lightTitles.tipOut('"+newOpac+"')",20);
		}
		else {
			if ( window.rmT ) {
				clearTimeout(rmT);
			}
			if ( window.opacityID ) {
				clearTimeout(opacityID);
			}
			if ( window.opacityOutID ) {
				clearTimeout(opacityOutID);
			}
			lightTitles.tip.style.display = 'none';
		}
	},
	tipOver : function(e) {
		lightTitles.obj = this;
		rmT = window.setTimeout("lightTitles.tipShow()",500);
		lightTitles.getPosition(e);
	},
	tipShow : function() {
		var scrX = Number(this.posX);
		var scrY = Number(this.posY);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var elm = this.obj;

		// Remove all previous content from tip <div>, before add new content
		var d = lightTitles.tip;
		for (var i=(d.childNodes.length - 1), child, attr; i>=0; i--) {
			child = d.childNodes[i];
			attr = child.attributes;
			if (attr) {
				for (var j=0, jl=attr.length; j<jl; j++) {
					if (typeof child[attr[j].name] === "function") {
						child[attr[j].name] = null;
					}
				}
			}
			child.parentNode.removeChild(child);
		}
		// Add content from old title to new title
		//this.tip.appendChild(document.createTextNode(elm.getAttribute('tip')));

		// check if there is more letter than 30, then width of tooltip set to 28em
		var size = elm.getAttribute('tip').length;
		if(size > 30){
			this.tip.style.width = "28em";
		}
		else{
			this.tip.style.width = "auto";
		}
		this.tip.innerHTML = elm.getAttribute('tip');

		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.display = 'block';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 99 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("lightTitles.tipFade('"+newOpac+"')",20);
		}
		else {
			this.tip.style.opacity = '.99';
			this.tip.style.filter = "alpha(opacity:99)";
			// hide title after n seconds
			outID = window.setTimeout("lightTitles.tipOut('100')",20000);
		}
	}
};
function runLightTitles() {
	lightTitles.init();
}

// Photo gallery
// use class ipopup for links
// split in one category by name from rel
function hideImagePopup(invoker) {
	// remove layer & layer childs
	var layer = document.getElementById('ipopup');
	while (layer.firstChild) {
		layer.removeChild(layer.firstChild);
	}
	var layer = document.getElementById('ipopup');
	layer.parentNode.removeChild(layer);
	// remove mask
	var mask = document.getElementById('ipopup-mask');
	mask.parentNode.removeChild(mask);
	// show selects
	var selects = document.getElementsByTagName("select");
	if (selects) {
		for (var i = 0; i < selects.length; i++)
		selects[i].style.visibility = 'visible';
	}

	// focus on invoker link
	if (invoker) invoker.focus();
	return false;
}

function calculateHeight(windowHeight, bodyHeight) {
	if (bodyHeight > windowHeight)
	return bodyHeight + 'px';
	else
	return windowHeight + 'px';
	return false;
}

function showImagePopup(invoker) {
	if(!document.getElementById || !document.createTextNode){ return false; }

	// returns current invoker from gallery array
	function getCurrentFromGallery(invoker) {
		var current = 0;
		for (var i = 0; i < gallery[rel].length; i++) {
			if (gallery[rel][i] == invoker)
			current = i;
		}
		return current;
	}

	// checking if any ipopup is allready opened
	if (document.getElementById('ipopup')) {
		hideImagePopup();
	}

	// invoker properties
	var imageHref = invoker.getAttribute('href');
	var rel = invoker.getAttribute('rel');

	// calculate height
	var windowHeight = getWindowHeight();
	var bodyHeight = getBodyHeight();
	var bodyScroll = getBodyScroll();
	var heightCalculated = calculateHeight(windowHeight, bodyHeight);

	// hide selects (IE6 bug)
	if(this.Browser.getIEVersion() == 6){
		var selects = document.getElementsByTagName("select");
		for (var i = 0; i < selects.length; i++)
		selects[i].style.visibility = 'hidden';
	}

	// create mask & layer
	var mask = document.createElement('div');
	mask.setAttribute('id','ipopup-mask');
	mask.style.height = heightCalculated;
	document.body.appendChild(mask);
	var layer = document.createElement('div'); // redundant layer (solution for IE6 DXImageTransform+links bug)
	layer.setAttribute('id','ipopup');
	layer.style.height = heightCalculated;
	var loaderImageOffset = 60; // offset for loader background image (layer background)
	var offsetTop = Math.ceil(windowHeight / 2) - loaderImageOffset + bodyScroll;
	layer.style.backgroundPosition = '50% ' + offsetTop + 'px';
	document.body.appendChild(layer);

	// main image preloader
	var imagePreload = new Image();
	imagePreload.onload = function() {

		// vertical centering - calculate offset
		var offsetTop;
		offsetTop = Math.ceil((windowHeight - imagePreload.height) / 2);
		if (offsetTop < 0)
		offsetTop = 0;

		// create container
		var container = document.createElement('div');
		container.setAttribute('id', 'ipopup-container');
		container.style.width = imagePreload.width + 'px';
		container.style.marginTop = bodyScroll + offsetTop + 'px';
		layer.appendChild(container);

		// create main photo
		var image = document.createElement('img');
		image.setAttribute('id', 'ipopup-image');
		image.setAttribute('src', imageHref);
		image.setAttribute('alt', '');
		image.onclick = function() {
			return hideImagePopup(invoker);
		}
		container.appendChild(image);

		// create close button
		var close = document.createElement('a');
		close.setAttribute('id', 'ipopup-close');
		close.setAttribute('href', '#');
		close.onclick = function() {
			return hideImagePopup(invoker);
		}
		var txt = document.createTextNode('Zamknij');
		close.appendChild(txt);
		container.appendChild(close);
		close.focus();
		if (rel) {
			// create next/prev buttons for gallery
			var current = getCurrentFromGallery(invoker);
			if (current > 0) {
				var prev = document.createElement('a');
				prev.setAttribute('id', 'ipopup-prev');
				prev.setAttribute('href', '#');
				prev.onclick = function() {
					return showImagePopup(gallery[rel][current-1]);
				}
				var txt = document.createTextNode('← Poprzedni');
				prev.appendChild(txt);
				container.appendChild(prev);
			}
			if (current < (gallery[rel].length - 1)) {
				var next = document.createElement('a');
				next.setAttribute('id', 'ipopup-next');
				next.setAttribute('href', '#');
				next.onclick = function() {
					return showImagePopup(gallery[rel][current+1]);
				}
				var txt = document.createTextNode('Następny →');
				next.appendChild(txt);
				container.appendChild(next);
			}
		}
		// calculate mask height - again!
		windowHeight = getWindowHeight();	bodyHeight = getBodyHeight();	bodyScroll = getBodyScroll();
		heightCalculated = calculateHeight(windowHeight, bodyHeight);
		mask.style.height = heightCalculated;

	}
	imagePreload.src = imageHref;

	return false;
}

var gallery = new Array;
function initImagePopup(nextText,prevText,closeText) {
	var invokers = document.getElementsByTagName("a");
	var count = 0, countRels = 0;
	var rels = new Array;

	/* checking rel attributes for gallery array */
	function checkRels(rel, rels) {
		var exists = false;
		for (var i = 0; i < rels.length; i++) {
			if (rel == rels[i]) exists = true;
		}
		return exists;
	}

	/* get all anchors with speciefied class name */
	for (var i = 0; i < invokers.length; i++) {
		if (invokers[i].className.indexOf("ipopup") != -1) {
			var rel = invokers[i].getAttribute('rel');
			if (rel) {
				// creating two-dimensional gallery array
				if (!checkRels(rel, rels)) {
					gallery[rel] = new Array;
					rels[countRels] = rel;
					countRels++;
					count = 0;
				}
				gallery[rel][count] = invokers[i];
				count++;
			}
			invokers[i].onclick = function() {
				return showImagePopup(this);
			}
		}
	}

}

// ************************
// load all event in onload
// ************************
addEvent(window, 'load', function(){
	setInitTextSize();
	textplus();
	textminus();
	initOverLabels();
	externalLinks.init("rel","external");
	zebraTables(); // find table on make zebra on every tr
	addPrintLink("list-menu-options","Drukuj"); // add print button
	toggle_init(); // toggle class on elements
	pullquote.init(); // initialise pullquote
	goToTop(); // set scroll to top
	runLightTitles(); // nice, new tooltip
	initImagePopup(); // make nice gallery for images
	addGoogleStats(); // initialise Google Stats
});
