var adresse = "dan"+'iel'+String.fromCharCode(64)+'fon'+'tes'+String.fromCharCode(46)+'bi'+String.fromCharCode(122);
var ptimer = null;
var lastpage = '';
var lastlang = 'german';
var IE = /*@cc_on!@*/false;
var startPer = 150;
var box2 = null;

var lang = new Array();
lang['lo'] = '<h1>about me</h1>My name is Daniel Fontes and I am studying <a href="http://www.hs-augsburg.de/gestaltung/studiengang/bachelor/iam/index.html" target="_blank" title="Interaktive Medien">Interactive Media</a> on the <a href="http://www.hs-augsburg.de/" target="_blank" title="University of Applied Sciences in Augsburg">University of Applied Sciences in Augsburg</a> since 2006.<br />In 1997 I jumped online for the first time and quickly realized the opportunities of the web&#x85;<h1>who wants to be normal?</h1>There are lots of pages looking like templates. I intend to build unique, well designed and implementable websites.';
lang['h1left1'] = 'my work';
lang['si1'] = '<p>On the following pages are some examples of my projects I realized, or at least, in which i played a significant role.</p><p>At the moment I am programming a restaurant management software including handheld support and waiter call system for a <a href="http://www.nifo.de/" target="_blank" title="NIFO.de">restaurant near Munich</a>&#x85;</p>last updated: January 2010';
lang['ro'] = '<h1>services</h1>Together with my clients I plan and develop internet presences to meet their individual requirements.<ul><li>counseling</li><li>concept development</li><li>consultation</li><li>implementation</li><li>maintenance</li></ul>Techniques: XHTML, CSS, MySQL, PHP, JS';		
lang['h1left2'] = 'contact';
lang['con'] = 'phone:<br />IM:<br />e-mail:';
lang['lang'] = 'Language';
lang['german'] = 'German';
lang['english'] = 'English';
lang['ietext'] = 'Boycott Internet Explorer';

var dimminterval = 0;
var ieobj = null;
var ietrans = 80;
var sekunden = 9;

function NoClickDelay(el) {
	this.element = el;
	if( window.Touch ) this.element.addEventListener('touchstart', this, false);
}

function setNoSel(elID) {
	document.getElementById(elID).className = "navi_item";
}

NoClickDelay.prototype = {
	handleEvent: function(e) {
		switch(e.type) {
			case 'touchstart': this.onTouchStart(e); break;
			case 'touchmove': this.onTouchMove(e); break;
			case 'touchend': this.onTouchEnd(e); break;
		}
	},

	onTouchStart: function(e) {
		e.preventDefault();
		this.moved = false;
		this.first = false;

		if (e.target.parentNode.id == 'navi') {
		
			for (var i=1;i<=navblocks;i++)
			{
				obj = document.getElementById('navi_nifo_'+i);
				if (e.target.id != 'navi_nifo_'+i) obj.className = "navi_item";
				else {
					if (obj.className != "selected") {
						obj.className = "selected";
						this.first = true;
					}
				}
			}		
		
		}

		this.element.addEventListener('touchmove', this, false);
		this.element.addEventListener('touchend', this, false);
	},

	onTouchMove: function(e) {
		this.moved = true;
	},

	onTouchEnd: function(e) {
		this.element.removeEventListener('touchmove', this, false);
		this.element.removeEventListener('touchend', this, false);

		if(( !this.moved ) && (!this.first)) {
			// Place your code here or use the click simulation below
			var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
			if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;

			var theEvent = document.createEvent('MouseEvents');
			theEvent.initEvent('click', true, true);
			theTarget.dispatchEvent(theEvent);
		}
	}
};

function getLang(type) {
    var lang;
    if (checknull(navigator.userLanguage)) {
        lang = navigator.userLanguage.toUpperCase();
    } else if (checknull(navigator.language)) {
        lang = navigator.language.toUpperCase();
    }
    return (lang && lang.indexOf(type.toUpperCase()) == 0)
}

function startdimmer(){
	if (sekunden>1){
		sekunden--;
		setcontent(document.getElementById('towait'), sekunden);
		setTimeout ( "startdimmer()", 1000 );	
	}
	else {
		setcontent(document.getElementById('towait'), '&nbsp;');
		dimminterval = setInterval ( "dimm()", 50 );
	}
}

function dimm(){
	if (ietrans>1){
		ietrans=ietrans-2;
		ieobj.style.filter = 'alpha(opacity='+ietrans+')';
	}
	else {
		ieobj.style.display = 'none';
		clearInterval(dimminterval);
	}	
}

function zoomOut(){
	if (box2!=null){
		if (startPer>180) startPer += rand2(-3, 2);
		else if (startPer<130) startPer += rand2(-2, 3);
		else startPer += rand2(-3, 4);
		box2.style.width = startPer+"%";
		box2.style.height = box2.style.width;
		box2.style.left = -((startPer - 100) / 2)+"%";
		box2.style.top = box2.style.left;
	}
	setTimeout("zoomOut()", rand(50, 1000));
}
		
function init() {
	if (IE){
		ieobj = document.getElementById('ie');
		ieobj.style.display = 'block';
		setTimeout ( "startdimmer()", 1000 );
	}
	setcontent(document.getElementById("email"), '<a href="mai'+'lto:'+adresse+'">'+adresse+'</a>');
	
	pages = document.getElementById('pages');
 	pages.onmouseover = pageover;
 	pages.onmouseout = clearptimer;
  	document.getElementById('german').onclick = function(){setLang('german')};
 	document.getElementById('english').onclick = function(){setLang('english')};
 	
 	new NoClickDelay(document.getElementById('lo'));
 	new NoClickDelay(document.getElementById('lu'));
 	new NoClickDelay(document.getElementById('ro'));
 	new NoClickDelay(document.getElementById('ru'));
 	 	
	if (!getLang("de")) setLang('english');
	addrects(60);
	zoomOut();
}

function rand ( n1, n2 )
{
  return ( Math.floor ( Math.random ( ) * (n2-n1) + n1 ) );
}

function rand2 ( n1, n2 )
{
  return (  Math.random ( ) * (n2-n1) + n1 );
}


function addrects(count){
	var newdiv;
	if (box2==null) {
		box = document.createElement('div');
		box.setAttribute('id', 'box');
		box2 = document.createElement('div');
		box2.setAttribute('id', 'box2');
		box.appendChild(box2);
		document.body.appendChild(box);
	}
	for (i=0; i<count; i++) {
		size = rand(30, 150);
		newdiv = document.createElement('div');	
		newdiv.style.width = size+'px';
		newdiv.style.height = size+'px';
		newdiv.style.left = rand(0, 100)+'%';
		newdiv.style.top = rand(0, 100)+'%';
		box2.appendChild(newdiv);
	}
	setTimeout("addrects(1)", rand(200, 3000));
}

function checklastpage(page) {
	if ((lastpage != page) && (lastpage.indexOf(page) == -1)) {
		lastpage = page;
	}
}

function setLang(newlang){
	var chng;
	var tmp;
	if (newlang != lastlang){
		for (key in lang) {
			chng = document.getElementById(key);
			tmp = getcontent(chng);
			setcontent(chng, lang[key]);
			lang[key] = tmp;
		}
		lastlang = newlang;
	}
}

function checknull(e){
	return (typeof(e) !== 'undefined' && e != null);
}

function getcontent(e){
	if (checknull(e)){
  		if (checknull(e.innerHTML)) return e.innerHTML;
  		else if (checknull(e.nodeValue)) return e.nodeValue;
  		else return '';
	}
	else return '';
}

function setcontent(e, content){
	if (checknull(e)){
		if (checknull(e.innerHTML)) e.innerHTML = content;
		else if (checknull(e.nodeValue)) e.nodeValue = content;
	}
}

function gettarget(e){
	e = e || window.event;
 	if (!e.srcElement)
		e = e.target;
	else
		e = e.srcElement;
	return e;
}

function clearptimer(){
	if (ptimer != null) clearTimeout(ptimer);
}

function pageclick(e){
	sender = gettarget(e);
	switchpage(sender);	
	return false;
}

function pageover(e){
	clearptimer();
	sender = gettarget(e);
	ptimer = setTimeout(function(){switchpage(sender);}, 200);
	return false;
}

function switchpage(sender){
	num = getcontent(sender);
	if (num > 0) {
		checklastpage('/lu/'+num.toString())
		lis = document.getElementById('pages').childNodes;
		for (var i = 0; i < lis.length; i++) {
			lis[i].className = 'nonsel';
		}
		sender.className = 'sel';
		imgs = document.getElementById('scroll');
		imgs.style.marginTop = ((num-1) * 137 * -1) + 'px';
	}
}

window.onload = init;
