$(document).ready(function() {
                           

// clear inputs on focus
        $('.cleared').focus(function () {
        if ($(this).val() == $(this).attr("title")) {
            $(this).val("");
            }
        }).blur(function () {
            if ($(this).val() == "") {
            $(this).val($(this).attr("title"));
        }
    });


            
            function getProducts()
            {
                var products = $.cookie('products');
                if (products == null) {
                    return new Array();
                } else {
                    return products.split('|');
                }
            }
            
            function addProduct(prodID, count)
            {
                var products = getProducts();
                
                for (var i in products) {
                    var product = products[i].split(',');
                    if (product[0] == prodID) {
                        alert('Produkt już znajduje się na liście zamówień. Nie można go dodać ponownie');
                        return;
                    }
                }
                
                if (products.length == 1 && products == '0,0') {
                    products = new Array();
                    products[0] = prodID+','+count;
                } else {
                    products[products.length] = prodID+','+count;
                }
                $.cookie('products', products.join('|'), {'path':'/'});
            }
            
            $('a.zamow').click(function() {
                var productID = $(this).prev().html();
                addProduct(productID, 1);
            });


// animate sidebar menu
 $('ul.side-menu li a').hover(function() {
   $(this).stop().animate({ left: 10 }, 'fast');
  }, function() {
   $(this).stop().animate({ left: 0 }, 'fast');
  });
 // 01.04.2011 - Usability fix
 /*$('ul.side-menu li.current a').hover(function() {
   $(this).stop().animate({ left: 10 }, 'fast');
  }, function() {
   $(this).stop().animate({ left: 10 }, 'fast');
  });*/


$("ul.side-menu li ul").hide();
$("ul.side-menu li.current ul").slideDown();

$("ul.side-menu li.current ul a").click(function(){          
    $("a.clicked").removeClass("clicked");
    $(this).addClass("clicked");
});

 
//colorbox
$(".colorbox").colorbox({
    transition:"none",
    width:"80%",
    height:"90%"
    });
$(".colorbox-flash").colorbox({
    transition:"none",
    innerWidth:"70%",
    innerHeight:"70%",
    iframe:true
    });
$(".colorbox-film").colorbox({
    transition:"none",
    innerWidth:"500px",
    innerHeight:"380px"
    });


// carousel na stonie g��wnej
$(".jcarousel").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    mouseWheel: true,
    speed: 800,
    auto: 4000

    });

// marki
$('.cycle-it').cycle()


//faq
        $('div#hide:eq(0)> div').hide();
        $('div#hide:eq(0)> h4.faq').click(function() {
        $(this).next().slideToggle('slow');
    });
        
    // Show/hide different post address fields in registration form
    $('#different_post_address').click(function() {
        $('#if_different_post_address').toggle();
    });
    var diffAdd = $('#different_post_address').attr('checked');
    if (diffAdd == true) {
        $('#if_different_post_address').show();
    }
    
    $('input[disabled=disabled],select[disabled=disabled]').addClass('disabled');
});



// tooltip script written by Alen Grakalic (http://cssglobe.com)

this.tooltip = function(){    
        xOffset = -15;
        yOffset = 10;        
    $("a.tooltip").hover(function(e){                                              
        this.t = this.title;
        this.title = "";                                      
        $("body").append("<p id='tooltip'>"+ this.t +"</p>");
        $("#tooltip")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .show("fast");
    },
    function(){
        this.title = this.t;        
        $("#tooltip").remove();
    });    
    $("a.tooltip").mousemove(function(e){
        $("#tooltip")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });
};

// starting the script on page load
$(document).ready(function(){
    tooltip();
});


