// JavaScript Document
/**
*	Prepare form
**/
var navOpen = false;
var navHoverTimeout;

function restartPlayer()
{
	if (document.getElementById('casemovie'))
	{
		var casemoviecontainer = document.getElementById('casemovie');
		casemoviecontainer.restart();
	}
}

function pausePlayer()
{
	if (document.getElementById('casemovie'))
	{
		var casemoviecontainer = document.getElementById('casemovie')
		casemoviecontainer.pauzeer();
	}
}



$(document).ready(function() {
	var navHoverTimeout;
	var navOpen = false;
	$('input').css('z-index','202');	
	//initSlideMenu('click');
	//initDropMenus('hover');
});



$(function(){
	var tm;

	$(window).scroll(function(){
	
		clearTimeout(tm);
		
		tm = setTimeout(function(){
			
			var top = $(window).scrollTop();
			
			$("#sideMenuContainer").animate({
			
				top: top+'px'
			
			}, 300);
		
		},300);
	
	}); 

		
	$("ul.menu a").hover(
		function(){
			$(this).css("border-bottom","1px #c3c3c3 dotted");				
		},
		function(){
			$(this).css("border-bottom","1px white dotted");
		}
	);
	
	
	$("#sideMenuIndentifier").click(function() {
		
		clearTimeout(navHoverTimeout);
	
		if ($("#sideMenuClose").hasClass("clicked")) {
			//Slide in
			$("#sideMenuIndentifier").animate({left: "-410px"}, 1000, "swing", function() { $('input').css('z-index','203'); $('#master_menu_container').css('z-index','1000'); $('#sideMenuIndentifier').css('z-index','1001');$('#master_menu_container').css('width','50px');});
			$("#sideMenuClose").removeClass("clicked");
			restartPlayer();
		} else {		
			//Slide out
			$("#sideMenuContainer").animate({top: $(window).scrollTop()}, 2, "swing");
			$("#sideMenuIndentifier").animate({left: "0"}, 1000, "swing");
			$("#sideMenuClose").addClass("clicked");
			$('input').css('z-index','1');
			$('#master_menu_container').css('z-index','204');
			$('#master_menu_container').css('width','500px');			
			pausePlayer();
		}
	});
});



/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</ul>

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initDropMenus(method) {
	if (method == '' || method == 0) {
		method = 'click';
	}
	
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	
	if (method == 'click')
	{
		$('ul.menu li a').click(function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
	
			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		 });
	}

	if (method == 'hover')
	{

		$('ul.menu li a').hover(
			function() {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;
				if (parent)
				{
					if($('#' + parent).hasClass('noaccordion')) {
						$(this).next().slideToggle('normal');
						return false;
					}
					if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
						if($('#' + parent).hasClass('collapsible')) {
							//$('#' + parent + ' ul:visible').slideUp('normal');
						}
						return false;
					}
					if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
						//$('#' + parent + ' ul:visible').slideUp('normal');
						checkElement.slideDown('normal');
						return false;
					}
				}
			},
			function() {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;
				if (parent)
				{
					if($('#' + parent).hasClass('noaccordion')) {
						$(this).next().slideToggle('normal');
						return false;
					}
					if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
						if($('#' + parent).hasClass('collapsible')) {
							//$('#' + parent + ' ul:visible').slideUp('normal');
						}
						return false;
					}
					if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
						//$('#' + parent + ' ul:visible').slideUp('normal');
						checkElement.slideDown('normal');
						return false;
					}
				}
			}
		);
	}
}

