//Current Scroll
var currentScroll = 0;
var currentGallery = 1;
var scrollOn = false;

//Scroll It
function scrollIt(moveDiv, moveVar) {

	//Getting Length
	var more_var = document.getElementById(moveDiv).offsetHeight;
	new_var = (0 - more_var) + 330;

	//Obj
	moveObj = $("#" + moveDiv);
	
	//Scrolling
	if (scrollOn) {
		currentScroll = currentScroll + moveVar;
	
		//Scroll Over
		if (currentScroll > 0) currentScroll = 0;
		if (currentScroll < new_var) currentScroll = new_var;
		
		//Scroll It
		moveObj.animate( { marginTop: + currentScroll + 'px'}, 80, function() {
			if (scrollOn) {
				scrollIt(moveDiv, moveVar);	
			}
		});
	} else {
		moveObj.stop();
	} 
}

//Main Script
$(document).ready(
	function(){
		$('#mapbox img').mouseover( function() { $(this).attr('src', 'http://sweet-e.ca/wp-content/themes/sweetes/images/maph.gif'); } )
		$('#mapbox img').mouseout( function() { $(this).attr('src', 'http://sweet-e.ca/wp-content/themes/sweetes/images/map.gif'); } )
		
		//First Menu
		if ($('#fragment-1').length) {
			$('#fragment-1').css('display', 'block');
		}
		
		//Getting Overflow of Text
		if ($('#content_text').length) {
			//Getting Length
			var more_var = document.getElementById("content_text").offsetHeight;
		
			//Show Scroll or Not
			if (more_var > 295) {
				document.getElementById("arrow_wrap").style.display = "block";
			}		

		}
		
		$("#scroll_down").mousedown(
			function() {
				scrollOn = true;
				scrollIt("content_text", -50)
			}
		).mouseup(
			function() {
				scrollOn = false;
			}
		)
		
		$("#scroll_up").mousedown(
			function() {
				scrollOn = true;
				scrollIt("content_text", 50)
			}
		).mouseup(
			function() {
				scrollOn = false;
			}
		)
		
		//Extra Scroll In Menu
		$("#menu-container a").click(
			function() {
				scrollOn = false;
				currentScroll = 0;
				
				//Get Name
				var currentName = $(this).attr('name');
				
				//Display
				$(".fragment").css('display', 'none');
				$("#" + currentName).css('display', 'block');
				
				//Menu Class
				$("#menu-container a").removeClass('active');
				$(this).addClass('active');
				
				
				
				//Getting Length
				var more_var = document.getElementById("content_text").offsetHeight;
				
				//Show Scroll or Not
				if (more_var > 300) {
					document.getElementById("arrow_wrap").style.display = "block";
				} else {
					document.getElementById("arrow_wrap").style.display = "none";
				}
				//To The Top
				$("#content_text").animate( { marginTop: '0px'}, 80);
			}
		)
		

		
		//Gallery Img
		$(".content_gallery img").click(
			function() {
				//Get SRC
				var thisLink = $(this).attr('src');

				//String Replace
				var newLink = thisLink.replace('-110x100', '');
				
				//Change Image
				$("#gallery_pic").attr('src', newLink);
			}
		)

	}
);


