 $(document).ready(function() {
 
/*$(".portfolio_preview .box:nth-child(3), .portfolio_preview .box:nth-child(6), .portfolio_preview .box:nth-child(9)").css({margin: '0'});


*/
  
/* $("#gallery-2 a").click(function() {
 	var img_src = $(this).attr('href')
 	alert( img_src );
 	
 	$("#gallery-1 img").attr('src', img_src);
 	return false;
 })
 */
/* 
  $("#gallery-2 li").click(function() {
	var this_class = $(this).attr('class');
	alert ( this_class )
	$("#gallery-1 li").css('display', 'none');
	 $("#gallery-1 li." + this_class).css('display', 'block');
	
	return false;
});
 */
 
 
 /* ---------
 blockquotes on home page
 ------------------------*/
 $('blockquote').cycle({
		fx: 'fade', 
		delay: -1000,
		timeout:  9000
	});
	
	
/*------------------------
gallery on photography pages - functions below
---------------------------*/
 
	$("#gallery-1 ul a").click(function() {
		return false;
	});
	
	//if (gallery1_ul_leftpos > 0) {}
 	$("#gallery-1").append("<a class='previous' href='#' title='previous photo'>&lt;</a>");
	$("#gallery-1").append("<a class='next' href='#' title='next photo'>&gt;</a>");
 
 	var length_of_gallery = $(".photography #gallery-2 ul li").length;
	var length_of_gallery1 = $(".photography #gallery-1 ul li").length;
 	//alert(length_of_gallery1 * 640);
 
 var width_of_tn_gallery = length_of_gallery * 200;
 
//  alert(width_of_tn_gallery);
 $("#gallery-2 ul").attr('style', 'width: ' + width_of_tn_gallery + 'px')
 
 
 
  $("a.previous").click(function() {
  	var xpos = check_gallery_leftpos();
  	if (xpos == 0) {
  		alert('You\'re already at the first photo :-\) Try clicking forward to see the rest')
  	} else {
  	$("#gallery-1 ul").animate( { left: '+=640' });
  	}
	
	return false;// in all cases, return false
	});

  $("a.next").click(function() {
    	var xpos = check_gallery_leftpos();
  	if (xpos == ( (length_of_gallery1 - 1) * -640) ) {
  		$("#gallery-1 ul").animate( { left: '0' });
  		//alert('You\'ve reached the last photo - try clicking back.')
  	} else {
  		$("#gallery-1 ul").animate( { left: '-=640' });
  	}
	
	return false;// in all cases, return false
	});
 
  $("#gallery-2 li").click(function() {
	var this_class = $(this).attr('class');
	var large_img = $("#gallery-1 li." + this_class);
	var position = large_img.position();
	//alert ( position.left );
	var new_gallery_pos = '-' + position.left + 'px'
	//$("#gallery-1 ul").css('left',  new_gallery_pos)
	
	$("#gallery-1 ul").animate( { left: new_gallery_pos });
	return false;
}); 
 


$("#content-slider").slider({
    animate: true,
    change: handleSliderChange,
    slide: handleSliderSlide
  });

 
 // end doc.ready: 
 
 });
 
 
function handleSliderChange(e, ui)
{
  var maxScroll = $("#gallery-2").attr("scrollWidth") -
                  $("#gallery-2").width();
  $("#gallery-2").animate({scrollLeft: ui.value *
     (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#gallery-2").attr("scrollWidth") -
                  $("#gallery-2").width();
  $("#gallery-2").attr({scrollLeft: ui.value * (maxScroll / 100) });
} 

function check_gallery_leftpos() {
 	var gallery1_ul_pos = $(".photography #gallery-1 ul").position();
	var gallery1_ul_leftpos = gallery1_ul_pos.left;
	return gallery1_ul_leftpos;
	//alert (gallery1_ul_leftpos);
	
	/*if (gallery1_ul_leftpos > 0) {
		$("#gallery-1").append("<a class='previous'>&lt;</a>");	
	}
	*/
}
