$(function(){
//alert("S");	
main_staff_stage_select=0;
sub_staff_stage_select=0;

$(".main_staff_stage").live("click",function(){
main_staff_stage_select=$(this).attr("id");
});
$(".sub_staff_stage").live("click",function(){
sub_staff_stage_select=$(this).attr("id");
});


$("#up_arrow_main_staff_stage").live("click",function(){
if(main_staff_stage_select!=0){
$("#save_main_staff_stage").show();
move_up=$(".main_staff_stage[id="+main_staff_stage_select+"]").prev(".main_staff_stage").attr("id");
sort_up=$(".main_staff_stage[id="+main_staff_stage_select+"]").prev(".main_staff_stage").attr("code");
sort_me=$(".main_staff_stage[id="+main_staff_stage_select+"]").attr("code");

$(".main_staff_stage[id="+main_staff_stage_select+"]").prev(".main_staff_stage").attr("code",sort_me);
$(".main_staff_stage[id="+main_staff_stage_select+"]").attr("code",sort_up);

$(".main_staff_stage[id="+main_staff_stage_select+"]").insertBefore(".main_staff_stage[id="+move_up+"]");	

  
//alert(move_up);
//alert(move_down);
}

});


$("#down_arrow_main_staff_stage").live("click",function(){
if(main_staff_stage_select!=0){
$("#save_main_staff_stage").show();
move_down=$(".main_staff_stage[id="+main_staff_stage_select+"]").next(".main_staff_stage").attr("id");
sort_down=$(".main_staff_stage[id="+main_staff_stage_select+"]").next(".main_staff_stage").attr("code");
sort_me=$(".main_staff_stage[id="+main_staff_stage_select+"]").attr("code");

$(".main_staff_stage[id="+main_staff_stage_select+"]").next(".main_staff_stage").attr("code",sort_me);
$(".main_staff_stage[id="+main_staff_stage_select+"]").attr("code",sort_down);

$(".main_staff_stage[id="+main_staff_stage_select+"]").insertAfter(".main_staff_stage[id="+move_down+"]");	


    
//alert(move_up);
//alert(move_down);
}

});


$("#save_main_staff_stage").click(function(){
$(".over_loading").show();
var arr = $('#main_staff_stage_list > option').map(function(){
return " set `code`="+$(this).attr("code") + " where `id`= " + this.id + 
", set `code`="+$(this).attr("code") + " where `sub`= " + this.id ;
}).get();

query=arr+"";
//alert(arr);

$.post("ajax_save_staff_stage_sort.php",{"query":query,"type":"main"},function(data){
$(".over_loading").hide();
$("#save_main_staff_stage").hide();
//alert(data);
});


});





$("#up_arrow_sub_staff_stage").live("click",function(){
if(sub_staff_stage_select!=0){
$("#save_sub_staff_stage").show();
move_up=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").prev(".sub_staff_stage").attr("id");
sort_up=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").prev(".sub_staff_stage").attr("sort");
sort_me=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").attr("sort");

$(".sub_staff_stage[id="+sub_staff_stage_select+"]").prev(".sub_staff_stage").attr("sort",sort_me);
$(".sub_staff_stage[id="+sub_staff_stage_select+"]").attr("sort",sort_up);

$(".sub_staff_stage[id="+sub_staff_stage_select+"]").insertBefore(".sub_staff_stage[id="+move_up+"]");	

  
//alert(move_up);
//alert(move_down);
}

});


$("#down_arrow_sub_staff_stage").live("click",function(){
if(sub_staff_stage_select!=0){
$("#save_sub_staff_stage").show();
move_down=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").next(".sub_staff_stage").attr("id");
sort_down=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").next(".sub_staff_stage").attr("sort");
sort_me=$(".sub_staff_stage[id="+sub_staff_stage_select+"]").attr("sort");

$(".sub_staff_stage[id="+sub_staff_stage_select+"]").next(".sub_staff_stage").attr("sort",sort_me);
$(".sub_staff_stage[id="+sub_staff_stage_select+"]").attr("sort",sort_down);

$(".sub_staff_stage[id="+sub_staff_stage_select+"]").insertAfter(".sub_staff_stage[id="+move_down+"]");	


    
//alert(move_up);
//alert(move_down);
}

});


$("#save_sub_staff_stage").click(function(){
$(".over_loading").show();
var arr2 = $('#sub_staff_stage_list > option').map(function(){
    return " set sort="+$(this).attr("sort") + " where id= " + this.id ;
}).get();

query=arr2+"";
//alert(arr2);

$.post("ajax_save_staff_stage_sort.php",{"query":query,"type":"sub"},function(data){
$(".over_loading").hide();
$("#save_sub_staff_stage").hide();
//alert(data);
});


});




});
           

