//
//Autor: Maciek Szwed

var timeout    = 200;
var closetimer = 0;
var ddmenuitem = 0;

function dropDown_open(){
   dropDown_canceltimer();
   dropDown_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function dropDown_close(){
    if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}
function dropDown_timer(){
    closetimer = window.setTimeout(dropDown_close, timeout);
}
function dropDown_canceltimer(){
    if(closetimer){
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

document.onclick = dropDown_close;


$(document).ready(function() {
    
    $("#mainImg").carousel({
        direction: 'vertical',
        pagination: true,
        loop: true,
        autoSlideInterval: 10000,
        autoSlide: true,
        effect: 'fade',
        animSpeed: 500,
        paginationPosition: 'outside',
        slideEasing: "easeOutBounce",
        btnsPosition: 'outside',
        nextBtn: '<div class="wrapper mainImgNextBtn"><span class="blackBox">&gt;</span></div>',
        prevBtn: '<div class="wrapper mainImgPrevBtn"><span class="blackBox">&lt;</span></div>'
    });
    
    $("#miniCarousel").carousel({
        direction: 'horizontal',
        pagination: false,
        loop: true,
        autoSlideInterval: 10000,
        autoSlide: true,
        nextBtn: '<span class="whiteBox">&gt;</span>',
        prevBtn: '<span class="whiteBox">&lt;</span>'
    });
    
    $("#similarProductsGallery").carousel({
        direction: 'horizontal',
        pagination: false,
        loop: true,
        autoSlideInterval: 10000,
        autoSlide: true,
        dispItems: 3,
        nextBtn: '<span class="whiteBox">&gt;</span>',
        prevBtn: '<span class="whiteBox">&lt;</span>'
    });
    


    //image zoom
    $(".zoomImg").mouseover(function(){
        $(this).next().css('display', 'block');    
    });
    $(".imgCont").mouseleave(function(){
        $(this).find('.productImg').css('display', 'none');
    });
    
    
    //dropdown menu
    $('.menu > li').bind('mouseover', dropDown_open);
    $('.menu > li').bind('mouseout',  dropDown_timer);  
   
   
   
   //admin - produkt - increase/decrease number
   $('table.singleProductDetails .valueCont .increase').click(function(){
       if(parseInt($(this).prev().attr('value')) >= 0 )
           $(this).prev().attr({'value' : (parseInt($(this).prev().attr('value'))  + 1 )});
   });
   $('table.singleProductDetails .valueCont .decrease').click(function(){
       if(parseInt($(this).prev().prev().attr('value')))
           $(this).prev().prev().attr({'value' : (parseInt($(this).prev().prev().attr('value'))  - 1 )});
   });
   
   
   //admin - tooltip
   $('.helpIcon').tooltip({ 
        track: true, 
        delay: 0, 
        showURL: false, 
        showBody: " - ", 
        fade: 250 
    });
    
    
    //koszyk datepicker
    $('#datepicker').datepicker();
    
    //opisy w koszyku
    $('.descCont .desc').click(function(){
        if($(this).next('.descItem').css('display') == 'none')
            $(this).next('.descItem').css({'display':'block'}); 
        else
            $(this).next('.descItem').css({'display':'none'}); 
    });
    $('.descCont .descItem .standardBtn').click(function(){
        $(this).parent().parent().css({'display':'none'}); 
    });
});

