$(document).ready(function(){
   $('img').ifixpng();
   if (typeof(window.onload) != "undefined")
      var oldFunc = window.onload;
   window.onload = function() {
      Shadowbox.init();
      $(window).resize(function(){
         $('#content, #newsbox').css('height','auto');
         $('#content').height(document.body.clientHeight-164+'px');
         if ($('#content').height() > $('#newsbox').height())
            $('#newsbox').height($('#content').height());
         var i = 0;
         while ($('#main').height() > $('#newsbox').height()) {
            if (i == 10)
               break;
            $('#newsbox').height($('#main').height());
            i++;
         }
         $('.resizeMeToo').height(window.innerHeight-166);
      });
      $('.searchBox').focus(function(){
         if ($(this).val() == $(this).attr('alt'))
            $(this).val('');
         $(this).css('color','#000000');
      }).blur(function(){
         if ($(this).val() == '') {
            $(this).val($(this).attr('alt'));
            $(this).css('color','#c0c0c0');
         }
      });
      if ($("#imagesBox").length > 0) {
         $("#imagesBox").css("height",$("#imagesBox img")[0].height);
         $("#imagesBox img.smallImage").css("margin-top",$("#imagesBox img")[0].height-55);
         $(window).resize(function(){
            if ($("#imagesBox img.smallImage").length > 0) {
               var firstTop = $("#imagesBox img.smallImage")[0].offsetTop;
               var lastTop = $("#imagesBox img.smallImage")[$("#imagesBox img.smallImage").length-1].offsetTop;
               if (firstTop != lastTop) {
                  $("#showImageMore").show();
               } else {
                  $("#showImageMore").hide();
               }
            }
         });
         $("#imagesBox img").each(function(){
            var targetThumb = $('#forPic_'+$(this).attr('id').replace('thumb_for',''))[0];
            var linkElement = this;
            $(this).mouseover(function(){
               $('.picFrame').hide();
               $(targetThumb).show().css({
                  'top': ((linkElement.offsetTop+linkElement.height)-$(targetThumb).height())+105,
                  'left': this.offsetLeft+15
               });
            });
            $(targetThumb).hover(function(){},function(){
               $(this).hide();
            }).click(function(){
               $(linkElement).click();
            });
         });
      }
      $(window).resize();
      if (typeof(oldFunc) == "function")
         oldFunc();
   }
});
function searchForFilms() {
   var url = document.location.href.split('films')[0]+'films/search';
   url += '/'+$('select[name=search_categ]').val();
   url += '/'+$('select[name=search_topic]').val();
   url += '/'+$('input[name=search_from]').val();
   url += '/'+$('input[name=search_to]').val();
   url += '/'+$('input[name=search_freetext]').val();
   url += '/1'; //paging
   document.location.href = url;
}