 $(document).ready(function(){
 			
			$("a[rel^='prettyPhoto']").prettyPhoto({
									show_title: true, 
									allow_resize: false, 
									theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
									overlay_gallery: true						
			});
			
			// image resizer for blog 
			$('.reSizer').aeImageResize({ width: 400 });
			
			// Scroller template scrollers 
			 $(".scroller_arrow").click(function(e){
			 		var $arrowID = $(this);
			 		var $scrollerSlider = $('#scroller_slider');
			 		var scrollerHeight = (0 - $scrollerSlider.height());
					var scrollerPos = Number($scrollerSlider.css('top').replace('px', ''));
					
					if ($arrowID.attr('id') == 'scroller_bottom_arrow'){
  					if (scrollerPos > (scrollerHeight + 700) ){
  						var scrollerUp = (scrollerPos - 350) + 'px';
							if(!$scrollerSlider.is(':animated')){
      						$scrollerSlider.stop(true,true).animate({
    								top: scrollerUp
    							},
    							{
    								duration:200,
    								easing: 'easeInOutExpo'
    							}
								)};
							}
					}
					if ($arrowID.attr('id') == 'scroller_top_arrow'){
  					if (scrollerPos < 0){
  						var scrollerDown = (scrollerPos + 350) + 'px';
							if(!$scrollerSlider.is(':animated')){
      						$scrollerSlider.stop(true,true).animate({
    								top: scrollerDown
    							},
    							{
    								duration:200,
    								easing: 'easeInOutExpo'
    							}
								)};
							}
					}
					e.preventDefault();
			 });
					
			// Gallery template scrollers
			 $(".gallery_arrow").click(function(e){
			 		var $arrowID = $(this);
			 		var $gallerySlider = $('#gallery_slider');
			 		var galleryWidth = (0 - Number($gallerySlider.width()));
					var galleryPos = Number($gallerySlider.css('left').replace('px', ''));
					
					if ($arrowID.attr('id') == 'gallery_right_arrow'){
						
  					if (galleryPos > (galleryWidth + 500) ){
  						var galleryLeft = (galleryPos - 400) + 'px';
							if(!$gallerySlider.is(':animated')){
      						$gallerySlider.stop(true,true).animate({
    								left: galleryLeft
    							},
    							{
    								duration:200,
    								easing: 'easeInOutExpo'
    							}
								)};
							}
					}
					if ($arrowID.attr('id') == 'gallery_left_arrow'){
  					if (galleryPos < 0){
  						var galleryRight = (galleryPos + 400) + 'px';
							if(!$gallerySlider.is(':animated')){
      						$gallerySlider.stop(true,true).animate({
    								left: galleryRight
    							},
    							{
    								duration:200,
    								easing: 'easeInOutExpo'
    							}
								)};
							}
					}
					e.preventDefault();
					
			 });		

			 // Auto-gallery 
			 
			 

			 $('.galleryimage').click(function(e){
			 		e.preventDefault();
			 		
				 	var $windowImage = $(this);
					var imageTitle = $windowImage.attr('title');
					var imageHref = $windowImage.attr('href');
					var imageText = $windowImage.siblings('.galleryimage_text').html();
					
					//populates the gallery
					galleryPopulate(imageTitle, imageHref, imageText);
					
					//creates hashtag
						location.hash = '#' + $windowImage.attr('class').replace('galleryimage ','');
						window.scrollTo(0, 0);
			 });	

 }); //end document ready
 
 function galleryPopulate(imageTitle, imageHref, imageText){
					jQuery.preLoadImages(imageHref);
 					var windowSrc= '<a href="' + imageHref + '" rel="prettyPhoto[Gallery]" title="' + imageTitle + '"><img src="' + imageHref + '" id="galleryResize"/></a>';
					$('#gallery_loader').animate({opacity:1}, 250).delay(2000).animate({opacity:0},250);
					$('#gallery_window').animate({opacity:0}, 100, function(){
           		$('.clearable').empty();
							$('#gallery_window').append(windowSrc);
							$('#gallery_title').append(imageTitle);
							$('#gallery_text').append(imageText);
							$("a[rel^='prettyPhoto']").prettyPhoto({
									show_title: true, 
									allow_resize: false, 
									theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
									overlay_gallery: false 
							});
							$('#galleryResize').aeImageResize({ height: 550, width: 600 });
          }).delay(3000).animate({opacity:1},500);
 };

 function galleryInit(){
 	// checks to see if a hashtag exists; if not, pull the first list item from the gallery.
 		if (location.hash == ''){
			var $windowImage = $(".galleryimage").first();
		} else {
			var imageID = (location.hash).replace('#','.');
			var $windowImage = $(imageID);
		}
			var imageTitle = $windowImage.attr('title');
			var imageHref = $windowImage.attr('href');
			var imageText = $windowImage.siblings('.galleryimage_text').html();
			galleryPopulate(imageTitle, imageHref, imageText);			
 };

function storeInit(){
 		// checks to see if a hashtag exists; animates scroller to hash location.
 		if (location.hash != ''){
		
			var hashID = (location.hash) + "_jump";
			var position = $(hashID).position();
			var scrollTo = (0 - Number(position.top)) + 'px';
						
			var $scrollerSlider = $('#scroller_slider');
			$scrollerSlider.stop(true,true).delay(1000).animate({
							top: scrollTo
						},
						{
							duration:1000,
							easing: 'easeInOutExpo'
						}
			);	
		}
};
 
 
					
 // Matt Farina's Image Preloader
 // taken from http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
 // Thanks, Matt
 
 (function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
