var iFactor = 8;

function stopSlide(obj) {
	obj.stop(true);
}

$(document).ready(function() {

	// prettyPhoto for: Filmboeken (youtube videos)
	if ($("#showVideos").length) {
		$("#showVideos").prettyPhoto({
			animation_speed: 'normal',
			theme: 'light_square',
			slideshow: 3000, 
			autoplay_slideshow: false,
			social_tools: ''
		});
	} 	
	
	if($('#videosContainer').length){

		var oVideoContainerItems = $('#videoContainerItems');
		var oSidebarGalleryUp = $('#videosContainer .up');
		var oSidebarGalleryDn = $('#videosContainer .down');
		
		oSidebarGalleryUp.mouseenter(function() {
			stopSlide(oVideoContainerItems);
			var iDuration = Math.abs(parseInt(oVideoContainerItems.css('top'))) * iFactor;
			var iDivTop = Math.abs(parseInt(oVideoContainerItems.css('top')));
			if (iDivTop > 0) {
				oVideoContainerItems.animate({
					top: 0
				}, {
					duration: iDuration,
					easing: 'linear'
				});
			}
		});
		
		oSidebarGalleryDn.mouseenter(function() {
			oSidebarGalleryDn.trigger('autoSlide', [iFactor, true, 0]);
		});

		oSidebarGalleryDn.bind('autoSlide', function(event, iFac, bStop, iDelay) {
			if (bStop === true) {
				stopSlide(oVideoContainerItems);
			}
			var iDuration = (oVideoContainerItems.height() - 400 - Math.abs(parseInt(oVideoContainerItems.css('top')))) * iFac;
			var iDivTop = oVideoContainerItems.height() - 400;

			if (iDivTop > Math.abs(parseInt(oVideoContainerItems.css('top')))) {
				oVideoContainerItems.delay(iDelay).animate({
					top: '-' + iDivTop
				}, {
					duration: iDuration,
					easing: 'linear'
				});
			}
		});
		
		$('#videoContainerItems .videoGalleryItem').mouseenter(function() {
			stopSlide(oVideoContainerItems);
		});			
		
		// slide gallery onload (if desired uncomment)
		//oSidebarGalleryDn.trigger('autoSlide', [(iFactor * 4), false, 2000]);

		//oSidebarGalleryUp.mouseout(function() {
		//	stopSlide(oVideoContainerItems);
		//});

		//oSidebarGalleryDn.mouseout(function() {
		//	stopSlide(oVideoContainerItems);
		//});
	}

});
