$(window).bind("load", function() {
		$("ul#list").each(function() {
			$("li:gt(9)", this).hide();
			updateButtons();
		});
		$("ul#list a").live("click", function() {
			var showingIndex = new Array();
			$("ul#list li.imgbt").each(function() {
				if(($(this).css('display') != 'none') && ($(this).attr('class') == 'imgbt')) {
					showingIndex.push($(this).index());	
				}	
			});
			if($(this).parent().attr("id") == "more"){
				$("ul#list").each(function() {
					//$("li:lt("+ showingIndex.length +")", this).hide();
					//$('ul#list > li').slice(showingIndex[0],  showingIndex.length - 1).hide();
					
					$("ul#list >li").hide();
					$('ul#list > li').slice(showingIndex[showingIndex.length-1]+1,showingIndex[showingIndex.length -1] +11).show();
				});
				
				updateButtons();
			}
			else if($(this).parent().attr("id") == "less"){
				$("ul#list").each(function() {
					$("ul#list >li").hide();
					$('ul#list > li').slice(showingIndex[0]-11, showingIndex[0]).show();
				});
				
				updateButtons();
			}
			if($(this).parent().attr("id") == "less"){
				
			}
		});
		
		function updateButtons() {
			$(".bt").remove();
			var indexCount = new Array(); 
			$('ul#list li').each(function() {
				if($(this).css('display') != 'none') {
					indexCount.push($(this).index());	
				}
			});
			var hiddenCount = new Array()
			$('ul#list li').each(function() {
				if($(this).css('display') == 'none') {
					hiddenCount.push($(this).index());
				}			
			});
			
			if((hiddenCount[0] > indexCount[indexCount.length-1]) || (hiddenCount[hiddenCount.length-1] > indexCount[indexCount.length-1])) {
				createMoreBt(hiddenCount[hiddenCount.length-1]);
			}
			
			if (hiddenCount[0] <= indexCount[0] ){
				createLessBt(indexCount[0]);

			}
		}
		
		function createMoreBt(position) {
			$("ul#list").each(function() {
				$("li:nth-child("+position+")", this).after("<li id='more' class='bt'><a href='#'>></a></li>");  
			});	
		}
		function createLessBt(position) {
			$("ul#list").each(function() {
				$("li:nth-child("+position+")", this).before("<li id='less' class='bt'><a href='#'><</a></li>");		
			});	
		}
	
});
