$(function(){
    $('form fieldset').jqTransform({
        imgPath:'/js/jqtransformplugin/img/'
    });
    
    $('#credits').each(function () {
        var distance = 10;
        var time = 250;
        var hideDelay = 150;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);


        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;
                
                info.html("Powered By <a href=\"http://www.greenbubble.it\"  title=\"Vai al sito\" onClick=\"javascript:ssxl('LINK=Greenbubble');\" target=\"_blank\">Greenbubble</a>");

                info.css({
                    top: -30,
                    right: 0,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });    
    
    $('#partners').each(function () {
        var distance = 10;
        var time = 250;
        var hideDelay = 150;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;
        var trigger = $('.trigger1', this);
        var info = $('.popup1', this).css('opacity', 0);
        
        var contenuto = $('#contenuto_partners');
        info.html(contenuto.html());
        var top = Math.round(String(info.css("height")).replace("px", "")) + 20;

        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;
                
                info.css({
                    top: -top,
                    right: -55,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;
                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');
                });

            }, hideDelay);

            return false;
        });
    });    
    
    $.Placeholder.init();

});

function chiudi_player() {
    $.prettyPhoto.close();
}

function animazione() {
    $('#riavviavideo').animate(

    {
            bottom: 0
        }, {
            duration: 1200,
            easing: 'easeInElastic'
                   
        });
}

Galleria.loadTheme('/galleria/themes/classic/galleria.classic.min.js');

$(document).ready(function(){	
    //menu
    mainmenu();
    thumbsimage();
    
    // Language Menu
    $("#lubeLangmenu .lubeButton").click(function(event){
        event.preventDefault();
        $("#lubeLangmenu .lubeDropdown").slideToggle(150);
    }).mouseenter(function(){
        $(this).addClass("lubeHover");
    }).mouseleave(function(){
        $(this).removeClass("lubeHover");
    });
    /* hide menu if clicked elsewhere or ESC pressed */
    $(document).click(function(e){
        if (!$(e.target).is('.lubeFlag')) {
            $("#lubeLangmenu .lubeDropdown").slideUp(250);
        }
    }).keypress(function(e){
        if (e.keyCode == 27) {
            $("#lubeLangmenu .lubeDropdown").slideUp(250);
        }
    });
    $("#lubeLangmenu .lubeDropdown").mouseenter(function(){
        $("#lubeLangmenu .lubeSelect").addClass("open");
    });
    $("#lubeLangmenu .lubeDropdown a").click(function(){
        var d = new Date(), v = $(this).attr("href");
        v = v.substr(v.lastIndexOf("/") + 1);
        d.setTime(d.getTime()+8553600000);
    //document.cookie="FRlangset="+v+"; expires="+d.toGMTString()+"; path=/; domain=cucinelube.it";
    }); 
    
    $(".video a[rel^='video']").prettyPhoto({
        theme: 'light_square',
        autoplay_slideshow:false,
        social_tools: '',
        showTitle: true,
        deeplinking: false,
        allow_resize: false,
        opacity:1,
        flash_markup: '<iframe id="player_3108"  width="560" height="315"  src="http://www.youtube.com/embed/TaSjEaLiFJE?enablejsapi=1&autoplay=1&rel=0"  frameborder="0" allowfullscreen></iframe>',
        callback: function () {
            animazione();
        }
    });
        
    //galleria    
    if ($('#gallery li').size() > 1) {    
        $('#gallery').bxSlider({
            auto: true,
            autoControls: false,
            controls: false,
            pause: 5000,
            autoHover: true,
            onAfterSlide: function(currentSlide, totalSlides){
                if ($('#gallery').css('display') == 'none')
                    $('#gallery').show();               
            }
        });
    } else
        $('#gallery').show();  
    
    $("#main a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'light_square',
        autoplay_slideshow:false,
        social_tools: '',
        showTitle: false,
        deeplinking: false,
        gallery_markup: ''
    });
    

    
    $(".galleria").galleria({
        width: 448,
        height: 420,
        imagePosition: "top",
        transition: "fade",
        lightbox: true,
        autoplay: true,
        imageTimeout: 300000,
        thumbQuality: 'auto',
        _toggleInfo: false
    });
    
    $(".galleria-mini").galleria({
        width: 258,
        height: 248,
        imagePosition: "top",
        transition: "fade",
        autoplay: false,
        popupLinks: true,
        imageTimeout: 300000,
        thumbQuality: 'auto',
        _toggleInfo: false
    });
    
   
    
    $(".galleria-news").galleria({
        width: 580,
        height: dammiAltezza(),
        imagePosition: "top",
        transition: "fade",
        lightbox: true,
        autoplay: true,
        imageTimeout: 300000,
        thumbQuality: 'auto',
        _toggleInfo: false
    }); 
            
    //zoomer
    $('ul.thumbs-zoomer li').Zoomer({
        speedView:200,
        speedRemove:400,
        altAnim:true,
        speedTitle:0,
        debug:false,
        width: 99,
        height: 99 
    });
    
    //zoomer
    $('ul.thumbs-zoomer-t li').Zoomer({
        speedView:200,
        speedRemove:400,
        altAnim:true,
        speedTitle:0,
        debug:false,
        width: 38,
        height: 38    
    });
    
    //zoomer
    $('ul.thumbs-zoomer-rassegna-redazionale li').Zoomer({
        speedView:200,
        speedRemove:400,
        altAnim:true,
        speedTitle:0,
        debug:false,
        width: 70,
        height: 90,
        zoom: 2
    });
    
    //zoomer
    $('ul.thumbs-zoomer-top-accessori li').Zoomer({
        speedView:200,
        speedRemove:400,
        altAnim:true,
        speedTitle:0,
        debug:false,
        width: 198,
        height: 198,
        zoom: 2
    });
    
    //zoomer
    $('ul.thumbs-zoomer-tavoli-e-sedie li').Zoomer({
        speedView:200,
        speedRemove:400,
        altAnim:true,
        speedTitle:0,
        debug:false,
        width: 93,
        height: 70,
        zoom: 2
    });
    
   

    
    
 
});

function dammiAltezza() {
    var img = $(".galleria-news img:first-child");
    var w = $(".galleria-news img:first-child").width();
    var h = $(".galleria-news img:first-child").height();
    var h1 = Math.round(560 * h/w) + 120;
    
    return h1;
}

function riavvia() {
    $('#riavviavideo').animate(

    {
            bottom: -200
        }, {
            duration: 1200,
            easing: 'easeOutElastic',
            complete:function() {
                $("#video").click();
            }
                   
        });
}


