// 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;
	};
}

// Google Analytics

var _gaq = _gaq || [];
function addGoogleStats()
{
    _gaq.push(['_setAccount', 'UA-22630681-1']);
    _gaq.push(['_trackPageview']);
    
    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
}

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

