var oPlayer = null;

function playerReady(thePlayer)
{
	oPlayer = window.document[thePlayer.id];
	addListeners();
}

function addListeners()
{
	oPlayer.addModelListener('STATE', 'stateMonitor');
}

function openPress(sLang)
{
	if (typeof(sLang) == 'undefined')
	{
		sLang = 'nl';
	}

	wPress = window.open('/press/?lang='+sLang,'pressmsg','width=800,height=800');
	wPress.focus();
}

$(document).ready(function()
{
	if ($.browser.msie  && parseInt($.browser.version) == 7)  /* Fix for menu for IE7 */
	{
		var zIndexNumber = 1000;
		$('ul#nav li').each(function() {
			$(this).css('z-index', zIndexNumber);
			zIndexNumber -= 10;
		});
	}

	/* lightbox laden als deze beschikbaar is */
	if (jQuery().lightBox)
	{
		$('a[rel]').lightBox({fixedNavigation:true});
	}

	/* colorbox laden als deze beschikbaar is */
	if (jQuery().colorbox)
	{
		$('a[colorbox]').colorbox({width: '80%', height: '80%', iframe:true});
		$('a[colorbox-img]').colorbox();
	}

	/* pngfix voor wedstrijdhomepage IE6 */
	if ($.browser.msie == true && parseInt($.browser.version) == 6)
	{
		var sFilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/gfx/homepage/camera.png')";
		$('div#camera img').attr('src','/gfx/homepage/pixel.gif').css('filter', sFilter);
	}

	/* Menu items hover */
	$('div#navcontainer ul#nav > li').hover(function()
	{
		$(this).addClass('current');
	},
	function()
	{
		$(this).removeClass('current');
	});

	/* Start video on click for Homepage */
	$('div#invisible-click-layer').click(function()
	{
		oPlayer.sendEvent('PLAY');
	});

	/* Photo slideshow for Homepage */
	if($('div#picture-frame img').length > 0)
	{
		$('div#picture-frame img:first').nextAll('img').hide();

		setInterval(function()
		{
			$oCurrentImg = $('div#picture-frame img:visible');
			$oNewImg = $oCurrentImg.next('img');
			if(!($oNewImg.attr('src')))
			{
				$oNewImg = $('div#picture-frame img:first');
			}

			$oCurrentImg.fadeOut(1000, function(){ $oNewImg.fadeIn(1000) } );

		}, 5000);
	}
});


var iCurrent = 0;

function changeRallyPhoto()
{
	var iRandom = parseInt(Math.random() * (aPhotos.length-1))
	var sPhoto = aPhotos[iRandom];

	$('div#photo').fadeOut('fast', function()
	{
		$(this).css('backgroundImage', "url('"+sPath+sPhoto+"')").fadeIn('fast');
		setTimeout(changeRallyPhoto, 3000);
	});
}
