// JavaScript Document
$(document).ready(function() {
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.aspx #content';
			$('#pager').load(toLoad, function(){
				changeTheNews('item1');
				$('#scrollpane').jScrollPane({dragMinHeight:80, dragMaxHeight:80});
				//$('H1').bind('click', function(){ clickHome(); });
				$('A.logo').bind('click', function(){ clickHome(); });
				$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').hover(function(){ setAfmeldenDim(); }, function(){ setAfmeldenLite(); });
				$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').hover(function(){ setAanmeldenDim(); }, function(){ setAanmeldenLite(); });
				$('.corner').each(function(){
					$(this).animate({  
						'opacity': 1  
					}, "slow")
				});
			});
		}
	});
	var news = $('A.item').each(function(){
		var href = $(this).attr('id');
		var hash = window.location.hash.substr(1);
		if(hash==href){ setTheNews(hash); }

	});

	$('#nav li a').click(function(){
		var toLoad = $(this).attr('href')+' #content';
		$('#content').stop().animate({"left": "-4000px"}, "slow", loadContent);
		
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			$('#content').load(toLoad,'', function(){
				$('#scrollpane').jScrollPane({dragMinHeight:80, dragMaxHeight:80});
				changeTheNews('item1');
				showNewContent();
			});
		}
		function showNewContent() {
			$('#content').css("left", "4000px").animate({"left": "-=4000px"}, "slow");
			//$('H1').bind('click', function(){ clickHome(); });
			$('A.logo').bind('click', function(){ clickHome(); });
			$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').hover(function(){ setAfmeldenDim(); }, function(){ setAfmeldenLite(); });
			$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').hover(function(){ setAanmeldenDim(); }, function(){ setAanmeldenLite(); });
			$('.corner').each(function(){
				$(this).animate({  
					'opacity': 1  
				}, "slow")
			});
		}
		return false;
	});
	
	function setAfmeldenDim()
	{
	    document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').className = 'buttonAfmeldenHover';
    }
    
    function setAfmeldenLite()
	{
        document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').className = 'buttonAfmelden';
    }
    
    function setAanmeldenDim()
	{
	    document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').className = 'buttonAanmeldenHover';
    }
    
    function setAanmeldenLite()
	{
        document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').className = 'buttonAanmelden';
    }

	function clickHome(){
		var toLoad = 'Default.aspx #content';
		$('#content').stop().animate({"left": "-4000px"}, "slow", loadContent);
		
		function loadContent() {
			$('#content').load(toLoad,'', function(){
				$('#scrollpane').jScrollPane({dragMinHeight:80, dragMaxHeight:80});
				changeTheNews('item1');
				showNewContent();
				activeState(this);
			});
		}
		function showNewContent() {
			$('#content').css("left", "4000px").animate({"left": "-=4000px"}, "slow");
			$('.nav LI A .hover').each(function(){
				$(this).animate({  
					'opacity': 0  
				}, "slow")
			});
	
			$('.nav LI A .active').each(function(){
				$(this).animate({  
					'opacity': 0  
				}, "slow")
			});
			$('.corner').each(function(){
				$(this).animate({  
					'opacity': 0  
				}, "slow")
			});
			//$('H1').bind('click', function(){ clickHome(); });
			$('A.logo').bind('click', function(){ clickHome(); });
			$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').hover(function(){ setAfmeldenDim(); }, function(){ setAfmeldenLite(); });
			$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').hover(function(){ setAanmeldenDim(); }, function(){ setAanmeldenLite(); });
		}
		return false;
	}

	$('.item').click(function() {
		var newsItem = $(this).attr('id');
		changeTheNews(newsItem);
	});
	//$('H1').bind('click', function(){ clickHome(); });
	$('A.logo').bind('click', function(){ clickHome(); });
	$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAfmelden').hover(function(){ setAfmeldenDim(); }, function(){ setAfmeldenLite(); });
	$('#ctl00_ctl00_ctl00_ContentPlaceHolderDefault_ContentBody_Nieuwsbrief_2_BtnAanmelden').hover(function(){ setAanmeldenDim(); }, function(){ setAanmeldenLite(); });

	function changeTheNews(x){
		$('.item').click(function() {
			if($(this).attr('id')!='item1') { x=$(this).attr('id'); } else { x='item1'; }
			var news = "news"+x;
			var img = "img"+x;
			$('.newsitem').stop().animate({
				'opacity': 0  
			}, "slow", function(){
				$('.newsitem').css({ 'display': 'none', 'visibility': 'hidden' });
				$('#'+news).css({ 'display': 'block', 'visibility': 'visible' });
				$('#'+news+' .scroll').jScrollPane({dragMinHeight:80, dragMaxHeight:80});
				$('#'+news).animate({ 'opacity': 1 }, "slow");
			});
			$('.imgitem').stop().animate({
				'opacity': 0  
			}, "slow", function(){
				$('.imgitem').css({ 'display': 'none', 'visibility': 'hidden' });
				$('#'+img).css({ 'display': 'block', 'visibility': 'visible' });
				$('#'+img).animate({ 'opacity': 1 }, "slow");
			});
		});
	}

	function setTheNews(x){
		var news = "news"+x;
		var img = "img"+x;
		$('.newsitem').css({ 'display': 'none', 'visibility': 'hidden' });
		$('#'+news).css({ 'display': 'block', 'visibility': 'visible' });
		$('#'+news+' .scroll').jScrollPane({dragMinHeight:80, dragMaxHeight:80});
		$('.imgitem').css({ 'display': 'none', 'visibility': 'hidden' });
		$('#'+img).css({ 'display': 'block', 'visibility': 'visible' });
	}

	$('.nav LI A').append('<span class="default"></span><span class="hover"></span><span class="active"></span>');  
		// span whose opacity will animate when mouse hovers.  
		$('.nav LI A .hover').each(function(){
			$(this).css('opacity',0);
		});

		$('.nav LI A .active').each(function(){
			$(this).css('opacity',0);
		});

		$('.nav LI A').hover(function() {  
			$('.hover', this).stop().animate({ 'opacity': 1 }, "slow")
			$('.default', this).stop().animate({ 'opacity': 0 }, "slow")
		}, function() {  
			$('.hover', this).stop().animate({ 'opacity': 0 }, "slow")  
			var active = $('.active', this).css('opacity');
			if (active==0){
				$('.default', this).stop().animate({ 'opacity': 1 }, "slow")  
			}
		});

		$('.nav LI A').click(function() {
			activeState(this);
		});

		function activeState(x) {
			$('.nav LI A .active').each(function(){
				$(this).stop().animate({ 'opacity': 0 }, "slow")
			});
			$('.nav LI A .hover').each(function(){
				$(this).stop().animate({ 'opacity': 0 }, "slow")
			});
			$('.nav LI A .default').each(function(){
				$(this).stop().animate({ 'opacity': 1 }, "slow")
			});
			//alert(x);
			if(x!="") {
				$('.active', x).stop().animate({ 'opacity': 1  }, "slow")  
				$('.default', x).stop().animate({ 'opacity': 0  }, "slow")  
				$('.hover', x).stop().animate({ 'opacity': 0  }, "slow")  
			}
		}

	var active = $('.nav LI A').each(function(){
		var sPath = window.location.pathname;
		var sPath = sPath.substring(sPath.lastIndexOf('/') + 1);
		var item = $(this).attr('href');
		if (sPath==item) { activeState(this); }
	});
});