$(document).ready(function () {
    InitEvents ();
    InitBoxSlide ();
    
	InitMenuEffects ();
});

/* *********************************************************************
 * Events
 * *********************************************************************/
function InitEvents () {
    $('.datepicker-inline').datepicker({
        firstDay: 1,
        dateFormat: 'dd/mm/yy',
        onSelect: function (dateText, inst) {
            id = $(this).attr('id');
            parts = id.split('-');
            id2 = parts[parts.length -1];
            $('#datepicker-target-id-' + id2).val(dateText);
        }
    });
}

/* *********************************************************************
 * Slide Box
 * *********************************************************************/
function InitBoxSlide () {
    $('.box-slide-head').click(function (event) {

        tgt = $(event.target);
        if (tgt.hasClass('clickable')) {
            return;
        }
        
        body = $(this).next();
        
        if (!body.hasClass('box-slide-body')) {
            body = body.find('.box-slide-body');
        }
        //body = $(this).next('.box-slide-body');

        if (body.is(':visible')) {
            body.hide();
        }
        else {
            body.show();
        }
        
        return false;
    });
}

/* *********************************************************************
 * Menus
 * *********************************************************************/
function InitMenuEffects () {
    $('.menu li').hover(function () {
        			$(this).find('ul:first').css({'visibility': 'visible', 'display': 'none'}).slideDown();
    }, function () {
        $(this).find('ul:first').css({visibility: "hidden"});

    });
    
    // Look for active element
    indexStart = 1;
    $('#iconbar li').each( function(index) { 
            if ($(this).hasClass('active')) 
                indexStart = index;
    });
    // Initialize carousel plugin
    $('#iconbar').jcarousel({
        start:          indexStart,
        scroll:         5,
        buttonPrevHTML: '<span>&lt;</span>',
        buttonNextHTML: '<span>&gt;</span>',
        initCallback:   function (instance, state) {}
    });    
    instance = $('#iconbar').data('jcarousel')
    // Roll on active element
    if (indexStart >= 7) {
        if (!$.browser.webkit) {
            list = $('#iconbar .jcarousel-list');  
            number = list.css('left');
            list.css({'left': 0});
            list.delay(500).animate({left: '+=' + number}, 750, function () {});
        }
    }

}


