var winHeight;
var contentHeight;

(function($){

	var AG = {
		ondomready: function(){

			//$(document).pngFix();
			AG.init();
			AG.buildHome();
			AG.buildGallery();
			
			AG.buildAnchorLinking();
			AG.buildCustomScroll();
		
		},
		
		init: function() {
					
		},
		
		buildHome: function() {
			$("#home_slides").cycle({
				fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			});
		},
		
		buildGallery: function() {
			$("#gallery_slides").cycle({
				fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
				next: '#arrowRight',
				prev: '#arrowLeft'
			});
		},
		
		buildAnchorLinking: function() {
			$("#pageScrollNav a").click(function(e) {
				e.preventDefault();
				$("#pageScrollNav a").toggleClass("active", false);
				$(this).toggleClass("active", true);
				
				anchorName = "anchor_"+$(this).attr("href").replace("#", "");
				destY = -1*$("#"+anchorName).position().top;
				//alert(anchorName + ": " + destY);
				$("#innerScroll").animate({top: destY+"px"}, 500);
				
				
			});
		},
		
		buildCustomScroll: function() {
			
			if ($("#innerScroll").length <= 0 || $(".scrollContainer").length <= 0) {
				$("#contentScroll").hide();
				return;
			}
		
			winHeight = $(".scrollContainer").height();
			contentHeight = $("#innerScroll").height();
						
			if (winHeight > contentHeight) {
				$("#contentScroll").hide();
				return;
			}
			
			$("#contentScroll").show();
			
			$("#arrowUp").hover(function() {
				time = contentHeight / 150 * 1000;
				atop = -1*$("#innerScroll").position().top;
				factor = atop/contentHeight;
				$("#innerScroll").animate({top: 0}, factor * time);
			}, function() {
				$("#innerScroll").stop();
			});
			
			$("#arrowDown").hover(function() {
				var scrollTo;
				time = contentHeight / 150 * 1000;
				atop = -1*$("#innerScroll").position().top;
				factor = 1-atop/contentHeight;
				
				scrollTo = -1*(contentHeight - winHeight + 20);

				$("#innerScroll").animate({top: scrollTo}, factor * time);
			}, function() {
				$("#innerScroll").stop();
			});
			
			
		}
		

	}

	window.AG = AG;
	$(document).ready(function(){AG.ondomready();});
})(jQuery);

