var category = new Array('novinky','modelky');
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:50+'px',left:20+'px'} )
$('thumbs').setStyle({overflow:'hidden'} );
$('helper').setStyle({overflow:'hidden'} )
$('likebox').update('<fb:like href="http://www.glamour-modelky.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=1006978&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();
                  $('fotka').observe('click',(function(event){zooming();}));
                  max=Math.round(karH/80)-6;
                  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' })
                  }
                  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]);

if (window.addEventListener)
        //  mozilla
        window.addEventListener('DOMMouseScroll', wheel, handle);
// IE/Opera
window.onmousewheel = document.onmousewheel = wheel;

                  }
                  
                  else {
                  klik=Math.round(target/4);
                  if (window.addEventListener)
        //mozilla
        window.addEventListener('DOMMouseScroll', wheel, handle);
//IE/Opera
window.onmousewheel = document.onmousewheel = wheel;
                  active=target;
                  setPhotoSrc(thumbs[target]);
                  thumbs[target].observe('load',function(event){
                  if (klik>8){
                  moveTo(klik);
                  }
                  })
                  }
                  };
};

function handle(delta) {
        if (delta < 0)
 moveUp()
        else
   moveDown()
}
function wheel(event){
        var delta = 0;
        if (!event) //ie
                event = window.event;
        if (event.wheelDelta) { //ie
                delta = event.wheelDelta/120;
        } else if (event.detail) { //fox

                delta = -event.detail/3;
        }

        if (delta)
                handle(delta);

        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}
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.7,
  delay:0,
  beforeStart: function (){

                          th[active].setStyle({zIndex:'201',cursor:'pointer'  })
                          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*80, mode: 'relative'}) ,

], {
  queue: 'start',
  duration: 0.5,
  delay:0,
  beforeStart: function (){

                          },
  afterFinish: function (){


                           }
   }
);

};


function moveDown(){

if (klik>0){
new Effect.Parallel([


new Effect.Move('karuselcenter',{sync: true, x: 0, y:80, mode: 'relative'}) ,


], {
  queue: 'start',
  duration: 0,
  delay:0,
  beforeStart: function (){


                           klik--;

                          },
  afterFinish: function (){



                           }

   }
);


}
};


function moveUp(){

if (klik<max-1){

new Effect.Parallel([

new Effect.Move('karuselcenter',{sync: true, x: 0, y:-80, mode: 'relative'}) ,


], {
  queue: 'start',
  duration: 0,
  delay:0,
  beforeStart: function (){

                           klik++;
                          },
  afterFinish: function (){


                          }
   }
);

}
};


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.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');
    //$('story').setAttribute('content','Novej obsah, Jana Miklová');
    //$('url').setAttribute('content','http://www.glamour-modelky.cz/fotografie/'+ path +'.html');


    var stateObj = {a:'b'}
    if (history.pushState){
    history.pushState(stateObj, 'title', '/fotografie/'+ path+ '.html');
    };
    file=path.split("/");
    $('link').setAttribute('href','/data/cache/thumb-'+file[1]+'.jpg');
    $('likebox').update('<fb:like href="'+'http://' +document.domain+ '/fotografie/modelky/' +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=1006978&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;
;
