$(document).ready(function(){

    $('#slider').nivoSlider(
    {
        directionNav:false,
        controlNav:false,
        pauseOnHover:true,
        pauseTime:5000,
        animSpeed:1000
    }
    );
	
    $('#slider').click(function(e) {


        var vars = $(this).data('nivo:vars');
        
        if ( vars.currentSlide == '0'){
            
            var offset = $("#slider").offset();            
            var x = e.pageX - offset.left;
            var y = e.pageY - offset.top;

            if (x >= 164 && x<=322 && y >= 15 && y <= 49){
               
                window.open('http://kellysbike.com/index.php?id=hu', '_blank'); 
                window.open('/uploads/kellys2011.xls', '_blank'); 
            } else if (x >= 93 && x<=238 && y >=86 && y <= 129){
                window.open('http://trek.hu/index.php', '_blank');            
            } else if (x >= 10 && x<=166 && y >=178 && y <= 218){
                window.open('http://www.bikefun.hu/aktualis-akcioink', '_blank');            
            }
                
        }

    });

    /* if ($("#brandbox")){
        $.ajax({
            url: "categoryBrands/",
            success: function(data){
                $("#brandbox").html(data)
            } ,
            cache: false
        });
    }*/

    $('a.lb').lightBox({
        overlayBgColor: '#000',
        overlayOpacity: 0.9,
        containerResizeSpeed: 350,
        txtImage: 'Kép',
        txtOf: '/'
    });

    jQuery('#carousel_promo').jcarousel({
        vertical: true,
        auto: 3,
        scroll: 1,
        wrap: "last",
        initCallback: carousel_initCallback
    });

    jQuery('#carousel_actual').jcarousel({
        vertical: false,
        auto: 10,
        scroll: 4,
        wrap: "last",
        initCallback: carousel_initCallback
    });

    jQuery('#carousel_merida').jcarousel({
        vertical: false,
        auto: 10,
        scroll: 3,
        wrap: "last",
        initCallback: carousel_initCallback
    });

    jQuery('#carousel_fitness').jcarousel({
        vertical: false,
        auto: 10,
        scroll: 4,
        wrap: "last",
        initCallback: carousel_initCallback
    });

    jQuery('#carousel_shop').jcarousel({
        vertical: false,
        auto: 10,
        scroll: 4,
        wrap: "last",
        initCallback: carousel_initCallback
    });

    $("#menu a").hover(
        function(){
            $(this).removeClass('menunnormal').addClass('menuhover');
        },
        function(){
            $(this).removeClass('menuhover').addClass('menunormal');
        });

    $(".categoryselector").click(function(){

        var options = {};
        $(this).parent().show('highlight', options, 500, function(){
            $(this).removeAttr("filter");
        });

        $.ajax({
            url: "categoryBrands/id/" + $(this).attr('id').split('_')[1],
            success: function(data){
                $("#brandbox").html(data)
            } ,
            cache: false
        });
        return false;
    });
    
});

function carousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}
