var t;
var timer_on=0;
var zlewej;
var num=1;
var ilosc = 2;
var iloscTapet=9;
var d=0;
var num=3;

var tla = new Array(2);
var th,ts;
var steph, steps;
var krok = 3;
var toh,tos; 

function hide(co) {
	steph=100;
	toh=co;
	_hide();
}
function _hide() {
	steph-=krok;
	opa(toh, steph);
	th = setTimeout("_hide()", 10);
	if (steph<1){
		stopT(th);
		zmienTap(toh);
	}
}
	
function show(co) {
	steps=0;
	tos=co;
	_show();
}
function _show(){
	steps+=krok;  
	opa(tos, steps);
	  ts = setTimeout("_show()", 10);
	  if (steps>99) stopT(ts);
}
function opa(co, ile) {
	  $(co).css("filter", "alpha(opacity="+ile+")");
}

function stopT(tim) {
  clearTimeout(tim);
}

function zmienTap(it){
	if (num>iloscTapet) num=1;
	var txt = "url(\"obrazy/tla/tlo";
	txt += num + ".jpg\")";
	$(it).css("background-image", txt);
	num++;
}
/*
function zmiana() {	
	var tla = document.getElementsByClassName("tla");
		for(var i=1; i<=ilosc; ++i){
			if (i==num) continue;
			if ($.support.opacity){
				$(tla[i]).animate({
					opacity: 0
				}, 2000);
			} else {
				hide("#tlo1");
			}
		}
		if ($.support.opacity){
			$(tla[num]).animate({
				opacity: 1
			}, 2000);
		} else {
			show("#tlo12");
		}
		
		num++;
		if (num>ilosc) num=1;
	
}*/
function zmiana2() {
	//var tla = document.getElementsByClassName("tla");
	tla[0] = document.getElementById("tlo1");
	tla[1] = document.getElementById("tlo2");
	if ($.support.opacity){
		$(tla[d]).animate({
			opacity: 0
		}, 2000, function (){
				zmienTap(this);
			}
		);
	} else {
		hide(tla[d]);
	}
	
	d++;
	if (d==ilosc) d=0;
	if ($.support.opacity){
		$(tla[d]).animate({
			opacity: 1
		}, 2000);
	} else {
		show(tla[d]);
	}

}


function bg() {
    //$('#main').animate({backgroundPosition: '-=1024'},1000);
	zmiana2();
    t = setTimeout("bg()", 4000);
}

function start(){
  if (!timer_on)
    {
      timer_on = 1;
      setTimeout('bg()',4000);
    }
}

function stop() {
  clearTimeout(t);
  timer_on=0;
}

function bodyload() {
  ustaw();
  start();
  setTimeout('poka()', 2000);
  /* $('#wybor').animate({
     opacity: '1'
   },2000);*/
 }
 function poka() {
 	$("#menu").animate({
 		top: "0px"
 	}, 200);
 	var poz = $("#txt_border").position();
 	if(poz.left!=300) prawo('oferta.html');
 	//alert(poz.left);
 }
function lewo()
{
  $('#txt_border').animate({
    left: '50px'
  }, 500);
}

function srodek()
{
  $('#txt_border').animate({
    left: '300px'
  }, 500);
}

function prawo(strona)
{
	$("#txt_border").animate({
	    left: "910px"
	  }, 200, function() {
		  //alert("done");
		  window.open(strona, 'zawartosc');
		  $('#txt_border').animate({
		    left: '300px'
		  }, 500, function(){
			  
		  });
	  }
	  );
}
function pokaz_galerie(str) {	
	zwin();
	stop();
	clearTimeout(t);
	var gal = document.getElementById("galeria_br");
	gal.style.display = "block";
	if ($.support.opacity){
	$("#galeria_br").animate({
		    opacity: '1'
		  }, 1, function(){
			window.open('web/', 'galeria');  
		  });
	} else {
		opa(gal, 100);
		window.open('web/', 'galeria');
	}
}

function zwin() {
  $("#txt_border").animate({
	    left: "910px"
	  }, 200);
}
function wybor() {
  $('.wybor img').hover(
    function() {
      $(this).animate({
        top: '-=30px'
      }, 100);
    },
    function() {
      $(this).animate({
        top: '+=30px'
      }, 100);
    }
  );
}
function ustaw()
{
	var szer = document.documentElement.clientWidth;
	
	document.getElementById("all").style.left = (szer/2 - 450) + "px";
	$("#tlo0").position({
		  my: "center center",
		  at: "center center",
		  of: "#main"
		});
	$("#tlo1").position({
	  my: "center center",
	  at: "center center",
	  of: "#main"
	});
	$("#tlo2").position({
	  my: "center center",
	  at: "center center",
	  of: "#main"
	});
}

function findPos() {
	obj = document.getElementById('main');
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}

	  document.getElementById("tlo1").style.left = curleft + "px";
	  document.getElementById("tlo1").style.top = curtop + "px";
	  document.getElementById("tlo2").style.left = curleft + "px";
	  document.getElementById("tlo2").style.top = curtop + "px";/*
	  document.getElementById("logo").style.left = curleft + "px";
	  document.getElementById("logo").style.top = curtop+500-50 + "px"*/
	//return [curleft,curtop];
}
	
function menu_zwin(){
	$("#menu").animate({
		top: "-145px"
	}, 500);
	mshow=0;
}
	
	
