// Clear inputs on focus including double click
function init(){
	var inp=document.getElementsByTagName('input');
	for(var i=0;i<inp.length;i++){
		if((inp[i].type=='text') && (!document.getElementById('www'))){
		inp[i].setAttribute('rel',inp[i].defaultValue)
		inp[i].onfocus=function(){
		if(this.value==this.getAttribute('rel')){this.value='';}
			else{return false;}}
		inp[i].onblur=function(){
		if(this.value==''){this.value=this.getAttribute('rel');}
			else{return false;}}
		inp[i].ondbclick=function(){this.value=this.getAttribute('rel')}
}}}
if(document.childNodes){window.onload=init}

// Add, remove events
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

// text zoom
function textSize(size)
{
	var theContainer = document.getElementById("main");
	var increment = 0.1
	var currentSize = parseFloat(document.getElementById("main").style.fontSize);

	if (!currentSize)
	{
		currentSize = 1;
	}

	if (size == "smaller")
	{
		theContainer.style.fontSize = (currentSize - increment) + "em";
	}
	else
	{
		theContainer.style.fontSize = (currentSize + increment) + "em";
	}

	return true;
}

// apple to text-increase and text-decrease
function textplus() {
	tp = document.getElementById('text-increase');
	tp.onclick = function() {
		textSize('bigger');
		return false;
	};
}
function textminus() {
	tm = document.getElementById('text-decrease');
	tm.onclick = function() {
		textSize('smaller');
		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-2893941-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); 
}

addEvent(window, 'load', function(){
	textplus();
	textminus();
	addGoogleStats();
});
