function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
	else
	{
		//alert(msg);
	}
}

var h;

$(document).ready(function()
{
	/* 
		
	*/
	var ie = false;
	jQuery.each(jQuery.browser, function(i, val)
	{
		//wc(val);
		
		if(i == 'msie' && val)
		{
			ie = jQuery.browser.version;
		}
	});
	
	$('a.external, a._blank').click(function(){
	
		window.open($(this).attr('href'));
		
		return false;
	});
	
	/* 
		beursgang banner op homepage
	*/
	if($('#page.homepage').length == 1)
	{
		window.setTimeout(function(){
			
			installBackGroundMusic('#background-music-container');
			
			/* rio popup */
			Shadowbox.open({
				content: BASE_URL + 'media/rio/visit-us-banner.jpg',
				player: 'img'
			}); 

		});
		
		window.setTimeout(function(){
			
			$('#background-music-container').remove();

		}, 23000);
		
		
		$('div.stockticker').cycle({
			fx: 'fade',
			delay: -3000, // additional delay (in ms) for first transition
			timeout: 5500,
			speed: 3500
		});
	}

	/* 
		newsticker
	
	var newsitems; 
	var curritem=0; 
	
	newsitems = $(".newsticker .articles li").hide().size(); 
	
	$(".newsticker .articles li:eq("+curritem+")").slideDown(); 
	
	setInterval(ticknews,6000); //time in milliseconds 

	
	function ticknews() 
	{ 
		
		$(".newsticker .articles li:eq("+curritem+")").slideUp(); 
		curritem = ++curritem%newsitems; 
		$(".newsticker .articles li:eq("+curritem+")").slideDown(); 
	
	}
	
	*/
	
	/* 
		round corners in IE > 6
	*/
	if(ie > 6){
		$("div.carousel a.item-name.selected, div.navigationobject > ul > li.selected > a, div.navigationobject > ul > li.inpath > a").each(
			function()
			{
				var contents = $(this).html();
				
				$(this)
					.empty()
					.append('<span class="rc-ltop"></span><span class="rc-rtop"></span>'
						+ contents
						+ '<span class="rc-lbottom"></span><span class="rc-rbottom"></span>'
					);
				
				delete contents;
			}
		);
	}
	
	/* 
		dropdown fixen voor IE < 8
	*/
	if(ie < 8)
	{
		$('#page div.headerframe div.navigationobject ul li ul > li').css({marginBottom: '-3px'});
	}
	
	/* 
		Homepage image frame, popup panels
	*/
		
	$("#page.homepage div.homepage-image-frame div.datarecord").css({ opacity: 0.85 });

	$("#page.homepage div.homepage-image-frame div.datarecord").hover(
		
		function ()
		{	
			
			if(!$(this).hasClass("selected"))
			{
			
				/* 
					css position top.
				*/
				var css_position_top = 321;
				
				/* 
					calculate the height for animation.
				*/
				var canvas_height = $(this).parent().height();
				
				var datarecord_height = $(this).height();
				
				var calculated_position_top = (canvas_height - datarecord_height);
				
				$(this).addClass("selected");
				
				
				/* 
					var css_position_top: mag niet groter zijn als max hoogte canvas.
				*/
				if( calculated_position_top <= css_position_top)
				{
					css_position_top = calculated_position_top;
				}
				
				/* 
					var css_position_top: mag niet negatief getal zijn, = wel negatief zet dan op hoogste positie.
				*/
				if( calculated_position_top < 0)
				{
					css_position_top = 0;
				}
				
					
				/* 
					animate to open position.
				*/						
				$(this).stop().animate({
					
					top: css_position_top
										
				}, '1500');
				
				wc('item open');
			
			}
		},
		function ()
		{
				
			
			if($(this).hasClass("selected"))
			{
				
				$(this).removeClass("selected");//.children("div");//.hide();
				
				/* 
					animate to closed position
				*/
				$(this).stop().animate({
					
					top: 321
					

					
				}, '1500');
				
								
				wc('item closed');
				
			}
			
		
		}	
	);
	
	/* 
		rotate
	*/
	h = $('p.rotating-image');
	
	if( h.length )
	{
		var img = $('img:first', h);
		var src = img.attr('src');
		
		$.get(
			
			src,
			
			{ return_type:'json' },
			
			function(data)
			{
			
				var files = data.files;
			
				for (i = 0; i < files.length; i++)
				{
					img
					.clone()
					.attr('src', '')
					.attr('alt',BASE_URL+'media/'+files[i])
					.appendTo( $(h) );
				}
				
				$(h).cycle({
					fx:			'fade',
					random:		1,
					delay:		-3000,
					timeout:	5500,
					speed:		3500,
					before:		cycleBefore,
					after:		cycleAfter
				});
				
			},
			
			'json'
		);
		
	};
	
	// before cycle
	function cycleBefore()
	{
		$(this)
			.filter('[alt^="http"]')
			.attr('src',$(this).attr('alt'))
			.removeAttr('alt');
	}
	
	// after cycle
	function cycleAfter(){
				
	}
	
	$('a.video').click(function(){
	
		Shadowbox.open({
			content:	$(this).attr('href'),
			player:		'flv',
			width:		496,
			height:		368
		});
		
		return false;
	});
	
});


/* 
	Shadowbox 3.0 Beta
	- buiten de jQuery ready houden
*/
var ShadowboxIsActive = false;

var ShadowboxOptions = {

	//language:				'nl',
	
	counterType:			'skip',//'default',//'skip',
	
	//overlayColor:			'#fff',
	
	overlayOpacity:	   		'0.4',
	
	initialWidth:			'550',//'320',
	initialHeight:			'450',//'160',
	
	resizeDuration:			'0.2',//'0.55',
	
	fadeDuration:			'0.15',//'0.35',
	
	animSequence:			'sync',//'wh',
	
	slideshowDelay:			4,
	
	//handleOversize:			'resize',//'drag',
		
	//enableKeys:				false,
	
	keysClose:				['c', 27], // c or esc
	
	players:				["iframe","html","img","swf","flv","qt","wmp"],
	
	autoDimensions:			true,
	continuous:				true,
	
	onOpen:	function(el) {
	
		wc('Shadowbox onOpen');
		
		ShadowboxIsActive = true;
		
		wc(h);
		
		h.cycle('pause');
		
		removeBackGroundMusic('#background-music-container');
	},
	
	onFinish: function() {
		
		wc('Shadowbox onFinish');
	},
	
	onClose: function(el) {
	
		wc('Shadowbox onClose');
		
		ShadowboxIsActive = false;
		
		h.cycle('resume');
		
		installBackGroundMusic('#background-music-container');
	}
};

Shadowbox.init(ShadowboxOptions);

/* 
	
*/
function installBackGroundMusic(id)
{
	if(true) // ! $.cookie('bgmusic'))
	{
		$.cookie('bgmusic', true, { expires: 365 });
		
		$(id).empty().append('<p id="background-music"></p>');
		
		if (swfobject.hasFlashPlayerVersion("9")) {
			var att = { data: BASE_URL + "media/background-music/anthem.swf", width:"120", height:"20" };
			var par = { menu:"false" };
			var mid = "background-music";
			var myFlashContent = swfobject.createSWF(att, par, mid);
		}
	}
}

function removeBackGroundMusic(id)
{
	$(id).empty();
}
