/**
 * @author blazsak
 */

Cufon.replace('#mainmenu a,#minifolio a,#folio a,#plenery a,#folio-cat a ', {hover: true});
Cufon.replace('h1,h2,h3,h4,h5,h6');

var imgL = 0;

 $(document).ready(function(){ 
    //if ( $.browser.msie && $.browser.version < 7 ) alert('old ie');
   
   $("img.lazy").lazyload({ threshold : 200 });
    
   $('#folio li, #folio-cat li').mouseenter(function(){
     $(this).animate(
     {
       opacity: 0.8
     },
      200,  
      function()
      { 
         $(this).animate(
        {
          opacity: 1
        });
      }
     );      
   });
   
   var api = $("div.scrollable").scrollable({
     api: true,
     size: 8
   }); 
  
   $('#cu3er a').cycle({
     fx: 'fade',
     timeout: 4000,
     speed: 2000
     
   });
   $('#portfolio img').click(function(){
    // api.reload();
     var id = $(this).attr('id');
     var current = api.getClickIndex();
     var size = api.getSize()
     var next =  size <= current + 1 ? 0 : current + 1;  
   //  alert('id: #' + id + ',current: '+current + ', size: ' + size + ', next: ' + next);
     $('#thumb-'+next).click();
     //api.click(next);
   })  
   $(".items img ").click(function() { 
     /* OLD
    var url = $(this).attr("alt"); 
 
    var wrap = $("#portfolio").fadeTo("medium", 0.3); 
    var img = new Image(); 
    img.onload = function() { 
       wrap.fadeTo("medium", 1); 
       wrap.find("img").attr("src", url); 
    }; 
   img.src = url; 
   console.log("URL:", url);
   */
    // NEW
  
      var url = $(this).attr("alt");
      //alert(url);
      imgL = url;
      var wrap = $("#portfolio").fadeTo("medium", 0.3,function(){
       
      img = new Image();
      
      img.onload = function(){
        if (url == imgL) {
          wrap.fadeTo("medium", 1);
          wrap.find("img").attr("src", url);
          wrap.find("img").attr("id", 'foto-' + api.getClickIndex());
          //alert(api.getClickIndex());
        }
        
      };
      img.src = url;
      //console.log("URL:", url);  
      });
      
    
    

}).filter(":first").click();



   // $('#logo a, #galeria-link a,#foot-eve a, #portfolio-lista a div , .pngfix').pngFix();
    //$(document).pngFix();
    //$.swapImage(".swapImage");
    //$.localScroll();
    
    //$("a.preview").lightbox();
    //$("a.preview").fancybox({'overlayOpacity':0.7,  'overlayShow': true, 'zoomSpeedIn': 0, 'zoomSpeedOut': 0 }); 
    //$("a.preview").fancybox(); 
    //$("a.pagelink").fancybox({ frameWidth : 800, frameHeight : 600  });
    $("img[align='right']").css('float','right');
    $("img[align='left']").css('float','left');
   


   
  }); 
  
// PASSIVE FUNCTIONS  
function search_swap(option,text){
  var obj = $('#search_field');
 // alert(obj.val());
  if(option){
    if(obj.val()==text){
      obj.val('');
    }
  }else{
    if(obj.val()==''){
      obj.val(text);
    }
  }
}  

function openGallery(id)
  {
    var sw = screen.width ?  screen.width  : 1000;
    window.open('/ajax/zdjecia/'+id+'','Galeria', 'width='+sw+', height=660, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no');
  }

function fixPNG(myImage) 
{
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1]) 
  
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
     var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
     var imgTitle = (myImage.title) ? 
                 "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
     var imgStyle = "display:inline-block;" + myImage.style.cssText
     var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
     myImage.outerHTML = strNewHTML   
    }
}





