$(document).ready(function(){
	$("div.p-thumb a").hover(function() {
		var thumbOver = $(this).find("img").attr("src");
		$(this).css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
		$(this).find("img").stop().fadeTo('normal', 0);
	}, function() {
		$(this).find("img").stop().fadeTo('normal', 1).show();
	});

    $("#b-city_list-opener").hover(function() {
       $("#b-city_list-div").stop().fadeTo('normal', 1);
    }, function() {
       $("#b-city_list-div").stop().fadeTo('normal', 0, function() {
            $("#b-city_list-div").hide();
        });
    });
    $("#b-city_list-div").hover(function() {
        $(this).stop().fadeTo('normal', 1);
    }, function() {
        $(this).stop().fadeTo('normal', 0, function() {
            $(this).hide();
        });
    });
    
});



(function($) {
     $.fn.serializeJSON=function() {
         var json = {};
         jQuery.map($(this).serializeArray(), function(n, i){
            json[n['name']] = n['value'];
         });
         return json;
     };
     
     
    $.fn.driveSave = function (options){
        var defaults = {
            suc_url: '',
            callback: false, 
            refresh: false,
            post: ''
        };
        var options = $.extend(defaults, options);

        $(this).bind('submit', function (){
            t=$(this);
            t.find('input[type=submit]').attr('disabled', 'true');
            $.ajax({
                    type: "POST",
                    url: t.attr('action'),
                    data: t.serializeJSON(),
                    success: function(msg){
                        
                        if(msg=='ok') {
                            if(options.suc_url) tbSuc(options)
                            else if(options.post) t.unbind('submit').attr('action',options.post).attr('method','POST').submit();
                            else tb_remove();
                            if(options.callback) tb_callback();
                        } else {
                            t.find('.errors').html(msg);
                            t.find('input[type="submit"]').removeAttr('disabled');
                        }
                    }
            });
            return false;
            
       });
    }   
    
    $.fn.inputFile = function (){
        $(this).wrap('<div class="file-upload-wrap"></div>');
    }


})(jQuery);

    function tbSuc (options){
           $.ajax({
                    type: "POST",
                    url: options.suc_url,
                    data: {},
                    success: function(msg){
                        if(msg!='error') {
                            $('#TB_ajaxContent').html(msg).animate({opacity:1},3500, function(){
                                tb_remove();
                            });
                            if(options.refresh) location.reload(true); 
                        } else {

                        }
                    }
            });
    }
    

