$(document).ready(function(){
	var curPage=1;
	var r_arrow=false;
	var l_arrow=false;
	var disPerPage=8;
	var pageWidth=515;
	
	$.get("images/logo/list.xml",function(xml){
		var files=$(xml).find("file");	
 		var length=files.length;
		var pages=parseInt(length%disPerPage?(length/disPerPage+1):(length/disPerPage));
		if(pages>=2)
		{
			$('#r_arrow').attr('src','images/right_arrow_active.gif').hover(function(){
				$(this).css('cursor','pointer');
			});
			r_arrow=true;
		}	
		var text='';
		for(i=1;i<=pages;i++)
		{
			text+='<div class="section" id="section'+i+'"></div>';			
		}
		$(text).appendTo('#moveArea');
 		for(i=1;i<=pages;i++)
		{
			$('#section'+i).css('left',(i-1)*pageWidth+'px');
		}
		
		for(i=1,page=1;i<=length;i++)
		{
			var file=files[i-1];
			var logo=$(file).attr("address");
			var url=$(file).find("url").text();			
			var text='<div class="logoImg" value="'+(i-1)+'"><a href="'+url+'" target="_blank"><img class="logo" src="'+logo+'" width="120" height="120"/></a></div>';	
			$('#section'+page).append(text);			
			text=''; 
			if(i%disPerPage==0)
			{	
				page++;				
			}
		}
		
		$('.logoImg').hover(
			function(){
				$(this).css('border','1px solid #cc0033');
				file=files[$(this).attr('value')];
				$('#description').html($(file).find('description').text());
			},
			function(){
				$(this).css('border','1px solid #d9d9d9');
				$('#description').html('');
			}
		);
		$('#r_arrow').click(function(){
			if(r_arrow)
			{
				r_arrow=false;
				leftVal=parseInt($('#moveArea').css('left'))-pageWidth;
				$('#moveArea').animate({left:leftVal},500,function(){
					if(++curPage>=pages)
					{
						r_arrow=false;
						$('#r_arrow').attr('src','images/right_arrow_normal.gif').hover(function(){
							$(this).css('cursor','default');
						});		
					}
					else
						r_arrow=true;
					$('#l_arrow').attr('src','images/left_arrow_active.gif').hover(function(){
						$(this).css('cursor','pointer');
					});
					l_arrow=true;				
				});
			}
		});
		$('#l_arrow').click(function(){
			if(l_arrow)
			{
				l_arrow=false;
				rightVal=parseInt($('#moveArea').css('left'))+pageWidth;
				$('#moveArea').animate({left:rightVal},500,function(){
					if(--curPage<=1)
					{
						l_arrow=false;
						$('#l_arrow').attr('src','images/left_arrow_normal.gif').hover(function(){
							$(this).css('cursor','default');
						});		
					}
					else
						l_arrow=true;
					$('#r_arrow').attr('src','images/right_arrow_active.gif').hover(function(){
						$(this).css('cursor','pointer');
					});
					r_arrow=true;				
				});

			}
		}); 
	});   
});