(function($)
{
    $(function()
    {
        if ($.app.lang == 'en')
            $.datepicker.setDefaults($.datepicker.regional['']);
        else
            $.datepicker.setDefaults($.datepicker.regional[$.app.lang]);
        
        
        // Remove table outside borders
        $(".wysiwyg table").each(function ()
        {
            var table = $(this);
            
            $("tr", table).each(function()
            {
                $("th:first", this).css({
                    borderLeft: 'none'
                });
                $("th:last", this).css({
                    borderRight: 'none'
                });
                $("th:not(:first):not(:last)", this).css({
                    borderLeft: '1px solid #ffffff',
                    borderRight: '1px solid #ffffff'
                });
                
                $("td:first", this).css({
                    borderLeft: 'none'
                });
                $("td:last", this).css({
                    borderRight: 'none'
                });
            });
            $("tr:has(td):first", table).each(function()
            {
                $("td", this).css({
                    borderTop: 'none'
                });
            });
            $("tr:last", table).each(function()
            {
                $("td", this).css({
                    borderBottom: 'none'
                });
            });
        });
        
        $(".btn1:has(input)").each(function ()
        {
            var btn1 = $(this);
            $("input", btn1).css('width', $(btn1).width());
        });
        
        $("a.lightbox").fancybox({
            'transitionIn'	: 'elastic',
            'transitionOut'	: 'elastic'
        });
        
        $("#highlights").each(function ()
        {
            var highlights = $(this);
            var rotateTimeout = false;
            
            
            function setItem(index)
            {
                var activeIndex =  $(".indicators-list .item-active", highlights).index();
                if (index != activeIndex)
                {
                    $(".indicators-list .item", highlights).removeClass('item-active');
                    $(".indicators-list .item", highlights).each(function ()
                    {
                        var index = $(".indicators-list .item", highlights).index($(this));
                        $("img", this).attr('src', $("img", this).attr('src').replace(/images\/(.*)/, 'images/highlights_indicators_' + (index + 1) + '.png'));
                    });
                    $(".indicators-list .item:eq(" + index + ")", highlights).addClass('item-active');
                    $(".indicators-list .item:eq(" + index + ") img", highlights).attr('src',
                        $(".indicators-list .item:eq(" + index + ") img", highlights)
                            .attr('src')
                            .replace(/images\/(.*)/, 'images/highlights_indicators_' + (index + 1) + '_active.png')
                    );
                    
                    $(".highlights-list .item", highlights).fadeOut('fast');
                    $(".highlights-list .item:eq(" + index + ")", highlights).fadeIn('fast');
                }
            }
            
            $(".indicators-list .item", highlights).click(function ()
            {
                rotateTimeout = clearTimeout(rotateTimeout);
                
                var index = $(".indicators-list .item", highlights).index($(this));
                setItem(index);
            });
            
            function rotate()
            {
                var index = $(".indicators-list .item-active", highlights).index();
                var count = $(".indicators-list .item", highlights).length;
                
                index = (index + 1) % count;
                setItem(index);
                
                rotateTimeout = setTimeout(arguments.callee, 5000);
            }
            rotateTimeout = setTimeout(rotate, 5000);
        });
        
        $("form.form1").each(function ()
        {
            $(".input .input-field-date input").datepicker();
        });
    });
})(jQuery);
