$(document).ready(function() {
    //area 1
    /*$('#footer ul').children().hover(function() {
        $(this).siblings().stop().fadeTo(500,0.2);
    }, function() {
        $(this).siblings().stop().fadeTo(500,1);
    });*/
    
    //tooltip
    $(".tooltip").easyTooltip();
    
    //dialog
    $('#dialog').dialog({
        autoOpen:false,
        width: 600
    });
    
    $('#dialog_link').click(function(){
        $('#dialog').dialog('open');
        return false;
    });
    
    //hover states on the static widgets
    $('#dialog_link, ul#icons li').hover(
        function() {
            $(this).addClass('ui-state-hover');
        },
        function() {
            $(this).removeClass('ui-state-hover');
        }
        );
            
    $('#dialog form').submit(function(){
        $(this).attr('action', '/products/demo');
        $(this).ajaxSubmit({
            'dataType':'json',
            'beforeSubmit':function(){},
            'success' : function(data, status) {
                if(status == 'success'){
                    if(data != null){
                        msg = '<div class="ui-state-highlight ui-corner-all flash-msg"><p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span><strong>Saved!</strong> บันทึกข้อมูลเรียบร้อยแล้ว</p></div>';
                        $('#dialog form').get(0).reset();
                        $('#dialog form').hide();
                        $('#dialog').html(msg);
                        setTimeout(function(){
                            $(".flash-msg").fadeOut("slow", function () {
                                $(".flash-msg").remove();
                            });
                            $('#dialog').dialog('close');
                            $('#dialog form').show();
                        }, 2000);
                    }
                }
            }
        });
        
        return false;
    });


    $('.jumper').each(function(){
        var jump = function(){
            var selectedOption = $('.jumper option:selected').val();
            newUrl = '/products/view/'+selectedOption;
            top.location.href = newUrl;
            return;
        }
        //simple dropdown selection jump
        $(this).find('select').change(jump);
        $(this).find('#jump-button').click(jump);
    });

//end document ready binding
});

Cufon.replace('.cufon', {
    color: '-linear-gradient(#7b7b7b, #555)'
});
