var i = 1;
var j = 1;
var arr = new Array ("first","second","third","fourth","fifth");
var txt = new Array ("text1","text2","text3","text4","text5");
var tt, ttone;
var element = 0;
var stop = 42;

global = window.setInterval( "beginne()", 300);

function beginne() {
	if ( element < 5 ) {
		if ( document.getElementById( txt[element] ) )
			document.getElementById( txt[element] ).style.visibility = 'visible';
	}
	i = element - 1;
	if ( element >= 5 ) {
		if ( document.getElementById( 'sm' ) )
			slideMenu.build('sm',248,10,10,0);
		window.clearInterval(global);
	}
	element = element + 1;
}

function makeAct( Element ){
	var arr = {Profil:1,Leistungen:2,Aktuelles:3,Referenzen:4,Kontakt:5};
	for (var key in arr)
	{
		if ( key == Element )
			document.getElementById( key ).style.color = "#009ee0";
		else
			document.getElementById( key ).style.color = "";
	}
}

function viewBox() {
	opacity( 'box', 0, 100, 10);
}

function hideBox() {
	opacity( 'box', 100, 0, 10);
}

function changePic( Element, Bild ) {
	var arr = {Profil:1,Leistungen:2,Aktuelles:3,Referenzen:4,Kontakt:5};
	opacity( Element, 100, 50, 1000 );
	for (var key in arr)
	{
		if ( key == Element )
			document.getElementById( Element ).style.backgroundImage = "url( "+Bild+" )";
		else
			document.getElementById( Element ).style.backgroundImage = "";
	}
	opacity( Element, 50, 100, 1000 );	
	hideBox();
}

function setPic( Element, Bild ) {
	document.getElementById( Element ).style.backgroundImage = "url( "+Bild+" )";
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
} 

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

var slideMenu=function(){
	var sp,st,t,m,sa,l,w,gw,ot;
	return{
		build:function(sm,sw,mt,s,sl,h){
			sp=s; st=sw; t=mt;
			if ( m=document.getElementById( sm ) ) {
				sa=m.getElementsByTagName('li');
				l=sa.length; w=m.offsetWidth; gw=w/l;
				ot=Math.floor((w-st)/(l-1)); var i=0;
				for(i;i<l;i++){s=sa[i]; s.style.width=gw+'px'; this.timer(s)}
				//if(sl!=null){m.timer=setInterval(function(){slideMenu.slide(sa[sl-1])},t);}
			}
		},
		dis:function(){
			var arr = {Profil:1,Leistungen:2,Aktuelles:3,Referenzen:4,Kontakt:5};
			for (var key in arr) {
				document.getElementById( key ).style.color = "";
			}
		},
		timer:function(s){
			s.onmouseover=function(){
				clearInterval(m.htimer);
				clearInterval(m.timer);
				m.timer=setInterval(function(){slideMenu.slide(s)},t);
				if ( document.getElementById( 'sm' ) ) {
				 document.getElementById( 'first' ).style.backgroundImage = "url(/images/p1_start.jpg)";
				 document.getElementById( 'second' ).style.backgroundImage = "url(/images/p2_start.jpg)";
				 document.getElementById( 'third' ).style.backgroundImage = "url(/images/p3_start.jpg)";
				 document.getElementById( 'fourth' ).style.backgroundImage = "url(/images/p4_start.jpg)";
				 document.getElementById( 'fifth' ).style.backgroundImage = "url(/images/p5_start.jpg)";
				 }
				}
			s.onmouseout=function(){clearInterval(m.timer);
				clearInterval(m.htimer);
				m.htimer=setInterval(function(){slideMenu.slide(s,true)},t);
				if ( document.getElementById( 'sm' ) ) {
				 document.getElementById( 'first' ).style.backgroundImage = "url(/images/p1_start.jpg)";
				 document.getElementById( 'second' ).style.backgroundImage = "url(/images/p2_start.jpg)";
				 document.getElementById( 'third' ).style.backgroundImage = "url(/images/p3_start.jpg)";
				 document.getElementById( 'fourth' ).style.backgroundImage = "url(/images/p4_start.jpg)";
				 document.getElementById( 'fifth' ).style.backgroundImage = "url(/images/p5_start.jpg)";
				 slideMenu.dis(); // link ausblenden beim rausgehen
				 }
				}
		},
		slide:function(s,c){
		if ( s ) {
		var cw=parseInt(s.style.width);
			if((cw<st && !c) || (cw>gw && c)){
				var owt=0; var i=0;
				for(i;i<l;i++){
					if(sa[i]!=s){
						var o,ow; var oi=0; o=sa[i]; ow=parseInt(o.style.width);
						if(ow<gw && c){oi=Math.floor((gw-ow)/sp); oi=(oi>0)?oi:1; o.style.width=(ow+oi)+'px';
						}else if(ow>=ot && !c){oi=Math.floor((ow-ot)/sp); oi=(oi>0)?oi:1; o.style.width=(ow-oi)+'px'}
						if(c){owt=owt+(ow+oi)}else{owt=owt+(ow-oi)}}}
				s.style.width=(w-owt)+'px';
			}else{clearInterval(m.timer);clearInterval(m.htimer);}
		}
		}
	};
}();
