var category = new Array('novinky','priroda');
var url= window.location.pathname;    //vezmu vstupni url
var ref= url.substring(12);           //oriznu na tvar kategorie/cislofotky.html
var ref = ref.substr( 0, ref.lastIndexOf( '.' )); //uriznu priponu
var thumbs = new Array();
var rounds = new Array();
var target=0;
var zoomed=1;
var active=0;
var tr=Effect.Transitions.Sinoidal;
var karH=0;
var max=0;
var klik=0;




function init(){

if ($('slideshow')) {
slideshow();
//$('likebox').setStyle({top:450+'px',left:470+'px'} )
$('thumbs').setStyle({overflow:'hidden'} );
$('helper').setStyle({overflow:'hidden'} )
$('likebox').update('<fb:like href="http://www.petrhrudka.cz"  width="1280" show_faces="false" action="like" layout="button_count" send="false" colorscheme="dark" font="arial"></fb:like>');
FB.Event.subscribe('xfbml.render', function(response) {

                                   new Effect.Appear('likebox',{duration: 0.05, from:     0, to:1})
});

FB.XFBML.parse(document.getElementById('likebox'));
toplist=new Image();
    toplist.src='http://toplist.cz/dot.asp?id=1128971&amp;http='+escape(document.referrer)+'&amp;wi='+escape(window.screen.width)+'&amp;he='+escape(window.screen.height)+'&amp;cd='+escape(window.screen.colorDepth)+'&amp;t='+escape(document.title)+'" width="1" height="1" alt="TOPlist" />';
};
if ($('forum')) {
                $('forum').setStyle({height: 'auto'});
                h=$('forum').getHeight();
                $('helper').setStyle({height: 'auto', overflow:'visible'});
                $('thumbs').setStyle({height: 'auto', overflow:'visible',top: 55+'px'});
                };
if ($('karuselcenter')) {
                  karH=$('karuselcenter').getHeight();
                  max=Math.round(karH/560)
                  if (karH<635){$('next').setStyle({visibility:'hidden'});$('prev').setStyle({visibility:'hidden'});}
                  //if  (klik==0){new Effect.Appear('prev',{duration: 0.2, from:     1, to:0})}
                  thumbs=$('karuselcenter').select('.thumbnail').toArray();
                  rounds=$('karuselcenter').select('.rounded').toArray();
                  target=thumbs.indexOf($(ref.replace('/', '-')) );


                  $('fotka').observe('load', (function(event) {

                  var w = $('fotka').naturalWidth;
                  var h = $('fotka').naturalHeight;

                  if (h>650){


                  $('fotka').setStyle({display: 'none',height: 600+'px',width: (600/h)*w+'px',left: -200+'px',top:10+'px' })
                  //$('imgcont').observe('click', function(event){zooming();event.stop();});
                  }


                  else if (w>1200){

                  $('fotka').setStyle({display: 'none',height: (900/w)*h+'px',width: 900+'px',left:-200+'px',top:10+'px' })

                  }



                  else {



                  $('fotka').setStyle({display: 'none',height: h+'px',width: w+'px',left:-200+'px',top:10+'px'  })

                  }


                  showPhoto(h,w);


                  }));

                  loadThumb(thumbs);

                  if (target==-1) {
                  target=0;
                  active=0;
                  setPhotoSrc(thumbs[target]);
                  }
                  
                  else {
                  if ((target>0) && (target <=32 )){klik=0}
                  else if ((target>32) && (target <=64 )){klik=1}
                  else if ((target>64) && (target <=96 )){klik=2}
                  else if ((target>96) && (target <=128 )){klik=3}
                  else if ((target>128) && (target <=160 )){klik=4}
                  else if ((target>160) && (target <=192 )){klik=5}
                  
                  active=target;
                  setPhotoSrc(thumbs[target]);


                  thumbs[target].observe('load',function(event){



                  offset=rounds[target].offsetTop;



                  if (offset>620){

                  moveTo(offset-310);

                  }
                  })



                  }
                  $('next').observe('click', function(event){moveUp();});
                  $('prev').observe('click', function(event){moveDown();});

                  };











// thumbs.each (function (th) {
//         th.observe ('mouseover', function(){
//             new Effect.Appear(th,{duration:0.15, from:     0.3, to:0.6})
//         });
//     });
// thumbs.each (function (th) {
//         th.observe ('mouseout', function(){
//             new Effect.Appear(th,{duration:0.15, from:     0.6, to:0.3})
//         });
//     });
};







function loadThumb(th){

       function rep(i,th){







       if (i<th.length){
       filename=th[i].id.split('-')[1];
       th[i].src= '/data/cache/thumb-'+filename+'.jpg';
       th[i].setStyle({opacity:0});
       th[i].setStyle({visibility:'visible'});
       $(th[i]).observe('load', function(event){
       new Effect.Appear(th[i],{duration: 0.05, from:     0, to:1,delay:0,afterFinish: function(){

                                                                                              if(i!=target){
                                                                                              new Effect.Appear(th[i],{duration: 0.3, from:     1, to:0.5,delay:0});

                                                                                              }
                                                                                              else{
                                                                                              new Effect.Parallel([

                                                                      new Effect.Appear(th[i],{sync:true, from:     0.5, to:1}),


                                                                      new Effect.Scale(th[i],135, {sync: true, scaleFrom: 100, scaleFromCenter: true, scaleMode: { originalHeight: 70,originalWidth: 70},transition:Effect.Transitions.spring}),
                                                                      ], {
  queue:'start',
  duration: 0.4,
  delay:0,
  beforeStart: function (){

                          th[i].setStyle({zIndex:'1000' })

                          rounds[i].setStyle({overflow:'visible'  })
                          },
  afterFinish: function (){

                          }
   }
);
                                                                                              }


                                            $(th[i]).observe('click', function(event){

                                                 setPhotoSrc(th[i-1]);

                                                 new Effect.Parallel([

                                                                      new Effect.Appear(th[active],{sync:true, from:     1, to:0.5}),
                                                                      new Effect.Appear(this,{sync:true, from:     0.5, to:1}),
                                                                      new Effect.Scale(this,135, {sync: true, scaleFrom: 100, scaleFromCenter: true, scaleMode: { originalHeight: 70,originalWidth: 70},transition:Effect.Transitions.spring}),
                                                                      new Effect.Scale(th[active],100, {sync: true, scaleFrom: 150, scaleFromCenter: true, scaleMode: { originalHeight: 70,originalWidth: 70},transition:Effect.Transitions.spring}),

                                                                      ], {
  queue:'start',
  duration: 0.4,
  delay:0,
  beforeStart: function (){

                          th[active].setStyle({zIndex:'201',cursor:'pointer'  })
                          //th[i-1].stopObserving();
                          th[i-1].setStyle({zIndex:'1000',cursor:'default' })
                          rounds[i-1].setStyle({overflow:'visible'})
                          rounds[active].setStyle({overflow:'hidden'  })

                          },
  afterFinish: function (){

                          },
  beforeUpdate: function (){



                         }
   }
);

                                                 active=i-1;

                                            });
                                                                                               rounds[i].setStyle({visibility:'visible'});
                                                                                               i++;
                                                                                              rep(i,th);

                                                                                                 }});
                                                                                                 })




                         }
       };




       rep(0,th);

};

function moveTo(offset){


new Effect.Parallel([

new Effect.Move('karuselcenter',{sync: true, x: 0, y:-offset, mode: 'relative'}) ,

], {
  queue: 'start',
  duration: 2,
  delay:0,
  beforeStart: function (){

                          },
  afterFinish: function (){


                           }
   }
);

};


function moveDown(){
if (klik>0){
new Effect.Parallel([


new Effect.Move('karuselcenter',{sync: true, x: 0, y:560, mode: 'relative'}) ,


], {
  queue: 'start',
  duration: 0.5,
  delay:0,
  beforeStart: function (){


                           klik--;

                          },
  afterFinish: function (){



                           }

   }
);


}
if  (klik==max-2){new Effect.Appear('next',{duration: 0.2, from:     0, to:1})}
if  (klik==0){new Effect.Appear('prev',{duration: 0.2, from:     1, to:0})}
};


function moveUp(){

if (klik<max-1){

new Effect.Parallel([

new Effect.Move('karuselcenter',{sync: true, x: 0, y:-560, mode: 'relative'}) ,


], {
  queue: 'start',
  duration: 0.5,
  delay:0,
  beforeStart: function (){

                           klik++;
                          },
  afterFinish: function (){


                          }
   }
);

}

if  (klik==max-1){new Effect.Appear('next',{duration: 0.2, from:     1, to:0})}
if  (klik==1){new Effect.Appear('prev',{duration: 0.2, from:     0, to:1})}
};


function setPhotoSrc(thumb){


var h = $('fotka').naturalHeight;

var sch = $('fotka').getHeight();

if (h==sch){s=(600/h)*100}
else {s=100}

    new Effect.Parallel([
    new Effect.Move('fotka',{sync: true, x: -100, y:10, mode: 'absolute',transition:Effect.Transitions.sinoidal}),
    new Effect.Morph('imgcont',  {sync: true, style :'height: 620px'}),
    //new Effect.Scale('fotka',s, {sync:true, scaleFrom: 100,scaleFromCenter: false}),

    new Effect.Opacity('fotka', {sync: true, from: 1,to: 0})
], {
  duration: 0.2,
  delay:0,
  queue: 'start',
  beforeStart: function (){},
  afterFinish: function (){


  new Effect.Appear('likebox',{duration: 0.05, from:     1, to:0})
      new Effect.Appear('loadfotka',{duration: 0.2, from:     0, to:1,delay:0})
    new Effect.Appear('likebox',{duration: 0.2, from:     1, to:0})

    new Effect.Appear('fotka',{duration: 0.5, from:     1, to:0,delay:0,afterFinish:function()

    {

    path = thumb.id.replace('-','/');
    $('fotka').setAttribute('src', '/data/'+path+'.jpg');


    var stateObj = {a:'b'}
    if (history.pushState){
    history.pushState(stateObj, 'title', '/fotografie/'+ path+ '.html');
    };
    file=path.split("/");

    $('likebox').update('<fb:like href="'+'http://' +document.domain+ '/fotografie/priroda/' +file[1]+ '.html'+'"  width="450" show_faces="false" action="like" layout="standard" send="true" colorscheme="dark" font="arial"></fb:like>');

    if (typeof(_gat) == 'object'){
     var pageTracker = _gat._getTracker('UA-12889070-1');
     pageTracker._trackPageview('/fotografie/'+ path +'.html');
    };


    }



    })





                           }
  }
);














};







function showPhoto(h,w){

new Effect.Appear('loadfotka',{duration: 0.2, from:     1, to:0})




$('fotka').setOpacity(0);
$('fotka').setStyle({visibility: 'visible'});
$('fotka').setStyle({display: 'block'});

w=$('fotka').getWidth();

new Effect.Parallel([
new Effect.Move('fotka',{sync: true, x: (920-w)/2, y:10, mode: 'absolute',transition:Effect.Transitions.sinoidal}),


new Effect.Opacity('fotka', {sync: true, from: 0,to: 1.0})
], {
  duration: 0.3,
  delay:0,
  queue: 'end',
  beforeStart: function (){},
  afterFinish: function (){
                           if( zoomed==1){
                           zoomed=0;
                           zooming();
                           }

                           FB.Event.subscribe('xfbml.render', function(response) {

  new Effect.Appear('likebox',{duration: 0.05, from:     0, to:1})
});

FB.XFBML.parse(document.getElementById('likebox'));


                           toplist=new Image();
    toplist.src='http://toplist.cz/dot.asp?id=1128971&amp;http='+escape(document.referrer)+'&amp;wi='+escape(window.screen.width)+'&amp;he='+escape(window.screen.height)+'&amp;cd='+escape(window.screen.colorDepth)+'&amp;t='+escape(document.title)+'" width="1" height="1" alt="TOPlist" />';

                           }
  }
);
};

function zooming(){
var w = $('fotka').naturalWidth;
var h = $('fotka').naturalHeight;
var scw = $('fotka').getWidth();
var sch = $('fotka').getHeight();


if (zoomed==0){


               new Effect.Scale('fotka', (h/sch)*100,{duration: 0.15, scaleFrom: 100, scaleFromCenter: true, scaleMode: { originalHeight: sch,originalWidth: scw},afterUpdate:function() {

               $('fotka').setStyle({left: 450-(($('fotka').getWidth())/2)+10+'px',top:10+'px'});
               $('imgcont').setStyle({height: $('fotka').getHeight()+20+'px'});

               },
               afterFinish: function(){
               zoomed=1;
               $('fotka').setStyle({width:w+'px',height:h+'px'});

               }
               })
               }
else if (zoomed==1){



               new Effect.Scale('fotka',(600/h)*100, {duration: 0.15, scaleFrom: 100, scaleMode: { originalHeight: h,originalWidth: w},scaleFromCenter: true, afterUpdate:function() {

               $('fotka').setStyle({left: 450-(($('fotka').getWidth())/2)+10+'px',top:10+'px'});
               $('imgcont').setStyle({height: $('fotka').getHeight()+20+'px'});
               },
               afterFinish: function(){
               zoomed=0;
               }
               })

             }
}




window.onload=init;
;
