$(document).ready(function() 
{
	activate_buttons();
});

function activate_buttons()
{	
	$( "#header" ).children(".btn").unbind().mouseover(function() {
		$(this).addClass("hover");
	}).mouseout(function() {
		$(this).removeClass("hover");
	});

	$('.lightbox a').lightBox({
		imageLoading:	base_url+'bartnelissen/images/lightbox/ajax-loader.gif',
		imageBtnPrev:	base_url+'bartnelissen/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:	base_url+'bartnelissen/images/lightbox/lightbox-btn-next.gif',
		imageBtnClose:	base_url+'bartnelissen/images/lightbox/lightbox-btn-close.gif',
		imageBlank:		base_url+'bartnelissen/images/lightbox/lightbox-blank.gif'
	});
	
	$( ".mouseover" ).unbind().mouseover(function() {
		$(this).css({"background-position":"bottom"});
	}).mouseout(function() {
		$(this).css({"background-position":"top"});
	}).mouseup(function() {
		$(this).css({"background-position":"top"});
	});
	
	$( ".share_btn,.share_btn_post" ).mouseup(function() {
		var post = $(this).parent().parent().parent();
		$( this ).css({"background-position":"top"});
		var show_big_buttons = false;
		if ( $( post ).children( '.info' ).hasClass( 'tekstrechts' ) || $( post ).children( '.info' ).hasClass( 'tekstlinks' ) )
		{
			if ( $( post ).children( '.info' ).width() < 400 )
			{
				if ( $( post ).children( '.share' ).length > 0 )
				{
					if ( $( post ).children( '.share' ).height() <= $( post ).children( '.info' ).height() ) show_big_buttons = true;
				}
			}
		}
		if ( show_big_buttons )
		{
			// Line on the correct side //
			$( post ).children( '.share' ).css( { 'border':'0px'} );
			if ( $( post ).children( '.info' ).hasClass( 'tekstrechts' ) )
			{ $( post ).children( '.share' ).css( { 'border-left':'1px solid #fff'} );
			} else { $( post ).children( '.share' ).css( { 'border-right':'1px solid #fff'} ); }
			// Share slider //
			var pos = $( post ).children( '.info' ).offset();
			var parent_pos = $( post ).offset();
			
			// Default values //
			var original_left = pos.left-parent_pos.left;
			var original_top = pos.top-parent_pos.top;
			var original_height = $( post ).children( '.info' ).height()-24;
			
			if ( $( post ).children( '.share' ).css( 'opacity' ) == '0')
			{
				var bg_left = pos.left-parent_pos.left-90;
				var bg_width = $( post ).children( '.info' ).width()+90;
				var info_left = pos.left-parent_pos.left-90;
				var share_left = 692;
				var share_animate_to = 598;
				var share_opacity = 1;
				if ( $( post ).children( '.info' ).hasClass( 'tekstlinks' ) )
				{
					info_left = pos.left-parent_pos.left+90;
					bg_left = pos.left-parent_pos.left;
					share_left = -94;
					share_animate_to = 0;
				}
			}
			else
			{
				bg_left = pos.left-parent_pos.left+90;
				info_left = pos.left-parent_pos.left+90;
				bg_width = $( post ).children( '.info' ).width();
				share_left = $( post ).children( '.share' ).css('left');
				share_animate_to = 692;
				share_opacity = 0;
				if ( $( post ).children( '.info' ).hasClass( 'tekstlinks' ) )
				{
					info_left = 2;
					bg_left = 2;
					share_animate_to = -94;
				}
			}
			$( post ).children( '.background' ).animate( {
				"left"	: bg_left,
				"width" : bg_width
			},250);
			$( post ).children( '.info' ).css({
				"left"	: original_left
			}).animate( {
				"left"	: info_left
			},250);
			$( post ).children( '.share' ).css({
				"top"	: original_top,
				"height": original_height,
				"left"	: share_left,
				"display": "block"
			}).animate({
				"left"	: share_animate_to,
				"opacity": share_opacity
			},250);
		
		}
		else
		{
			$( this ).parent().children( '.share_buttons' ).animate({width:'toggle'},150);
		}
		
	});
		
	$( ".back_btn" ).mouseup(function() {
		if ( direct_url )
		{
			window.location = base_url;
		}
		else
		{
			history.go(-1);
		}	
		return false;
	});
	
	if ( inanimate )
	{
		var top = 0;
		if ( $( '#content' ).find( '.previous_page' ).length > 0 && $( '#content' ).find( '.previous_page' ).html() != '')
		{
			var last_page = $( '#content' ).find( '.previous_page' ).html().replace("/", "_");
			if ( $( '#content' ).children( "#"+last_page ).length > 0 ) { 
				if ( $( '#content' ).children( "#"+last_page ).height() > 80 )
				{
					top = $( '#content' ).children( "#"+last_page ).offset().top-(($(window).height()-$( '#content' ).children( "#"+last_page ).height())*.5);
				}
			}
		}
		var scroll_speed = Math.round( Math.max( 240, Math.abs( top - $(window).scrollTop() ) / 8 ) );
		$('html,body').stop(true,false).animate({scrollTop: top},{'duration':scroll_speed});
		
		$.each( $( '#header' ).find( 'a' ), function() {
			$( this ).css( {'color':''} );
			var href = $( this ).attr('href').split('/');
			if ( href[href.length-1] != "") 
			{
				var selected = $( '#content' ).find('.selected_menu_items:contains(",en/' + href[href.length-1] +',")');
				if ( $( selected ).length > 0 ) $( this ).css( {'color':'#20abcd'} );
			}
		});
	}
	
}

