
jQuery(document).ready(function($) {
	
	// Sub-menu show/hide on parent hover code 
	$(".hide-portfolio .portfolio-entry ul.sub-menu").css('display', 'none');
	$(".hide-portfolio .portfolio-entry").hover(
		function() {
			$(".hide-portfolio .portfolio-entry ul.sub-menu").css('display', 'block');
		},
		function() {
			$(".hide-portfolio .portfolio-entry ul.sub-menu").css('display', 'none');
		}
	);

	$(".hide-about .about-entry ul.sub-menu").css('display', 'none');
	$(".hide-about .about-entry").hover(
		function() {
			$(".hide-about .about-entry ul.sub-menu").css('display', 'block');
		},
		function() {
			$(".hide-about .about-entry ul.sub-menu").css('display', 'none');
		}
	);

	
	
	
	// Slider  code
	
	if ($('#slider-wrapper')) {
	
		// Slider position retainment code

		// Look for dw_slider_position cookie
		var documentCookies = document.cookie.split("; ");
		for (i=0; i < documentCookies.length; i++) {
			if (documentCookies[i].indexOf("dw_slider_position=") == 0) {
				var positionValue = documentCookies[i].substring( 19, documentCookies[i].length );
				break;
			}
		}

		positionValue = parseInt(positionValue);

		// Set the slider position to value in cookie
		$('#slider-wrapper').scrollLeft(positionValue);

		
		
		// Scroll Animation
		scroll_speed = 0.3 // Pixels/Millisecond
		right_margin = 8 // Right margin on each element (right-most should not be revealed with scroll)
		
		$("#next").mouseenter(
			function() {
				total_slider_width = $('#slider-wrapper').attr("scrollWidth");
				slider_width = $('#slider-wrapper').width();
				scroll_distance = total_slider_width - slider_width - right_margin;
				
				scroll_position = $('#slider-wrapper').scrollLeft();

				scrolling_time = (scroll_distance - scroll_position)/scroll_speed;
				$('#slider-wrapper').animate({ scrollLeft : scroll_distance }, scrolling_time);
			}
		);

		$("#prev").mouseenter(
			function() {
				total_slider_width = $('#slider-wrapper').attr("scrollWidth");
				slider_width = $('#slider-wrapper').width();
				scroll_distance = total_slider_width - slider_width - right_margin;
				
				scroll_position = $('#slider-wrapper').scrollLeft();

				scrolling_time = (scroll_position)/scroll_speed;
				$('#slider-wrapper').animate({ scrollLeft : 0 }, scrolling_time);
			}
		);
		
		
		$("#next, #prev").mouseleave(
			function() {
				$('#slider-wrapper').stop();

				// Remmeber slider position with cookie
				document.cookie = "dw_slider_position=" + $('#slider-wrapper').scrollLeft();
			}
		);
		
	}
});

