var closeIntro = function ()
{
	$j('#flv div.movie').hide();

	$j('div.overlay').fadeOut(1000,function(){
		$j('#flv').remove();
		$j.rotatetabs();
	});
}

$j(document).ready(function(event)
	{
		
		/* question rollovers */
		
		$j('ul.questions li').each(function(i,el)
		{
			$j(this).addClass('nr'+i%3);
		});
		/*$j('ul.questions li a').mouseenter(function(event)
		{
			$j(this).children('.image').fadeOut(400);	
			$j(this).children('.answer').fadeIn(400);	
		});
		$j('ul.questions li a').mouseleave(function(event)
		{
			$j(this).children('.image').fadeIn(400);	
			$j(this).children('.answer').fadeOut(400);	
		});*/
		/* go back link */
		
		$j('a.goback').click(function(event)
		{
			event.preventDefault();
			history.go(-1);
		});
		
		var re = /admin/;
		var isAdmin = re.test(document.location.href);

		if ( isAdmin ) jQuery.fx.off = true;
		if ( isAdmin ) $j('#cont_home').addClass('admin');

		if ($j('#blockmenu').length==1)
		{
			var links = $j('#blockmenu a');

			$j('#blockmenu a').click(function(event)
			{
				event.preventDefault();
			});

			$j('#blockmenu a').mouseenter(function(event,forced)
			{
				if ( forced == true )
				{
				}
				else
				{
					$j.stoprotatetabs();
				}

				if ( $j(this).parent().hasClass('selected') ) return;

				links.parent().removeClass('selected');
				$j(this).parent().addClass('selected');
				$j(this).blur();

				var target = $j(this).attr('href');

				$j('div.block').hide();
				$j(target).fadeIn();

				startRotates( $j(target) );
			});

			// elke tab 1 keer tonen:

			$j.rotatetabs = function ()
			{
				var tabcnt = 0;

				if ( ! isAdmin )
				{
					$j('#blockmenu').everyTime(6000,function()
					{
						tabcnt++;
						if ( tabcnt == 4 ) tabcnt = 0;

						var trg = $j('#blockmenu a:eq('+tabcnt+')');

						trg.trigger('mouseenter',true);
						//trg.css('color','red');
					},4);
				}

			}

			$j.stoprotatetabs = function ()
			{
				if ( ! isAdmin )
				{
					$j('#blockmenu').stopTime();
				}
			}

			// FLV

			if ( $j.browser.msie && $j.browser.version == '6.0' )
			{
				$j('#flv').remove();
				$j.rotatetabs();
			}
			else
			{
				$j('#flv').css({
					'display':'block',
					'width':$j(window).width(),
					'height':$j(document).height()
				});

				$j('#flv div.overlay').css({
					'opacity':0.5,
					'width':$j(window).width(),
					'height':$j(document).height()
				});

				$j('#flv a.close').click(function(event)
				{
					event.preventDefault();
					closeIntro();
				});
			}

			// COL ROTATES

			var updateRotates = function (colrotates)
			{
				var children = $j('div.colrotate',colrotates);
				var counter = $j(colrotates).data('counter');

				if ( ! counter ) counter = Math.floor(Math.random()*10);

				$j('div.colrotate:nth-child(1)',colrotates).hide().appendTo(colrotates).fadeIn(1500);

				counter++;
				if ( counter == children.length ) counter = 0;

				$j(colrotates).data('counter',counter);
			}

			var startRotates = function (block)
			{
				if ( ! isAdmin )
				{
					$j('div.block').stopTime();

					$j(block).everyTime(30000,function()
					{
						$j('div.colrotates',block).each(function(colrotnum,colrotates)
						{
							$j(colrotates).oneTime(1500*(colrotnum+1),function()
							{
								updateRotates(colrotates);
							});
						});
					});
				}
			}

			// randomize stories

			$j('div.block').each(function(blocknum,block)
			{
				$j('div.colrotates',block).each(function(colrotnum,colrotates)
				{
					var rand = Math.floor(Math.random()*5);
					for ( var i = 0 ; i < rand ; i++ )
					{
						$j('div.colrotate:nth-child(1)',colrotates).appendTo(colrotates);
					}
				});
			});

			startRotates( $j('div.block:nth-child(1)') );
		}



		// LOG DOWNLOADS

		$j('a.logdownload').click(function(event)
		{
			var href = $j(this).attr('href');
			var trg = $j(this).attr('target');

				if ( trg == '_blank' )
				{
			$j.post('/rpc.asp?action=logdownload',{
				url: href
			},function(data){
			//		window.location = href;

			});
				}
				else
				{
				event.preventDefault();
			$j.post('/rpc.asp?action=logdownload',{
				url: href
			},function(data){
					window.location = href;

			});
				}


		});

		// BANNERS

		if ( $j('div.banners') )
		{
			var cnt = 0;

			$j('div.banners div.banner').each(function()
			{
				cnt ++;
				var banner = $j(this);

				var link = $j('<a></a>').attr('href','#').text(cnt);

				link.data('target',banner);

				link.click(function(event)
				{
					event.preventDefault();

					if ( $j(this).hasClass('active') ) return;

					$j('div.banners div.nav a').removeClass('active');
					$j(this).addClass('active');

					var banner = $j($j(this).data('target'));

					banner.hide();
					banner.insertBefore($j('div.banners div.nav'));
					banner.fadeIn(750);
				});

				$j('div.banners div.nav').append(link);
			});

			//var rnd = Math.floor( Math.random() * $j('div.banner').length );
			//$j($j('div.banners div.nav a')[rnd]).click();
			$j($j('div.banners div.nav a')[0]).click();

			$j('div.banners').mouseover(function(event)
			{
				if ( ! isAdmin )
				{
					$j('div.banners').stopTime();
				}
			});
			$j('div.banners').mouseout(function(event)
			{
				if ( ! isAdmin )
				{
					$j('div.banners').everyTime(5000,function()
					{
						var next = $j('div.banners div.nav a.active').next();
						if ( next.length==0 ) next = $j('div.banners div.nav a:first');
						next.click();
					});
				}
			});
			$j('div.banners').mouseout();
		}

		// BANNER NEXT TO OTHER BANNER ?!


		if ( ! isAdmin )
		{
			if ( $j('#bannertext .bannertext1') )
			{
				var cont = $j('#bannertext');
				$j('.bannertext2',cont).hide();

				var i = 0;
				if (false)
				{
				cont.everyTime(20000,function ()
				{
					i++;

					if ( i == 1 )
					{
						$j('.bannertext1',cont).hide()
						$j('.bannertext2',cont).show();;
					}
					else
					{
						i = 0;

						$j('.bannertext1',cont).show();
						$j('.bannertext2',cont).hide();
					}
				});
				}
			}
		}
		else
		{
			$j('.bannertext1',cont).css('position','relative');
			$j('.bannertext2',cont).css('position','relative');
		}

		// ACCORDEON

		var openAcc;
		$j('div.acc').hide();

		$j('a.acc').click(function(event)
		{
			event.preventDefault();
			if(openAcc)openAcc.hide(150);
			openAcc = $j( $j(this).attr('href') );
			openAcc.show(150);
		});

		$j('a.acc:first').click();

		var searchBox = $j('#search_keywords')
		var searchLabel = searchBox.val();

		searchBox.focus(function(event)
		{
			if ( searchBox.val() == searchLabel ) searchBox.val('');
		});
		searchBox.blur(function(event)
		{
			if ( searchBox.val() == '' ) searchBox.val(searchLabel);
		});
	});
