$(document).ready(function () {
    $('#categories ul li a').click(function(){
        var thisUrl = $(this).attr('href');
        var thisParent = $(this).parent();
        var thisChildren = $(this).parent().children('ul').html();
        if (thisChildren == null)
        {
            parent.location.href = thisUrl;
            return true;
        }
        else
        {
            if ($(thisParent).children('ul').css('display') == 'none')
            {
                $(thisParent).children('ul').animate({ opacity: 0.1 }, 1).fadeIn('fast').animate({ opacity: 1 }, 100);
            }
            else
            {
                $(thisParent).children('ul').fadeOut('fast');
            }
            return false;
        }
    });
    $('div.images a').fancybox();
    var default_lag_txt = $('#flags span').html();
    $('#flags a').mouseover(function()
    {
        $('#flags span').html($(this).attr('title'));
    }).mouseout(function()
    {
        $('#flags span').html(default_lag_txt);
    });
    $("#slider").easySlider({
        auto: true,
        prevText: '',
        nextText: '',
        continuous: true 
    });
    $("#product_slider").jcarousel({
        scroll: 1,
        auto: 2,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
});

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#product_slider a.next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#product_slider a.prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};