$(document).ready(function(){
	
	var num_img= $('#gallery_tb ul li').length;
	var state = 1;
	
	$('#gallery_tb').css('width',num_img*100+100);
	
	$('#gallery_left').bind('click',function(){
		var x = $('#gallery_tb').css('marginLeft');
		x=x.split('px');
		var x = parseInt(x);
		if(state>1){
			$('#gallery_tb').animate({
				marginLeft:'+=503'
			  }, 500, function() {
			  });
			  state-=1;
		}
	});
	
	$('#gallery_right').bind('click',function(){
		var x = $('#gallery_tb').css('marginLeft');
		x=x.split('px');
		var x = parseInt(x);
		if(state*5<num_img){		
			$('#gallery_tb').animate({
				marginLeft:'-=503'
			  }, 500, function() {
			  });
			  state+=1;
		}
	});
	
	
	var tog=0;
	$('#gallery_mid').bind('click',
	function(){
		if(tog==0){
			$('#portfolio_browse').stop().animate({
				top:383
			},500,function(){});
			tog=1;
		}else{
			$('#portfolio_browse').stop().animate({
				top:473
			},500);
			tog=0;
		}
	}
	);
	
	
	$('#gallery_tb ul li').bind('click',function(){
		var big_src = $(this).children('img').attr('alt');
		var h3 = $(this).children('.gallery_desc').children('h3').html();
		var p = $(this).children('.gallery_desc').children('p').html();
		
		$('#portfolio_slide').css("background-image", "url("+big_src+")"); 
		$('#portfolio_desc h3').html(h3);
		$('#portfolio_desc p').html(p);
	});
	
	
	$('#gallery_tb img').bind('mouseover',function(){
		$(this).stop().fadeTo(1000,1);
	}).bind('mouseout',function(){
		$(this).stop().fadeTo(1000,0.5);
	});
		
	$('#gallery_left').bind('mouseover',function(){
		$(this).css("background-image", "url(images/portfolio/left_btn_mo.png)");
	}).bind('mouseout',function(){
		$(this).css("background-image", "url(images/portfolio/left_btn.png)");
	});
	
	$('#gallery_right').bind('mouseover',function(){
		$(this).css("background-image", "url(images/portfolio/right_btn_mo.png)");
	}).bind('mouseout',function(){
		$(this).css("background-image", "url(images/portfolio/right_btn.png)");
	});
	
	$('#gallery_tb img').fadeTo( 1, 0.5);
	//$('.gallery_btn').fadeTo( 2, 0.5);
		
});
