if (typeof console === 'undefined'){console = {log: function(){return false}, debug: function(){return false}}}

$(document).ready(function(){
    $(".alert-message").alert();

    $('#enquiryForm').modal({
        keyboard: true,
        backdrop: 'static'
    });

    $('div.modal a[data-modal-control-close]').click(function(){
        $(this).closest('div.modal').data('modal').hide();
        return false;
    });

    $('.triggerEnquireForm').click(function(){
        $('#enquiryForm').modal('show');
        return false;
    });

    $('div.modal input[data-ajax-submit]').live('click', function(){
        var $this = $(this);
        var $modal = $this.closest('div.modal');
        var $container = $modal.find('div.modal-body:first');
        var $form = $modal.find('form:first');

        $.ajax({
            url: $form.prop('action'),
            type: $form.length ? 'post' : 'get',
            data: $form.length ? $form.serialize() : null,
            cache: false,
            success: function(response) {
                $container.html(response);
                var result = $("input[name='result']", $container).val();
                //var result_message = $("input[name='result_message']", $container).val();
                switch ( result ) {
                    case 'success':
                        $this.remove();
                        break;
                }
            }
        });

        return false;
    });

    if ($.isFunction($.fn.popupwindow)) {
        $('.popupwindow').popupwindow();
    }
});


var dimmensions = {
    s1: {
        large: {
            width: "180",
            height: "44",
            lineHeight: "44px",
            fontSize: "20px",
            marginTop: '-6px'
        },
        normal: {
            width: "120",
            height: "38",
            lineHeight: "38px",
            fontSize: "14px",
            marginTop: '0px'
        }
    },
    s2: {
        large: {
            fontWeight: 'bold'
        },
        normal: {
            fontWeight: 'normal'
        }
    },
    s3: {
        large: {
            //fontWeight: 'bold'
        },
        normal: {
            //fontWeight: 'normal'
        }
    }
};

var $menuContainer = $('.menu-container');
var menuStyle = 's1';
if ($menuContainer.hasClass('style-2')) {
    menuStyle = 's2';
}
if ($menuContainer.hasClass('style-3')) {
    menuStyle = 's3';
}

$('#top-menu > li').each(function(){
    var $li = $(this);
    var $a = $(this).find('a:first');
    var $ul = $(this).find('ul:first');
    var speed = 100;
    $a.data('original', {
        width: $a.width(),
        height: $a.height(),
        fontSize: $a.css('font-size')
    });

    $li.bind({
        mouseenter: function() {
            if ($a.is('.active')) {
                $li.addClass('hover');
                $ul.slideDown('fast');
            } else {
                $a
                .stop(true)
                .animate(dimmensions[menuStyle].large, {
                    duration: speed,
                    complete: function(){
                        $li.addClass('hover');
                        $ul.slideDown('fast');
                    },
                    queue: true
                })
                .next('div').show();
            }

            $('#top-menu > li > a.active').not($a)
                .stop(true)
                .animate(dimmensions[menuStyle].normal, {
                    duration: speed,
                    queue: true
                })
                .next('div').hide();
        },
        mouseleave: function() {
            $ul.slideUp('fast', function(){});
            $li.removeClass('hover');

            $a.not('.active')
                .stop(true)
                .animate(dimmensions[menuStyle].normal, {
                    duration: speed,
                    queue: true
                })
                .next('div').hide();

            $('#top-menu > li > a.active')
                .stop(true)
                .animate(dimmensions[menuStyle].large, {
                    duration: speed,
                    queue: true
                })
                .next('div').show();
        }
    });
//        $li.hoverIntent({
//             sensitivity: 14,
//             interval: 100,
//             timeout: 200,
//             over: function() {
//            },
//             out:function (){
//            }
//        });
});



