var get = {
	id : function(id) {
		return document.getElementById(id);
	},
	tag : function(t, p) {
		return p ? p.getElementsByTagName(t) : document.getElementsByTagName(t);
	}
};
function goToAnchor(anchor) {
	var curUrl = String(window.location);
	var dashPos = curUrl.indexOf('#');
	if(dashPos > 0) 
		var url = curUrl.substring(0, dashPos) + '#' + anchor;
	else
		var url = curUrl + '#' + anchor;
	window.location = url;
}
var searchPage = {
	checkResult : function(id) {
		var t = get.id(id);
		var n = t.firstChild.nodeValue;
		if(n < 10)
			t.firstChild.nodeValue = '0' + n;
	}
};
function dropdown(o, dd, cs) {
	// Swap user settings
	var enableSwap = true;
	var swapClass = 'hover';
	
	// Global vars
	var dd = get.id(dd);
	var cs = cs ? get.id(cs) : o;
	var oc = cs.className;
	
	if(dd.hasChildNodes()) {
		// Mouseover
		dd.style.display = 'block';
		if(enableSwap) cs.className = swapClass;
		
		// Mouseout
		o.onmouseout = function() {
			dd.style.display = 'none';
			if(enableSwap) cs.className = oc;
		};
	};
};
function shortenByClass(tagName, className, maxLength, close) {
	objElements = document.getElementsByTagName(tagName);
	for(i = 0; i < objElements.length; i++) {
		if(objElements[i].className == className) {
			if(objElements[i].innerHTML.length > maxLength) {
				objElements[i].innerHTML = objElements[i].innerHTML.substring(0, maxLength);
				if(objElements[i].innerHTML.substring(objElements[i].innerHTML.length - 1, objElements[i].innerHTML.length) == ' ')
					objElements[i].innerHTML = objElements[i].innerHTML.substring(0, objElements[i].innerHTML.length - 1);
				if(close)
					objElements[i].innerHTML = objElements[i].innerHTML + close;
			};
		};
	};
};
function zClass(id, t, eClass, b) {
	var p = get.id(id);
	var e = get.tag(t, p);
	var c = 0;
	for(i = 0; i < e.length; i++) {
		if(e[i].className == eClass) {
			if(b == false && c == 0)
				c++;
			else if(c == 0) {
				e[i].className = eClass + '_even';
				c++;
			} else {
				e[i].className = eClass + '_odd';
				c = 0;
			};
		};
	};
};
function rssCheck() {
	if(get.id('news_page') || get.id('news_message') || get.id('news_view_0') || get.id('news_archive')) {
		get.id('rss_link').style.display = 'block';
	};
};
function set_hidden_input(id,checked) {			
	var objRequired=document.getElementById('choice_required');
	if(checked)
		objRequired.value=objRequired.value+id+';';
	else
		objRequired.value=objRequired.value.replace(id+';','');
	var objInput=document.getElementById(id);
	if(checked)
		objInput.value='Ja';	
	else
		objInput.value='Nee';
};

function navigation() {
	
	// Level 2 - show subelements if active
	$('#navigation > li > .active').next().show();
	
	// Level 3 - show subelements if active
	$('#navigation .subelement > .active').next().show();
	
	// Level 1
	$('#navigation > li > ul:has(li)').parent().children('a').click(function(event) {
		$(this).next(':has(li)').toggle('normal');
		event.preventDefault();
	});
	
	// Level 3
	$('#navigation .subelement1 ul:has(li)').parent().hover(function() {	
		var $this = $(this);
		$this.children('a').addClass('hover');
		$this.children('ul:has(li)').css({
			width : 0,
			opacity : 0							   
		}).stop().animate({
			width : 200,
			opacity : 1
		}, 'normal');
	}, function() {
		var $this = $(this);
		$this.children('a').removeClass('hover');
		$this.children('ul:has(li)').stop().animate({
			width : 0,
			opacity : 0
		}, 'fast', function() {
			$(this).hide();
		});
	});
};

$(window).load(function() {
	
	$('.movie').each(function(i) {
							  
		// Set up variables
		var fpContainer = $(this),
			fpMovie = fpContainer.children('.movie-player'),
			fpMovieId = fpMovie.attr('class') + '-' + i,
			fpControls = fpContainer.children('.movie-controls'),
			fpControlsId = fpControls.attr('class') + '-' + i;
			
		// Assign attributes
		fpMovie.attr('id', fpMovieId);
		fpControls.attr('id', fpControlsId);
		
		// Set up flowplayer
		flowplayer(fpMovieId, {
			src : 'style/stabu08/flowplayer/flash/flowplayer.swf',
			wmode : 'opaque'
		}, {
			canvas : {
				backgroundColor : '#333333'
			},
			clip: {
				autoPlay : false,
				autoBuffering : true
			},
			plugins: {
				controls : null
			}
		}).controls(fpControlsId);

		// Set up initial state
		var oBottom = fpControls.css('bottom'),
			initStyle = {
				opacity : 0,
				bottom : oBottom.substring(0, oBottom.length - 2) / 2 + 'px'
			};
		fpControls.css(initStyle);
			
		// Set up events
		fpContainer.hover(function() {
			fpControls.stop().animate({
				opacity : 1,
				bottom: oBottom
			}, 250);
		}, function() {
			fpControls.stop().animate(initStyle, 500);
		});

	});
		
});

$(function() {
	$('hr').wrap('<div class="hr" />');
});