

	
$(function() {
	$("#index_ins_tab > ul").tabs();
	
	$('ul#index_ins_tab_list').bind('tabsshow', function(event, ui) {
		switch(ui.index){
			case 0: $("#rand_instructions .ins_list_content").empty();
					$("#rand_instructions .loader").show();
					$("#rand_instructions .ins_list_content").load(
						'/ajax/load_instructions/4/',
						function(){
							$("#rand_instructions .loader").hide();
						}
					);
					
					break;
			case 1: if($("#last_added_instructions .ins_list_content").html()==''){
						$("#last_added_instructions .ins_list_content").load(
							'/ajax/load_instructions/5/',
							function(){
								$("#most_instructions .loader").hide();
							}
						);
					}
					break;
			case 2: if($("#most_instructions .ins_list_content").html()==''){
						$("#most_instructions .ins_list_content").load(
							'/ajax/load_instructions/1/',
							function(){
								$("#most_instructions .loader").hide();
							}
						);
					}
					break;
			case 3: if($("#best_instructions .ins_list_content").html()==''){
						$("#best_instructions .ins_list_content").load(
							'/ajax/load_instructions/2/',
							function(){
								$("#best_instructions .loader").hide();
							}
						);
					}
					break;
			case 4: if($("#recommended_instructions .ins_list_content").html()==''){
						$("#recommended_instructions .ins_list_content").load(
							'/ajax/load_instructions/3/',
							function(){
								$("#recommended_instructions .loader").hide();
							}
						);
					}
					break;
					
		}

	});
	
});


function boxes_down(obj,obj2, fun_static){
	
	obj.show();	
	obj2.show();	
	
	obj.animate({ 
	        top: "425px"
	      }, 
		  2000,
		  function(){
			obj.hide();	  	
		  }
	);
	
	obj2.animate({ 
	        top: "0px"
	      },
		  2000,
		  function (){
		  	fun_static.block = false;
		  }	  
	);
}


function boxes_up(obj, obj2, fun_static){

	obj.show();
	obj.animate({ 
	        top: "-425px"
	      }, 
		  2000,
		  function(){
			obj.hide();	  	
		  }
	);
	
	obj2.show();
	obj2.css('top','425px');
	obj2.animate({ 
	        top: "0px"
	      }, 
		  2000,
		  function (){
		  	fun_static.block = false;
		  }
		);
		  
	fun_static.page++;
}

function show_prev_ins(){
	if (show_next_ins.block == false) {
		
		if (show_next_ins.page > 2) {
			show_next_ins.block = true;
			show_next_ins.page--;
			boxes_down($("#other_cv_ins .ins_others_list_page_" + show_next_ins.page), $("#other_cv_ins .ins_others_list_page_" + (show_next_ins.page - 1)),show_next_ins);
		}
	}
}

function show_next_ins(){
	if (show_next_ins.block == false) {
		
		if ($("#other_cv_ins .ins_others_list_page_" + show_next_ins.page).html()) {
			show_next_ins.block = true;
			boxes_up($("#other_cv_ins .ins_others_list_page_" + (show_next_ins.page - 1)), $("#other_cv_ins .ins_others_list_page_" + show_next_ins.page),show_next_ins);
		//alert(show_next_ins.page);
		
		}
		else {
			show_next_ins.block = true;
			$('#other_cv_ins .other_ins_loader').show();
			
			$.ajax({
				url: "/ajax_instruction/load_currently_viewed/" + show_next_ins.page,
				cache: false,
				success: function(html){
				
					if (html) {
						$("#other_cv_ins").append(html);
						boxes_up($("#other_cv_ins .ins_others_list_page_" + (show_next_ins.page - 1)), $("#other_cv_ins .ins_others_list_page_" + show_next_ins.page),show_next_ins);
					} else {
						show_next_ins.block = false;
					}
					
					$('#other_cv_ins .other_ins_loader').hide();
					
				}
			});
			
		}
	}
}

show_next_ins.page  = 2;
show_next_ins.block = false;


