
$(window).bind('load resize updateShadow', function(e){

	//================================================================================
	// shadow on article
	//================================================================================


	
	  $('#drop_shadow_layer').css({
		position: 'absolute',
		width: ($('#article_div').width() + 20) + 'px',

		height: ($('#article_div').height() + 20) + 'px',
		top: ($('#article_div').offset().top + 10) + 'px',
		left: ($('#article_div').offset().left - 10) + 'px'

	  });
	
	//================================================================================
	// place marker
	//================================================================================
	
	$('.marker_article').css({
		top: ($('#article_holder').offset().top-10) + 'px',
		left: 310 + 'px'
	});

});

$(window).bind('load', function(e){

	//================================================================================
	// make texts non selectable
	//================================================================================

	$('.disable_select').each(function() {
	    $(this).attr('unselectable', 'on')
	           .css('-moz-user-select', 'none')
	           .each(function() { 
	               this.onselectstart = function() { return false; };
	            });
	});

	//================================================================================
	// contact item
	//================================================================================
	$('#contact_div').hide();

	$('#contact_item').mouseenter(function(e){		
		$('#contact_div').css({
			left: (-$('#contact_div').width()+$('#main_menu').width()) + 'px'
		});

		$('#contact_div').show();
	})
	$('#contact_item').mouseleave(function(e){
		$('#contact_div').hide();
	})
	//================================================================================
	//filter window
	//================================================================================

	$('#filter_window').hide();
	$('#filter_controls').mouseenter(function(e){
		$('#filter_window').css({
			position: 'absolute',
//			width: $(this).width() + 'px',
			width: 130 + 'px',
			height: 147 + 'px',			
			zIndex: 6000,
			backgroundImage: "url('css-images/controls/filter_arrow_down.gif')",
			backgroundRepeat : 'no-repeat',

			backgroundPosition : '2px 0px',
			textIndent : 15 + 'px',
			paddingTop : 3 + 'px',

			left: $(this).offset().left + 'px',
			top: -130 + 'px'
		}).show();		


	})
	$('#filter_window').mouseleave(function(e){
		$('#filter_window').hide();
	});

	//================================================================================
	//browse controls
	//================================================================================
	$('#post_numbers_one').html(article_counter_one+" / "+article_max_one);
	$('#post_numbers_two').html(article_counter_two+" / "+article_max_two);
	if(article_counter_one == 1){
		$('#left_arrow_one').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'})
	}
	if(article_counter_two == 1){
		$('#left_arrow_two').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'})
	}
	
	$('#left_arrow_one').click(function() {
		if(article_counter_one > 1){
			article_counter_one--;
			$('#post_numbers_one').html(article_counter_one+" / "+article_max_one);
			$('#articles_scroller_one').animate({
				left: '+=200'
				}, 300, function() {
			});
			$('#right_arrow_one').css({backgroundImage : 'url("css-images/controls/arrow_right.gif")'});
			if(article_counter_one == 1){
				$('#left_arrow_one').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'});
			}
		}
	})
	$('#right_arrow_one').click(function() {
		if(article_counter_one < article_max_one){
			article_counter_one++;
			$('#post_numbers_one').html(article_counter_one+" / "+article_max_one);
			$('#articles_scroller_one').animate({
				left: '-=200'
				}, 300, function() {
			});
			$('#left_arrow_one').css({backgroundImage : 'url("css-images/controls/arrow_left.gif")'});			
			if(article_counter_one == article_max_one){
				$('#right_arrow_one').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'});
			}
		}
	})
	$('#left_arrow_two').click(function() {
		if(article_counter_two > 1){
			article_counter_two--;
			$('#post_numbers_two').html(article_counter_two+" / "+article_max_two);
			$('#articles_scroller_two').animate({
				left: '+=200'
				}, 300, function() {
			});
			$('#right_arrow_two').css({backgroundImage : 'url("css-images/controls/arrow_right.gif")'});			
			if(article_counter_two == 1){
				$('#left_arrow_two').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'});
			}
		}
	})
	$('#right_arrow_two').click(function() {
		if(article_counter_two < article_max_two){
			article_counter_two++;
			$('#post_numbers_two').html(article_counter_two+" / "+article_max_two);
			$('#articles_scroller_two').animate({
				left: '-=200'
				}, 300, function() {
			});
			$('#left_arrow_two').css({backgroundImage : 'url("css-images/controls/arrow_left.gif")'});
			if(article_counter_two == article_max_two){
				$('#right_arrow_two').css({backgroundImage : 'url("css-images/controls/arrow_left_disabled.gif")'});
			}
		}
	})
	
	if(window.location.hash){
		var hash = window.location.hash.replace("#", "");
		if(hash.charAt(hash.length-1) == "_"){
			get_menu_item(hash, null);
		}else{
			get_post(hash);
		}
	}else{
		if(first_post_hash != ""){
			window.location.hash = "#"+first_post_hash;
			get_post(first_post_hash);
		}
	}
});

function setNumbers(number){
	article_max_two = article_amounts_two[number];
	article_max_two > 0 ? article_counter_two = 1 : article_counter_two = 0;
	$('#post_numbers_two').html(article_counter_two+" / "+article_max_two);
	$('#articles_scroller_two').css({left : '0px'});
}


function get_post(title_safe){
	$('.menu_item_selected').removeClass('menu_item_selected').addClass('menu_item');
	$.ajax({
		type: "POST",
		url: "lib/functions.php",
//		contentType: "text/html; charset=iso-8859-1",
		data: "title_safe="+title_safe,
		success: function(result){
			location.hash = "#"+title_safe;
			var results = result.split("_GENRE_");
			$('#article_holder').html(results[0]);
			$('#article_div').css({
				backgroundImage : 'url("../css-images/colors/'+results[1]+'_voorkant.jpg")'
			});
			$('#drop_shadow_layer').css({
				backgroundImage : 'url("../css-images/colors/'+results[1]+'_schaduw.jpg")'
			});
			$('.marker_article').css({
				top: ($('#article_holder').offset().top-10) + 'px',
				left: 310 + 'px'
			});
			$(window).trigger('updateShadow');			
		}
	});
}
function get_menu_item(title_safe, el){
	$('.menu_item_selected').removeClass('menu_item_selected').addClass('menu_item');
	$(el).addClass('menu_item_selected').removeClass('menu_item');
	$.ajax({
		type: "POST",
		url: "lib/functions.php",
		data: "menu_item_safe="+title_safe,
		success: function(result){
			location.hash = "#"+title_safe;
			var results = result.split("_GENRE_");			
			$('#article_holder').html(results[0]);
			$('#drop_shadow_layer').css({
				backgroundImage : 'url("../css-images/colors/hoofdteksten_schaduw.jpg")'
			});
			$(window).trigger('updateShadow');			
		}
	});
}

