// tworzy obiekt do asynchronicznego transferu danych
var xmlHttp = createXMLHttpRequestObject();

//przełącza zakładki pod głównym filmem
function przelacz_zakladke(iZakladka)
{
    var oZakladka = new Array();
    oZakladka[1] = document.getElementById('content_o_filmie');
    oZakladka[2] = document.getElementById('content_zdjecia');
    oZakladka[3] = document.getElementById('content_komentarz');
    oZakladka[4] = document.getElementById('content_slownik');
    
    oZakladka[1].style.display = 'none';
    oZakladka[2].style.display = 'none';
    oZakladka[3].style.display = 'none';
    oZakladka[4].style.display = 'none';
    
    oZakladka[iZakladka].style.display = '';
}

//pobiera obrazek do galerii
function pobierz_obrazek(oSpan)
{
    var poprzednie = document.getElementById('obrazek_poprzednie');
    var nastepne = document.getElementById('obrazek_nastepne');
    
    var idFilm = poprzednie.getAttribute('film');
    
    var iNumer = oSpan.getAttribute('numer');
    //zmieniamy aktywnosc
    if (xmlHttp)
      {
      try
        {
        xmlHttp.open("GET", "validate/film_pobierz_zdjecie.php?film=" + idFilm + "&numer=" + iNumer + "&ran=" +Math.random());
        xmlHttp.onreadystatechange = function ()
          {
          if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
          {
          xml = xmlHttp.responseXML.documentElement;
          
          var opis = xml.getElementsByTagName('opis')[0].firstChild.nodeValue;
          document.getElementById('opis_zdjecia').innerHTML = opis;
          
          var img = xml.getElementsByTagName('url')[0].firstChild.nodeValue; 
          document.getElementById('obrazek').src = img;    
         
          var height = xml.getElementsByTagName('height')[0].firstChild.nodeValue;
          document.getElementById('obrazek').height = height;   

          var nr_nastepny = xml.getElementsByTagName('nr_nastepny')[0].firstChild.nodeValue;
          var nr_poprzedni = xml.getElementsByTagName('nr_poprzedni')[0].firstChild.nodeValue;
          
          var flaga = xml.getElementsByTagName('flaga')[0].firstChild.nodeValue; 
          if (flaga == '0')
              { 
              poprzednie.style.color = '#ffffff'; 
              poprzednie.setAttribute('numer','');
              nastepne.style.color = '#0d5088';
              nastepne.setAttribute('numer', nr_nastepny);              
              }
          else if (flaga == '1')
              {
              poprzednie.style.color = '#0d5088';
              nastepne.style.color = '#0d5088';
              poprzednie.setAttribute('numer', nr_poprzedni);            
              nastepne.setAttribute('numer', nr_nastepny);                 
              }
          else
              {
              poprzednie.style.color = '#0d5088';
              nastepne.style.color = '#ffffff'; 
              poprzednie.setAttribute('numer', nr_poprzedni);             
              nastepne.setAttribute('numer','');                
              }
          }
          }
        xmlHttp.send(null);        
        }
      catch (oError)
        {
        alert("Błąd na serwerze! Proszę spróbować później!");
        }
      }
}

//oceniamy film
function ocen(iOcena)
{
    //id filmu
    var poprzednie = document.getElementById('obrazek_poprzednie');
    var idFilm = poprzednie.getAttribute('film');
    
    //zmieniamy aktywnosc
    if (xmlHttp)
      {
      try
        {
        xmlHttp.open("GET", "validate/film_ocen.php?film=" + idFilm + "&ocena=" + iOcena + "&ran=" +Math.random());
        xmlHttp.onreadystatechange = function ()
          {
          if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            document.getElementById('ocen_film').innerHTML = '<div class="t28sub" style="width:100%; text-align:center">Dziękujemy!</div>';
          }
        xmlHttp.send(null);        
        }
      catch (oError)
        {
        alert("Błąd na serwerze! Proszę spróbować później!");
        }
      }
}

$(document).ready(function(){
  $('#info').click(function(){
    $(this).slideUp(500,function(){
      $(this).next().slideDown(1000);
    });
  });
  
  $('#zwin').click(function(){
    $(this).parent().slideUp(1000,function(){

        $(this).prev().slideDown(500);

    });
  });  
  
});

