// fade 
var counter2 = 33;
var cancelPreload=0;
var preloadTarget=0;
// moje funkcje 
ns6=(document.getElementById&&!document.all)?true:false;
ie4=(document.all&&!window.opera)?true:false;
ie7=(window.ActiveXObject)?true:false;
opera=(window.opera)?true:false;

function fade(option,id,t){
	//alert('fade');
	if(option==1){
		//alert('option1');
		if(counter2==-3){
			step='3';
			rotatenfade();
		}
		if(counter2<33){
			preloadTimer(id,1,id,t);
		}
		if(counter2>=33){
				step='0'
				rotatenfade();
			}
		}
	
	if(option==0){
		if(counter2>=0){
			preloadTimer(id,0,id,t);}
		if(counter2==0){
			step='2';
			rotatenfade();
			//alert(counter2);			
		}
		if(counter2==-3){
			
		}
	}
}

function preloadTimer(id,option,id1,tt){
	op=option;
	iden = id1;
	ttt = tt;
	var obj = document.getElementById(id);
	//alert(obj);
		//alert(obj);
			if(opera)obj.style.opacity = (counter2/30)
			if(ns6)obj.style.MozOpacity = (counter2/30)
			if(ie4){obj.style.filter = "alpha(opacity="+counter2*3+")"}
	if(op==1)counter2+=3
	if(op==0)counter2-=3
	var smoothTimer = setTimeout('fade(op,iden,ttt)',50);
}
//do przeladowan w tabpanelach w glownym oknie
/////////////////////////////timer////////////////////////	
	var td1 = false; //td = timerDziala -> jak dziala to nei odpala go drugi raz
	var td2 = false;
function stopTimer(){
		if(td1){
			clearTimeout(timer1)
		td1 = false}
	}
function setTimer(func){
		funkcja = func;
		if(time == 0){stopTimer();eval(funkcja)}
		else{time = time-1;td1 = true; timer1=setTimeout('setTimer(funkcja)',delay)}
	}
function interval(czas,opoznienie,funkcja){//time - okresla ile jednostek ma odczekac, delay to jedno opoznienie: 1000=1sek
		time = czas;
		delay = opoznienie;
		stopTimer();
		setTimer(funkcja);	
	}
///////////////////////////////////////////////////////////////

var objstyle = false;
var parstyle = false;
var count = 0;
var anim = 0;
var idlay = 0;
var lastlay = 1; 
var tab = 0;
var s=0;
currObj = 0;

function startrot(){
	//interval(1,50,'alert(s=1)');
	interval(1,500,'rotatenfade();');  // zwalnia stop i rozpoczyna rotacje po 2sek
}
function changeimg(img,newsrc){
	//var dd = document.getElementById(img);
	alert('');
	img.src = newsrc;
}
var currimg = 1;
var step = 0;
function rotatenfade(){
	if(stop!=0&&anim!=1){  // jeżeli nie następuje zamknięcie i zamiana wedgetów rozpocznij rotację obrazków
		s = 'rot'+t;
		img = document.getElementById(s);
		//imgsrc = eval('imgprel'+t+'['+currimg+']');
		if(step == '0')	{interval(1,1500,'fade(0,s,tab)');}  //fade out starego obrazka
		if(step == '2') {interval(1,1100,'fade(1,s,tab)');currimg++;}	  //fade in  nowego obrazka
		if(step == '3') {
			if(currimg >= eval('imgprel'+t+'.length')) currimg=0;
			img.src = eval('imgprel'+t+'['+currimg+']');
			step=2;}                     //zamiana obrazka
		if(step!=1&&step!=2){step++;}
	}
	if(stop==0||anim==1) {
	step=0;
	currimg = 0;
	counter2 = 27
	stop=1;
	interval(1,10,'rotatenfade()');}
}

function cutStr(str,s,e){ 
	if(s!=null&&e!=null){return str.substring(s,e);	}
	if(s!=null){return str.substring(s,str.length);	}
	if(e!=null){return str.substring(0,e);}
}
