google.load("jquery", "1.4");
google.load("jqueryui", "1.7");
google.load("swfobject", "2.1");

google.setOnLoadCallback(function()
{
	core();
});

/*
 * Place your custom code inside this function
 */

function custom()
{
	$("#navigation .level_1").hover(function() {
		$(this).find('ul').stop(true,true).fadeIn('fast');
	}, function() {
		$("#navigation li ul").delay(100).fadeOut('fast');
	});

	$(".tabs").tabs();

	$('#news').find('a').each(function() {
		var href = $(this).attr("href");
		$(this).parents('li').css('cursor','pointer');
		$(this).parents('li').click(function() {
			document.location.href = href;
		});
	});
}

function hanleRandomDivs()
{
	$(".random").each(function()
	{
		var nthChild = Math.floor(Math.random() * $(this).children().size() + 1);

		$(this).find(":nth-child(" + nthChild + ")").show();
	});
}

function handleVideos()
{
	$(".videoItem").each(function(i)
	{
		var vars = { 'file': $(this).find('img').attr('rel'), 'stretching': 'exactfit'};
		var params = { menu: 'false', allowfullscreen: 'true' };
		var attributes = { id: $(this).find('img').attr('id'), name: $(this).find('img').attr('id') };

		swfobject.embedSWF('http://www.websitebeheermodule.nl/Lib/WYSIWYG/swf/player.swf', $(this).find('img').attr('id'), $(this).find('img').width(), $(this).find('img').height(), "9.0.0", "", vars, params, attributes);
	});
}

function setWrapperHeights()
{
	$(".wrapper").each(function()
	{
		var maxHeight = 0;
		$(this).find('.workspaceItem').each(function()
		{
			var top = parseInt($(this).css('top').replace('px',''));
			var height = $(this).height();

			if(top+height > maxHeight)
			{
				maxHeight = top+height;
			}
		});

		$(this).parent().height(maxHeight);
		$(this).show();
	});
}

function handleImageHrefs()
{
	$('.imageItem').find('img').each(function(i) {
		if($(this).attr('href'))
		{
			$(this).wrap('<a href="' + $(this).attr('href') + '" />')
		}

	});

}

function handleDatePickers()
{
	$(".datepicker").each(function() {
		$(this).datepicker({
			dateFormat: $(this).attr('rel')
		});
	});
}

function handleManditory()
{

	$(".mandatory:first").each(function() {
		$(this).parents('form').submit(function () {

			var pass = true;

			$(".mandatory").each(function() {
				if($(this).val() == '')
				{
					$(this).addClass('mandatory');
					$(this).focus();

					if($(this).attr('rel') != '')
					{
						alert($(this).attr('rel'));
					}
					else
					{
						alert('Field ' + $(this).attr('name') + ' is empty');
					}

					pass = false;
				}
			});

			return pass;
		});
	});


}

function core()
{
	custom();

	handleImageHrefs();

	// setWrapperHeights();

	handleDatePickers();

	handleManditory();

	hanleRandomDivs();

	handleVideos();
}


