$(document).ready(function(){

    $.ajaxSetup({

        cache: false

    });



    $('#pageListTop').sortable({

        'axis': 'y',

        'items': 'tr.sortable_top',

        'opacity': 50,

        update: function(){

            $.ajax({

                url: '/admin/pages/saveorder/top',

                type: 'POST',

                data: $(this).sortable('serialize'),

                success: function(data){

                    $('#orderMessageTop').html(data).show('fast').animate({opacity: 1.0}, 2000).fadeOut('slow');

                }

            });

        }

    });



    $('#pageListBottom').sortable({

        'axis': 'y',

        'items': 'tr.sortable_bottom',

        'opacity': 50,

        update: function(){

            $.ajax({

                url: '/admin/pages/saveorder/bottom',

                type: 'POST',

                data: $(this).sortable('serialize'),

                success: function(data){

                    $('#orderMessageBottom').html(data).show('fast').animate({opacity: 1.0}, 2000).fadeOut('slow');

                }

            });

        }

    });



    $('#imageList').sortable({

        'axis': 'y',

        'items': 'tr.sortable',

        'opacity': 50,

        update: function(){

            $.ajax({

                url: '/admin/auction_images/saveorder',

                type: 'POST',

                data: $(this).sortable('serialize'),

                success: function(data){

                    $('#orderMessage').html(data).show('fast').animate({opacity: 1.0}, 2000).fadeOut('slow');

                }

            });

        }

    });



    // For initial load

    var fixedPrice = $('#AuctionFixedPrice').val();



    if(fixedPrice == 0){

        $('#AuctionFixedCheck').removeAttr('checked');

        $('#AuctionFixedPrice').parent().hide(0);

    }else{

        $('#AuctionFixedCheck').attr('checked', true);

        $('#AuctionFixedPrice').parent().show(1);

    }



    // For change

    $('#AuctionFixedCheck').click(function(){

        if($(this).attr('checked')){

            $('#AuctionFixedPrice').parent().show(1);

            $('#AuctionFixedPrice').val(fixedPrice);

        }else{

            $('#AuctionFixedPrice').parent().hide(1);

            $('#AuctionFixedPrice').val(0);

        }

    });

});
