
var pageTitle = 'Brzydula';

Event.observe(window, 'load', function() {
   if (!document.all) return;
   var t = document.title;
   t = t.replace(/#.*/ , '');
   if (t) pageTitle = t;
   else t = pageTitle;
   document.title = t;
   setTimeout(arguments.callee, 1000);
});

var Init = {

   queue: {},
   
   start: function() 
   {
      var list = [];
      for (var i in Init.queue)
      {
         list.push(i);
      }
      Init.initDeps(list);
   },

   initDeps: function(deps)
   {
      for (var i = 0; i < deps.length; i++)
      {
         var name = deps[i];
         if (typeof Init.queue[name] != 'undefined')
         {
            if (typeof Init.queue[name].inited == 'undefined')
            {
               Init.queue[name].inited = true;
               if (typeof Init.queue[name].deps == 'object' && Init.queue[name].deps.constructor == Array)
               {
                  Init.initDeps(Init.queue[name].deps);
               }
               Init.queue[name].func();
            }
         }
         else
         {
            var url = window.location.pathname + window.location.search + window.location.hash;
            var img = new Image(1,1);
            img.src = 'ajax/3742,' + escape(name) + ',' + escape(url.replace('/', '|', 'g').replace(',', '!', 'g')) + ',notice.html';
         }
      }
   }
   
};




var top_timer = null;

function resizeMe(eid, h)
{
   var step = 20;
   var elem = document.getElementById(eid);
   
   if(elem.offsetHeight > h)
   {
      step = -step;
   }
   if (top_timer != null)
   {
      clearTimeout(top_timer);
      top_timer = null;
   }
   top_timer = setInterval(function()
   {
      var he = elem.offsetHeight;
      
      if(step > 0 && he + step < h || step < 0 && he + step > h)
      {
         elem.style.height = (he + step)+'px';      
      }
      else
      {
         clearTimeout(top_timer);
         top_timer = null;
         elem.style.height = h + 'px';
      }
   }, 10);   
}

function getFlashVersion()
{
   var version = deconcept.SWFObjectUtil.getPlayerVersion();
   if (document.getElementById && (version['major'] > 0)) {
      return version['major'];
   }
}

/**
  * ImageSlider
  * @author: Jakub Biczkowski <jakub.biczkowski@dreamlab.pl>
  * @version 1.0 
  *
  * Parametry:
  * i - identyfikator DOM kontrolki
  * c - zaznaczony element
  * v - ilosc widocznych elementow
  * w - szerokosc elementu
  * p - padding-left elementu
  * a - wartosc boolowska, czy strzalki sa widoczne (w razie uzywania zewnetrznej nawigacji mozna je wylaczyc)
  * 
  * Metody:
  * initialize  - konstruktor
  * collect     - zebranie do tablicy this.elemArray wszystkich elementow
  * select      - zaznaczenie elementu
  * setArrows   - ustalenie widocznosci strzalek nawigacyjnych
  * forward     - przesuniecie elementow wprzod
  * backward    - przesuniecie elementow wstecz
  *
  * 
  * "element" to div z pojedyncza miniaturka zdjecia
  *
  */

function ImageSlider(i,c,v,w,p,a)
{
   this.obj         = document.getElementById(i);
   this.current     = c;  
   this.visElems    = v;
   this.elemWidth   = w;
   this.elemPadd    = p;
   this.arrowVis    = a; 

   this.step        = 10; // jednostkowe przesuniecie w animacji   
   this.arrowWidth  = 35;
   this.avaible     = 1;

   this.sgroup      = this.obj.firstChild.nextSibling.firstChild; // przesuwany div, kontener elementow
   this.elemSize    = this.elemWidth + this.elemPadd; // pelna szerokosc elementu (szerokosc + padding)
   this.floor_vE    = Math.floor(this.visElems / 2); 
   this.ceil_vE     = Math.ceil(this.visElems / 2);
   this.elemArray   = new Array();   
}

/** 
  * medotda: initialize 
  * konstruktor
  *
  * - wywolanie metody collect
  * - ustalenie odpowiednich styli
  * - wywolanie metody select
  * - ustawnienie parametru this.mcurrent (ktory element jest pierwszy na liscie)
  * - ustawienie stylu - poczatkowa pozycja
  * - odpowiednie ustawienie strzalek
  **/
ImageSlider.prototype.initialize = function()
{
   try
   {
      //zebranie do tablicy this.elemArray wszystkich elementow
      this.collect(this.sgroup.childNodes);                 
      
      // ustawienie styli
      
      if(!this.arrowVis)
      {
         this.obj.firstChild.style.display = 'none';
         this.obj.firstChild.nextSibling.nextSibling.style.display = 'none';
         this.arrowWidth  = 0;
      }
      
      var picwidth = (this.visElems * this.elemWidth) + (this.visElems-1) * this.elemPadd;
      this.obj.firstChild.nextSibling.style.width = picwidth + 'px';      
      var ctrlwidth = picwidth + (2 * this.arrowWidth);
      this.obj.style.width = ctrlwidth + 'px';            
      var sgrw = (this.elemArray.length * this.elemSize) + 0;
      this.sgroup.style.width = sgrw + 'px';
      this.sgroup.style.left = '0px';    
      this.obj.style.display = 'block';
      
      if(this.current>=0)
      {      
         this.select(this.current);  
      }
      // ustawnienie parametru this.mcurrent
      if(this.visElems >= this.elemArray.length)
      {
         this.mcurrent    = 0;
      }
      else
      {
         if(this.current < this.ceil_vE)
         {
            this.mcurrent    = 0;
         }
         else if(this.current >= this.ceil_vE && this.current < (this.elemArray.length - this.ceil_vE))
         {
            this.mcurrent    = this.current - this.floor_vE;
         }
         else
         {
            this.mcurrent = this.elemArray.length - this.visElems;
         }                  
      }
      
      // ustawienie poczatkowej pozycji grupy elementow
      var em = -(this.mcurrent * this.elemSize);
      this.sgroup.style.left = em + 'px';
      
      // ustawienie klikalnosci strzalek
      this.setArrows();
   }
   catch(ex)
   {
      //alert('initialize - '+ex.message);
   }
}

ImageSlider.prototype.collect = function(s)
{
   try
   {
      for(var i=0; i<s.length; i++)
      {
         this.elemArray[i] = s[i];      
      }
   }
   catch(ex)
   {
      //alert('collect - '+ex.message);
   }
}

ImageSlider.prototype.select = function(j)
{
   try
   {
      for(var i=0; i<this.elemArray.length; i++)
      {
         this.elemArray[i].className = 'imageSliderElement';
      }
      this.elemArray[j].className = 'imageSliderElementSelected';
   }
   catch(ex)
   {
      //alert('select - '+ex.message);
   }
}

ImageSlider.prototype.setArrows = function()
{ 
   try
   {
      if(this.mcurrent<=0)
      {
         this.obj.firstChild.firstChild.style.display = 'none';
         this.obj.firstChild.className = 'imageSliderArrowBackwardDisabled';
      }
      else
      {
         this.obj.firstChild.firstChild.style.display = 'block';
         this.obj.firstChild.className = 'imageSliderArrowBackward';
      }
      
      if(this.mcurrent >= (this.elemArray.length-this.visElems))
      {
         this.obj.firstChild.nextSibling.nextSibling.firstChild.style.display = 'none';
         this.obj.firstChild.nextSibling.nextSibling.className = 'imageSliderArrowForwardDisabled';
      }
      else
      {
         this.obj.firstChild.nextSibling.nextSibling.firstChild.style.display = 'block';
         this.obj.firstChild.nextSibling.nextSibling.className = 'imageSliderArrowForward';  
      }
   }
   catch(ex)
   {
      //alert('setArrows - '+ex.message);
   }
}

ImageSlider.prototype.forward = function()
{
   try
   {  
      
      var smaxforward = -(parseInt(this.sgroup.style.width)-parseInt(this.obj.style.width)-parseInt(this.elemPadd));      
      
      if(this.avaible==1)
      {
         var parent = this;
         if(smaxforward>=parseInt(this.sgroup.style.left))
         {
            return false;
         }
         var destpos = parseInt(this.sgroup.style.left) - this.elemSize; //pozycja docelowa
         this.avaible = 0;
         
         var stimer = setInterval(function()
         {               
            var emove = parseInt(parent.sgroup.style.left) - parent.step;
         
            if(parseInt(parent.sgroup.style.left)>destpos && emove>=destpos)
            {
               parent.sgroup.style.left = emove + 'px';            
            }
            else
            {            
               parent.sgroup.style.left = destpos + 'px';
               clearInterval(stimer);                             
               stimer = null;            
               parent.mcurrent = parent.mcurrent + 1;      
               parent.setArrows();
               var p = parent;
               var kt = setTimeout(function(){p.avaible = 1;},50);
            }        
         }, 10);
      }
      
   }
   catch(ex)
   {
      //alert('forward - '+ex.message);
   }
}

ImageSlider.prototype.backward = function() 
{
   try
   {
      var smaxbackward = 0;
      
      if(this.avaible==1)
      {
         var parent = this;
         if(smaxbackward<=parseInt(this.sgroup.style.left))
         {
            return false;
         }
         
         var destpos = parseInt(this.sgroup.style.left) + this.elemSize; //pozycja docelowa
         this.avaible = 0;
      
         var stimer = setInterval(function()
         {      
            var emove = parseInt(parent.sgroup.style.left) + parent.step;
         
            if(parseInt(parent.sgroup.style.left)<destpos && emove<=destpos)
            {            
               parent.sgroup.style.left = emove + 'px';
            }
            else
            {            
               parent.sgroup.style.left = destpos + 'px';
               clearInterval(stimer);               
               stimer = null;            
               parent.mcurrent = parent.mcurrent - 1;      
               parent.setArrows();
               var p = parent;
               var kt = setTimeout(function(){p.avaible = 1;},50);               
            }        
         }, 10);
      }
   }
   catch(ex)
   {
      //alert('backward - '+ex.message);
   }
}










// ContentChanger
// @author: Jakub Biczkowski <jakub.biczkowski@dreamlab.pl>

function ContentChanger(i,c)
{
   this.obj         = document.getElementById(i);
   this.elemArray   = new Array();
   this.current     = c;
}

ContentChanger.prototype.initialize = function()
{
   try
   {      
      this.collect(this.obj.firstChild.childNodes);
      this.select(this.current);
      
   }
   catch(ex)
   {
      //alert('initialize - '+ex.message);
   }
}

ContentChanger.prototype.collect = function(s)
{
   try
   {
      for(var i=0; i<s.length; i++)
      {
         this.elemArray[i] = s[i];      
      }
   }
   catch(ex)
   {
      //alert('collect - '+ex.message);
   }
}

ContentChanger.prototype.select = function(j)
{
   try
   {
      for(var i=0; i<this.elemArray.length; i++)
      {
         this.elemArray[i].style.display = 'none';
      }
      this.elemArray[j].style.display = 'block';
   }
   catch(ex)
   {
      //alert('select - '+ex.message);
   }
}

ContentChanger.prototype.which = function(element, j)
{
   try
   { 
      elementID = document.getElementById(element).childNodes
       
      for(var i=0; i<elementID.length; i++)
      {
         elementID[i].style.display = 'none';
      }
      elementID[j].style.display = 'block';
   }
   catch(ex)
   {
      //alert('select - '+ex.message);
   }
}

ContentChanger.prototype.forward = function(element)
{
   try
   {
      if((this.elemArray.length-1)==this.current)
      {
         this.current = 0;
      }
      else
      {
         this.current += 1;
      }
      this.select(this.current);
      if(element)
      {
         this.which(element, this.current);
      }
   }
   catch(ex)
   {
      //alert('forward - '+ex.message);
   }
}

ContentChanger.prototype.backward = function(element)
{ 
   try
   {      
      if(this.current==0)
      {
         this.current = this.elemArray.length-1;
      }
      else
      {
         this.current -= 1;
      }
      
      this.select(this.current);
      if(element)
      {
         this.which(element, this.current);
      }      
   }
   catch(ex)
   {
      //alert('backward - '+ex.message);
   }
}

ContentChanger.prototype.autoplay = function(hash)
{
   try
   {
      document.location.href = this.elemArray[this.current].getElementsByTagName('a')[0]+hash;
   }
   catch(ex)
   {
      //alert('autoplay - '+ex.message);
   }
}

ContentChanger.prototype.add = function()
{
   try
   {
      alert('dodaj do playlisty: '+this.current);
   }
   catch(ex)
   {
      //alert('add - '+ex.message);
   }
}



function fontSizer(t,s)
{
   try
   {      
      var cDefault  = 'tresc';                   // domyslna nazwa klasy
      var cSmall    = cDefault + ' trescmala';   // klasa z czczionka mala
      var cBig      = cDefault + ' trescduza';   // klasa z czczionka duza

      var elem = t.parentNode;      
      while(elem.className !=cDefault && elem.className !=cSmall && elem.className !=cBig)
      {
         elem = elem.parentNode;
         if(elem.tagName=='BODY')
         {
            break;
         }
      }
      if(elem.className==cDefault || elem.className==cSmall || elem.className==cBig)
      {
         switch(s)
         {
            case 0: 
               elem.className=cSmall;
               t.className = 'maly tekst_rozmiary_aktywny';
               t.nextSibling.className = 'tekst_rozmiary_nieaktywny';
               t.nextSibling.nextSibling.className = 'duzy tekst_rozmiary_nieaktywny';
            break;
            
            case 1: 
               elem.className=cDefault;
               t.className = 'tekst_rozmiary_aktywny';
               t.previousSibling.className = 'maly tekst_rozmiary_nieaktywny';
               t.nextSibling.className = 'duzy tekst_rozmiary_nieaktywny';
            break;
            
            case 2: 
               elem.className=cBig;
               t.className = 'duzy tekst_rozmiary_aktywny';
               t.previousSibling.className = 'tekst_rozmiary_nieaktywny';
               t.previousSibling.previousSibling.className = 'maly tekst_rozmiary_nieaktywny';
            break;            
         }
      }
   }
   catch(ex)
   {
   }      
}


/**
  * szukajInput
  * @author: Jakub Biczkowski <jakub.biczkowski@dreamlab.pl>
  * @version 1.0 
  *
  * Parametry:
  * i - element DOM
  *
  */
function szukajInput(i)
{
   try
   {
      i.focus();
      i.select();
   }
   catch(ex)
   {
      alert(ex.message);
   }
   
}
/*
function aktualnezdjecie()
{
   document.getElementById('ilosc_zdjec').innerHTML = 'sss';
}
*/


/*
   Funkcja do przelaczania wybranego bloga w zajawce 
*/
function switch_blogger(blogger_id)
{
   // odznaczenie wszystkich wpisow
   var rows=$$('.blog_wpis');
   rows.each(
      function(row)
      {
         row.className = 'blog_wpis unselected';
       }
   );
  
   // zaznaczenie wybranego wpisu
   var blogger_id = 'blogger_' + blogger_id;
   $(blogger_id).className = 'blog_wpis selected';

   switch (blogger_id)
   {
      case 'blogger_569': $('prawa_swf').ustaw('zmuda'); break;
      case 'blogger_568': $('prawa_swf').ustaw('maciag'); break;
      case 'blogger_571': $('prawa_swf').ustaw('buzek'); break;
      // dostepne: zmuda, buzek, maciag, wieczorkowski, damiecki, kasprzykowski, krolikowski
   }
}