jQuery(function($){
	$(function(){
		$('#count1').show().animate({opacity:1}, 0);
		
		$('.siphoto').each(function(i){
			if(i!=0){
				$(this).css('opacity', .5);
			}
			$(this).attr('rel', i);
		});
		
		var leftpad = ($(window).width()-940)/2-10;
		$('#scroller #scrollbar').css('paddingLeft', leftpad);
		
		var currentItem = 0;
		var maxItems = $('.galleryitem').size();
		$('#picdesc').text($(".siphoto[rel='"+currentItem+"']").attr('title'));
		
		var startScroll = function(toNum){
			var nextEl = $('a.galleryitem[rel=' + toNum + ']');
			
			// OPTIONS GO HERE
			$('#scroller').scrollTo(nextEl, {
				'duration': 250,
				'offset': {left: (-($(window).width()-940)/2+10)},
				'axis' : 'x'
			});
			
			showCurrentText ();
		};
		
		
		$(document).keydown(function(e){
			if (e.keyCode==37) {
				slideleft();
			} else
			if (e.keyCode==39) {
				slideright();
			}
		});
		
		function slideleft() {
			// $(this).animate({'opacity':1}, 500);
			if( currentItem > 0 ) {
				$(".siphoto[rel='"+currentItem+"']").animate({'opacity':.5}, 500);
				currentItem--;
				startScroll(currentItem);
				$(".siphoto[rel='"+currentItem+"']").animate({'opacity':1}, 500);
			}
		};
		
		function slideright() {
			// $(this).animate({'opacity':1}, 500);
			if( currentItem < maxItems - 1 ) {
				$(".siphoto[rel='"+currentItem+"']").animate({'opacity':.5}, 500);
				currentItem++;
				startScroll(currentItem);
				$(".siphoto[rel='"+currentItem+"']").animate({'opacity':1}, 500);
			}
		};
		
		function showCurrentText () {
			$('#picdesc').fadeOut(function(){
				if ($(".siphoto[rel='"+currentItem+"']").attr('title') != "") {
					$(this).text($(".siphoto[rel='"+currentItem+"']").attr('title')).fadeIn()}
				}
			);
		} 
		
		$('#scroll-left').click(slideleft);
		
		$('#scroll-right').click(slideright);
		
		$('.single').click(function(){
			$('#scroller').scrollTo(this, {
				'duration': 500,
				'offset': {left: (-($(window).width()-940)/2+10)},
				'axis' : 'x'
			});
			// $(this).animate({'opacity':1}, 500);
			currentItem = $(this).attr('rel');
		});
		
		$('.siphoto').click(function(){
			if( currentItem == $(this).attr('rel')) {					
			}
			else{
				// $('.workdesc').stop().animate({'opacity':0}, 500, function () {$(this).hide()});
				$('#scroller').scrollTo(this, {
				'duration': 500,
				'offset': {left: (-($(window).width()-940)/2+10)},
				'axis' : 'x'
				});
				$(this).animate({'opacity':1}, 500);
				$(".siphoto[rel='"+currentItem+"']").animate({'opacity':.5}, 500);
				currentItem = $(this).attr('rel');
				showCurrentText ();
				return false
			}
		});
	});


// Nav Trigger
	
        $(function(){
            
            navheight = $('#nav').height();
            $('#nav').css('height', '0');
            $('#nav div').css('display', 'none');
            

            $('#menutrigger').click(function(){
                $('#nav div').css('display', 'block');
                $('#nav').animate({height: navheight + "px", marginBottom: '30px'});
                $('#menutrigger').slideUp();
                return false;
            });
            
            $('#closenav').click(function(){
                $('#nav').animate({height: '0', marginBottom: '0'}, function(){$('#nav div').css('display', 'none')});
                $('#menutrigger').slideDown();
                return false;
            });
        });






// Scroll to TOP


$(function(){
		   
	$.fn.scrollToTop=function(){
		
		$(this).hide().removeAttr("href");
		
		if($(window).scrollTop()!="0"){
			$(this).fadeIn("slow")
		}
		var scrollDiv=$(this);
		
		$(window).scroll(function(){
								  
			if($(window).scrollTop()=="0"){
				$(scrollDiv).fadeOut("slow")
			}else{
				$(scrollDiv).fadeIn("slow")
			}
		
		});
		
		$(this).click(function(){
			$("html, body").animate({scrollTop:0},"slow");
		});
	
	}
			
});




$(function() {
	$("#toTop").scrollToTop();
});
	
$(document).ready(function(){
	
	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();
		
		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;
		
		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];
		
		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;
		
		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
	});

   });
	
});




