// Floating menu
$(document).ready(function(){
	$float_speed=1500; //milliseconds
	$float_easing="easeOutQuint";
	$menu_fade_speed=500; //milliseconds
	$page_load_fade_delay=2000; //milliseconds
	$closed_menu_opacity=0.75;
	
	//cache vars
	$fl_menu=$("#fl_menu");
	$fl_menu_menu=$("#fl_menu .menu");
	$fl_menu_label=$("#fl_menu .label");
	$fl_menu_item=$("#fl_menu .menu .menu_item");
	
	$(window).load(function() {
		menuPosition=$fl_menu.position().top;
		FloatMenu();
		$fl_menu_item.delay($page_load_fade_delay).fadeTo($menu_fade_speed, 0, function(){$fl_menu_item.css("display","none");});
		/*$fl_menu.hover(
			function(){ //mouse over
				$fl_menu_label.stop().fadeTo($menu_fade_speed, 1);
				$fl_menu_item.css("display","block").stop().fadeTo($menu_fade_speed, 1);
			},
			function(){ //mouse out
				$fl_menu_label.stop().fadeTo($menu_fade_speed, $closed_menu_opacity, function(){$fl_menu_item.css("display","none");});
				$fl_menu_item.stop().fadeTo($menu_fade_speed, 0);
			}
		);*/

	});
	
	$(window).scroll(function () { 
		FloatMenu();
	});
	
	function FloatMenu(){
		var scrollAmount=$(document).scrollTop();
		var newPosition=menuPosition+scrollAmount;
		if($(window).height()<$fl_menu.height()+$fl_menu_menu.height()){
			$fl_menu.css("top",menuPosition);
		} else {
			$fl_menu.stop().animate({top: newPosition}, $float_speed, $float_easing);

		}
	}
});

////////////////////////////////////////////////////////////////////////////////////////////////
// Nav active state
  $(document).ready(function() {
	
	$(".btn-nav").anchorScroll();
	
	$("a.btn-nav").click(function(){
		$("a.btn-current").removeClass("btn-current");
		 $(this).addClass("btn-current");
				event.preventDefault();
	  })

});


// Anchorscroll
(function($){
	$.fn.anchorScroll = function(options) {
		var defaults = {
			speed: 1100,
			fx: "jswing"
		};	
		//var version =  "1.0";
		var options = $.extend(defaults, options);
		return $(this).each(function(){
			var element = this;
			
			
			$(element).click(function (event) {	
				
				var locationHref = window.location.href;
				var elementClick = $(element).attr("href");
				
				var destination = $(elementClick).offset().top;
				
				$("html,body").animate({ scrollTop: destination-120}, options.speed,  options.fx);
				
				//Stop links default events
				event.preventDefault();

				return false;
			})
		})
	}
})(jQuery);
////////////////////////////////////////////////////////////////////////////////////////////////

// Drag Panel
$(document).ready(function () {        
	$('.timeline').mousedown(function (event) {
		$(this)
			.data('down', true)
			.data('x', event.clientX)
			.data('scrollLeft', this.scrollLeft);
			
		return false;
	}).mouseup(function (event) {
		$(this).data('down', false);
	}).mousemove(function (event) {
		if ($(this).data('down') == true) {
			this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
		}
	}).css({
		'overflow' : 'hidden',
		'cursor' : 'move'
	});
});

$(window).mouseout(function (event) {
	if ($('.timeline').data('down')) {
		try {
			if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
				$('.timeline').data('down', false);
			}                
		} catch (e) {}
	}
});	

function ViewClip(mov) {
	$(document).scrollTop(0);
	$('#ValpreSWF')[0].viewMovie(mov);
}
