// JavaScript Document
$(document).ready(function() {
	/*Centering Function*/
	$("#project_image a").each( function() {
		img_width = this.getElementsByTagName('img')[1].offsetWidth;
		img_height = this.getElementsByTagName('img')[1].offsetHeight;
		$(this).css('left', (480-img_width)/2);
		$(this).css('top', (390-img_height)/2);
	});
	
	/* Begin Gallery Functions */ 	
	var index = 0;
	$("#project_image a").fancybox({"overlayOpacity":.7, "zoomOpacity":true});
	$("#project_image .image_container").hide().slice(0, 1).show();
	$('#project_thumbnails img:nth-child(4n)').each(function() {
		$(this).addClass('end')	;
	});
	$('#project_thumbnails img').click(function() {
		this_index=$('#project_thumbnails img').index($(this));
		if(this_index == index) {
			return;
		}
		else {
/*			if (jQuery.browser.version=='8.0') {
				$('#project_image div.image_container').hide();
				$('#project_image div.image_container').slice(this_index,this_index+1).show();	
			}
			else {*/
			$('#project_image div.image_container').fadeOut();
			$('#project_image div.image_container').slice(this_index,this_index+1).fadeIn();
			index = this_index;
		}
	});
	
	/* Begin Project Navigation Functions */ 
	var project_number = $('#scroll_inner div.nav_link').size();
	var scroll_width = (project_number*105);
	var current_pos = new Number();
	
	function setArrows() {
		current_pos = Math.abs(parseFloat($('#scroll_inner').css('left')));
		if(current_pos>=(scroll_width-840)) {
			$('.scroll_arrow.left').show();
			$('#project_nav').css('margin-left',-30);
			$('.scroll_arrow.right').hide();
		}
		else if(current_pos==0) {
			$('.scroll_arrow.right').show();
			$('.scroll_arrow.left').hide();
			$('#project_nav').css('margin-left',0);
		}
		else {
			return;
		}
	}
	
	$('#scroll_inner').width(scroll_width);
	setArrows();	
	if (project_number <=8) {
		$('.scroll_arrow.right').hide();
		$('.scroll_arrow.left').hide();
		$('#project_nav').css('margin-left',0);
	}
	$('.scroll_arrow').click(function() {
		if ($('#scroll_inner:animated').size()>0) {
			return;
		}
		if($(this).hasClass('right')) {
			$('.scroll_arrow.left').show();
			$('#project_nav').css('margin-left',-30);
			$('#scroll_inner').animate({'left':-840},1500,'easeInOutSine', function(){
				setArrows();
				$('#scroll_inner a').attr('href',function(index){return $(this).attr('href').split('&pos')[0] + "&pos=" + (current_pos/105);});
			});
		}
		else if($(this).hasClass('left')) {
			$('.scroll_arrow.right').show();
			$('#scroll_inner').animate({'left':0},1500,'easeInOutSine', function(){
				setArrows(); 
				$('#scroll_inner a').attr('href',function(index){return $(this).attr('href').split('&pos')[0] + "&pos=" + (current_pos/105);});
			});
		}
		
		
	});
	
	/* Begin Button Functions */ 
	$('div.nav_link').hover(function() {
		$(this).find("img").fadeTo(300, 0.05); 
		$(this).find("a.info").fadeIn(300); 
	}, function() {
		$(this).find("img").fadeTo(300, 1.0);
		$(this).find("a.info").fadeOut(300); 
	});
	
	/* Begin Info Resize Functions */
	if($('#project_thumbnails img').size()<=4) {
		$('#project_text').css('height', 360);
	}
	if($('#project_thumbnails img').size()<=1) {
		$('#project_thumbnails').hide();
		$('#project_text').css('height', 390);
	}
	
	/*Remove Post Image Function*/
	post_images = $('div.post a:has(img)');
	if (post_images.size()>0) {
		post_images.hide();
	}
	/*Remove Post Image Title*/
	$('#project_image a').removeAttr('title');
	 
  });