// very messy code for key navigation

function next_page(){
	if($(".page_Next").length > 0){ 
		window.location = domain_base+$('.page_Next a').attr('href');
	}
}

var items_per_page = '52';
var start = 0;
shortcut.add("down",function() {
	if (view != 'thumbs') items_per_page = '26';
	if (start < items_per_page) {
		if (start > -1) {
			if (view == "thumbs" && start > 0){
				if($('#marker'+(start+4)).length <= 0){ // if the next marker doesn't exist
					if($(".page_Next").length > 0){ // if there is a next page to go to
						next_page();
					}
					return; 
				} 
				start=start+4;
			}else{
				if($('#marker'+(start+1)).length <= 0){
					if($(".page_Next").length > 0){ 
						start = items_per_page;
					}
					return;
				} 
				start++;
			}
			if($('#marker'+start).length > 0){
				$.scrollTo( '#marker'+start, 100,{offset:-10}  );
			}
    	}
	}else if (start >= items_per_page && $(".page_Next").length > 0){
		next_page();
	}
	

}
,{
		'type':'keydown',
		'disable_in_input':true,
		'target':document
	}

);

shortcut.add("up",function() {
	if (start != 0) {
			
		if (view == "thumbs" && start > 4){
			start=start-4;
		}else{
			start--;
		}
	
		$.scrollTo( '#marker'+start, 100,{offset:-10}  );
    }else if (start == '0' && $(".page_Prev").length > 0){
		window.location = domain_base+$('.page_Prev a').attr('href');
	}
}
,{
		'type':'keydown',
		'disable_in_input':true,
		'target':document
	}
);

shortcut.add("right",function() {
	if ($(".page_Next").length > 0){
		window.location = domain_base+$('.page_Next a').attr('href');
	}
}
,{
		'type':'keydown',
		'disable_in_input':true,
		'target':document
	}
);

shortcut.add("left",function() {
	if ($(".page_Prev").length > 0){
		window.location = domain_base+$('.page_Prev a').attr('href');
	}
}
,{
		'type':'keydown',
		'disable_in_input':true,
		'target':document
	}
);

/*shortcut.add("space",function() {

	if (start){
		var imageid = $('#marker'+start+' .image_info').attr('imageid');
		addtofavorites(imageid);
		favebtn_state_change(imageid);
	}
}
,{
		'type':'keydown',
		'disable_in_input':true,
		'target':document
	}
);*/

if(flagkey == true){
	shortcut.add("shift",function() {
		if (start){
				var imageid = $('#marker'+start+' .image_info').attr('imageid');
				flag(imageid,'nudity');
		}
	}	,{
				'type':'keydown',
				'disable_in_input':true,
				'target':document
			}
	);

}	

