  var ie=document.all;
  var ns6=!document.all;
  
  //zdjecie
  var idZdjecie;
  var divPod;
  var ileAlfaIe = 0;
  var ileAlfaNs = 0;
  var imageSemiTap;
  var widthOld=0;
  var heightOld=0;
  var widthNew = 0;
  var heightNew = 0;
  var oldImage = new Image();
  var oldId = 0; 
  var oldA;
  var pierwszy = 1;
  var timoutID;
  var maxImg = '';
  var idCat = 0;
  var idTA=0;
  var nameTap = '';
  var prefix;
  
  
  var podCatId = 0;
  var namePodCat = '';
  var name = '';
  
  //ocena
  var iloscGwiazd = 10;
  var gwiazdy = new Array();
  var ocenaAvg = 0;
  var czyRozwin = 0; 
  var jakaOcena = 0;
  var divN;
  var imgStarGray = new Image();
  var imgStarHalf = new Image();
  var imgStarGold = new Image();
  var dHeight=0;
  
  //tagi
  var czyRozwinTag=0;
  var iloscTagow=0;
  var dHeightTag=0;
  var divTagi;
  var xmlHttpContentTag;
 
  //dodaj tapete
  var czyRozwinDodajTap=0;
  var divDodajTap;
  var dHeightDodajTap=0;
  
  //obrazki
  var strzalkaBottom = new Image();
  strzalkaBottom.src = path+'assets/images/wallpaper/arrow_ocena_bottom.gif';
  
  var strzalkaRight = new Image();
  strzalkaRight.src = path+'assets/images/wallpaper/arrow_ocena_right.gif';
  
  
  var loader = new Image();
  loader.src = path+'assets/images/wallpaper/Bloader.gif';
  
    
  function powieksz(el){
    //widthOld = el.width;
    //heightOld = el.height;
    
    //widthNew = Math.floor(widthOld*1.15);
    //heightNew = Math.floor(heightOld*1.15);
    
   // el.width = widthNew;
   // el.height = heightNew;
  }
  
  
  function reset(el)
  {
   // el.width = widthOld;
   // el.height = heightOld;
  }
  
  
  function wczytaj(tabImg,i,el,dir,blimit,slimit)
  {
  
 // if (!blimit) alert ('blimit');
 // if (!slimit) alert ('slimit');
  
   
    var nameTap = document.getElementById('name_tap');
    imageSemiTap = document.getElementById('image_semi_tap');
    var tagiTap = document.getElementById('tagi_tap');
    var autorT = document.getElementById('autorT');
    var dataT = document.getElementById('dataT');
    var ilosc_pobT = document.getElementById('ilosc_pobT');
    var ocenaT = document.getElementById('ocenaT');
    idTA = document.getElementById('idT');
    var divNad = document.getElementById('divNad');
    var divParentTag = document.getElementById('obtaguj');
    var divChildTag = document.getElementById('obtagujA');
    divTagi = document.getElementById('obtagujA');
    maxImg = tabImg[i].maxImg;
    name = tabImg[i].name;
    
    
    var keyF;
    var postText;
        
     podCatId = tabImg[i].podCatId;
     namePodCat = tabImg[i].namePodCat;
     nameImage = tabImg[i].nameImage;
    
    idkomorka = tabImg[i].prefix;
    idCat = tabImg[i].catid;
    
   
    
    idZdjecie = i;
    

       
    imgStarGray.src = path+'assets/images/wallpaper/star_gray.gif';
    imgStarHalf.src = path+'assets/images/wallpaper/star_half.gif';
    imgStarGold.src = path+'assets/images/wallpaper/star_gold.gif';
    
    ocenaAvg = Number(tabImg[i].ocenaSrednia);
   
    if(oldId != 0)
    {
      oldA.appendChild(oldImage);
    }
    
    var imgSemi = new Image();
    imgSemi.src = tabImg[i].src;
    
    
    divPod = document.createElement('div');
    divPod.appendChild(imgSemi);
    
    divPod.style.position='absolute';
    imageSemiTap.appendChild(divPod);
    
    ileAlfaIe = 0;
    ileAlfaNs = 0;
    
    shadowImg();
    
    nameTap.innerHTML = '';
    tagiTap.innerHTML = '';
    autorT.innerHTML = '';
    dataT.innerHTML = '';
    ilosc_pobT.innerHTML = '';
    ocenaT.innerHTML = '';
    idTA.value = '';
    
   
    nameTap.innerHTML = tabImg[i].name;
    
    tagiTapArray=tabImg[i].tagi.split(",");
    var htmltag="";
    
    //alert(path)
    
        for( var idx in tagiTapArray) {
        var tmpline=stripSpaces(tagiTapArray[idx]);
        htmltag+= '<span class="taglink"><a href="'+pathTag+tmpline+'/page/0/">'+tmpline+'</a></span> ';
        }
        
    
    tagiTap.innerHTML = htmltag;
    
    
    
    
    autorT.innerHTML = tabImg[i].autor;
    dataT.innerHTML = tabImg[i].date;
    ilosc_pobT.innerHTML = tabImg[i].iloscPob;
    ocenaT.innerHTML = (Number(tabImg[i].ocenaSrednia)).toFixed(2);
    idTA.value = tabImg[i].idT;
    
    divN = document.getElementById('ilosc_pobA');
    
    iloscTagow = tabImg[i].iloscTagow;
    
    
    if(keyF = document.getElementById('aKomentarz'))
    {
     keyF.href = "http://www.ekofora.pl/postautotapety.php?keyforum="+tabImg[i].keyForum;
     
      if(postText = document.getElementById('ilePost'))
         postText.innerHTML = tabImg[i].ilePost;
     
      if(postText = document.getElementById('postText'))
         postText.innerHTML = tabImg[i].postText;
      
      if(postText = document.getElementById('postAutor'))
         postText.innerHTML = tabImg[i].postAutor;
         
      if(postText = document.getElementById('postData'))
         postText.innerHTML = tabImg[i].postData;      
          
         
    }
    
    
    
    
    
    if(maxIloscTagow<=tabImg[i].iloscTagow)
    {
      var tagS = divChildTag.childNodes[0];
      
      if(divChildTag.childNodes[0])
      {
      
      divChildTag.removeChild(tagS);
      }
      
      divParentTag.style.display='none';
      divChildTag.style.display='none';
      czyRozwinTag=0;
    }  
    else
    {
     
        if(czyRozwinTag)
        {  
        removeTag();
        showTagi();
        }
    
      divParentTag.style.display='block';  
    }
   
    
    var tabI = new Array();
    
    
    if(czyRozwin)
    {
    removeStar();
    rozs();
    }
    
   // rozwinTagi('obtagujA');
    
   if (el){
   
     
    oldImage = el;
    oldId = el.id;
    oldA = el.parentNode;
    //el.parentNode.removeChild(el); to usuwa obrazek  
   
   var pozostale=new Array();
   
   pozostale=getElementsByClassName('image_sample_tap_selected'); 
   
   for (var i in pozostale){
    pozostale[i].className='image_sample_tap';
    }
   
    
   oldA.parentNode.className='image_sample_tap_selected'; 
   
   
   bprev=parseInt(idZdjecie)-1;
   if (bprev<0) bprev=0;
    
   if (parseInt(idZdjecie)>0) {
   var leftgo=document.getElementById('leftgo');
   leftgo.onclick=function () {wczytaj(tabImg,bprev,'',1,blimit,slimit);};
   }
   
   if (parseInt(idZdjecie)==0) {
   var leftgo=document.getElementById('leftgo');
  // leftgo.onclick=function () {if (otherPage(document.location.href,1,slimit)) document.location.href=otherPage(document.location.href,1,slimit);};
   leftgo.onclick=function () {if (otherPage(document.location.href,1,slimit)) hiddenPost(otherPage(document.location.href,1,slimit),1);};
   }
      
   bnext=parseInt(idZdjecie)+1;
   if (bnext>blimit) {  
   var reload=document.location.href;
   reloadgo=otherPage(reload,2,slimit);
   var rightgo=document.getElementById('rightgo');
   rightgo.onclick=function () {if (otherPage(document.location.href,2,slimit)) document.location.href=reloadgo;};   
   }
   
   if (parseInt(idZdjecie)<blimit) {
   var rightgo=document.getElementById('rightgo');
   rightgo.onclick=function () {wczytaj(tabImg,bnext,'',2,blimit,slimit);};
   }
   
   
   }
   
      if (dir){ 
      
   goback=parseInt(idZdjecie)-1;
   gofor=parseInt(idZdjecie)+1;
   if (goback<0) goback=0;
   if (gofor>blimit) gofor=blimit;

   if (goback==0) {
   var leftgo=document.getElementById('leftgo');
   //leftgo.onclick=function () {if (otherPage(document.location.href,1,slimit)) document.location.href=otherPage(document.location.href,1,slimit);};
   leftgo.onclick=function () {if (otherPage(document.location.href,1,slimit)) hiddenPost(otherPage(document.location.href,1,slimit),1);};
   }

   if (idZdjecie>0) { 
   var leftgo=document.getElementById('leftgo');
   leftgo.onclick=function () {wczytaj(tabImg,goback,'',1,blimit,slimit);};
   }
      if (parseInt(idZdjecie)<blimit) {
   var rightgo=document.getElementById('rightgo');
   rightgo.onclick=function () {wczytaj(tabImg,gofor,'',2,blimit,slimit);};
   }

   
   if (dir==1) {
   var leftgo=document.getElementById('leftgo');
   leftgo.onclick=function () {wczytaj(tabImg,goback,'',1,blimit,slimit);}
   var rightgo=document.getElementById('rightgo');
   rightgo.onclick=function () {wczytaj(tabImg,gofor,'',2,blimit,slimit);}
   
   }
   
   
    if (dir==1 && bprev>0){
    bprev--;
    bnext--;  
    }
    
    if (dir==2 && bnext<blimit){
    
    bprev++;
    bnext++;

    }
   

      
   var pozostale=new Array();
   pozostale=getElementsByClassName('image_sample_tap_selected'); 
   
   for (var ii in pozostale){
    pozostale[ii].className='image_sample_tap';
    }
    
   var wybierz=document.getElementById('imgSample'+i);
   wybierz.className='image_sample_tap_selected';
   
   //blimit=8; problem polega na tym, że nie są wczytywane te wartości
   //slimit=22;
             
   if (i==blimit){
           
    var reload=document.location.href;
    reloadgo=otherPage(reload,2,slimit);
    if (reloadgo){
   var rightgo=document.getElementById('rightgo');
   rightgo.onclick=function () {document.location.href=reloadgo;};
    }
    
          }
          
   if (i==0){
          
    var reload=document.location.href;
    reloadgo=otherPage(reload,1,slimit);
    if (reloadgo){
   var leftgo=document.getElementById('leftgo');
   leftgo.onclick=function () {if (otherPage(document.location.href,1,slimit)) hiddenPost(otherPage(document.location.href,1,slimit),1);};
    }
    
          }          
          
     
    }
    
  

   }
    
  
  
  
  
  function otherPage(url, dir, slimit){
  
   var regex = /\/page\/([0-9]+)\//;
   var regarr = regex.exec(url);
 
 if (dir==1){
 
    var regarrminus=parseFloat(regarr[1])-1;
    if (regarrminus>=0) {
    regarr[1]--;
    var reloadgo = url.replace(/\/page\/([0-9]+)\//, "/page/"+regarr[1]+"/");
    return reloadgo; 
    }   
    }
 
 
    if (dir==2){
    var regarrplus=parseFloat(regarr[1])+1;
    if (regarrplus<slimit) {
    regarr[1]++;
    var reloadgo = url.replace(/\/page\/([0-9]+)\//, "/page/"+regarr[1]+"/");
    return reloadgo; 
    }   
    }
  
  }  
  
  function hiddenPost(url, back){
  var hiddenForm=document.getElementById('hiddenform');
  hiddenForm.action=url;
  hiddenForm.hiddenpost.value=back;
  hiddenForm.submit();
  
  }
  
  function getElementsByClassName(classname) {
      var a = [];
      var re = new RegExp('\\b' + classname + '\\b');
      var els = document.body.getElementsByTagName("div");
       for(var i=0,j=els.length; i<j; i++)
            if(re.test(els[i].className))a.push(els[i]);
            return a;
       }


  
  
  
  function shadowImg()
  {
     
    if(ie && ileAlfaIe<101) 
    {
    ileAlfaIe = ileAlfaIe+1;
    divPod.style.filter="alpha(opacity="+ileAlfaIe+")";
    
        if(imageSemiTap.childNodes[1])
        {
          var iu = 100-ileAlfaIe;
          imageSemiTap.childNodes[0].style.filter="alpha(opacity="+iu+")";
        }
    }
    else if(ie && ileAlfaIe>=100)
    {
        if(imageSemiTap.childNodes[1])
        {
          imageSemiTap.removeChild(imageSemiTap.childNodes[0]);
        }
        return 1;
    }
    
    
    
    if(ns6 && ileAlfaNs<1.01)
    {
    ileAlfaNs = ileAlfaNs+0.01;
    divPod.style.MozOpacity=ileAlfaNs;
       if(imageSemiTap.childNodes[2])
        {
          
          var iu = 1-ileAlfaNs;
          imageSemiTap.childNodes[1].style.MozOpacity=iu;
        }

    }
    else if(ns6 && ileAlfaNs>=1) 
    {
        if(imageSemiTap.childNodes[2])
        {
          imageSemiTap.removeChild(imageSemiTap.childNodes[1]);
        }
        return 1;
    }
    


    var t=setTimeout("shadowImg()",1);

  }
  
   function submitCat(objectID,event)
  {
    var node = document.getElementById(event);
    var valueSelect = node.options[objectID].value; 
    window.location.href = valueSelect;  
  }
  
  
  function getButton(f)
  {
      var button = document.createElement('div');
      var button_left = document.createElement('div');
      var button_middle = document.createElement('div');
      var textButton = document.createElement('div');
      var button_right = document.createElement('div');
      
      button.className = 'button';
      button_left.className = 'button_left';
      button_middle.className = 'button_middle';
      textButton.className = 'textButton';
      button_right.className = 'button_right';
      
      
      textButton.innerHTML = 'OK';
      
      button_middle.appendChild(textButton);
      
      button.appendChild(button_left);
      button.appendChild(button_middle);
      button.appendChild(button_right);
      
      
      button.onclick=function(){
      if(f==0) wyslij();
      else if(f==1) wyslijTag();
      };
      
      return button;
      
  }
  
  function pobierzPulpit()
  {
    var iloscPob = document.getElementById('ilosc_pobT');
    var oldIlePob = parseInt(iloscPob.innerHTML);
    var id = document.getElementById('idT').value;
     
    if(idCat && maxImg)
    {
    window.location = "http://www.pogoda.ekologia.pl/assets/php/wallpaper/pobierz.php?idcat="+idkomorka+"&name="+maxImg+'&id='+id; 
    
    iloscPob.innerHTML = '';
    iloscPob.innerHTML =oldIlePob+1;
    
    }
   
    
    
    
  }
  
  
  var tabImg = new Array();
  
  function stripSpaces(txt) {
    
    
   if (txt.length==2) {txt=''; }           
   //var re = new RegExp("</?a[^>]*>","gi");
 //txt = txt.replace(, '') ;  
     
    return txt;
}


