/* VARS */

var IS_LIVE = true;
var IS_OPEN = false;

var position = undefined;
var padding_bottom = undefined;
var height = 0;

var currentElement = undefined;
var currentArticle = undefined;
var currentText = undefined;
var currentImage = undefined;

/* FUNCTIONS */

function setMain() {
	
/*	
	position = $("#content").position();
	padding_bottom = parseInt( $("#content").css("padding-bottom").substr(0, 2) );
	height = parseInt( $("#content").height() + position.top + padding_bottom );
*/
	
//	console.log( top );
//	console.log( padding_bottom );
//	console.log( height );
//	console.log( height + " - " + $(window).height() );

	/*  */

//	console.log( $(window).height() );
	
	if( height > $(window).height() ) {
		
		
	
	} else {
	
		$("#main").css("height", $(window).height() + "px");
	
	}
  	
}

function setButtons() {

	$(".button").hover(
	
		function() {
		
			$(this).find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_over.png");
			
		}, 
		function() {
		
			$(this).find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_out.png");
			
		}

	);
	
	//
	
	$(".button_up").hover(
	
		function() {
		
			$(this).find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_up_over.png");
			
		}, 
		function() {
		
			$(this).find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_up_out.png");
			
		}

	);
	
	$(".button_up").click( function() {
		
		$(this).parent().parent().parent().find(".text").slideToggle( 500 );
		
		//
		
		if( $(this).parent().parent().parent().attr("id") == "headlines" ) {

			IS_OPEN = false;

		}
		
	} );

}

function setArticles() {

	$(".article").find("a").hover(
	
		function() {
		
			$(this).parent().find(".button").find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_over.png");			
			
		}, 
		function() {
		
			$(this).parent().find(".button").find("img").attr("src", "http://joswillemse.nl//uploads/development/arrow_out.png");
			
		}

	);
	
	$(".article").find("a").click( function() {
		
		if( $(this).parent().find(".text").length != 0 ) {
		
			$(this).parent().find(".text").slideToggle( 500 );
		
		} else {
			
			if( !IS_OPEN ) {
			
				currentArticle = $(this).parent().attr("id");
				currentElement = $(this).parent().parent().parent().find(".text");
				
				/*  */
				
				currentElement.find(".text_extra").html("");
				currentElement.find(".image").html("");
	
				//
				
				currentText = $(this).parent().find(".hidden").find(".text_extra").html();
				currentImage = $(this).parent().find(".hidden").find(".image").html();
				
				//
				
				currentElement.find(".text_extra").append( currentText );
				currentElement.find(".image").append( currentImage );
				
				/*  */
				
				$(this).parent().parent().parent().find(".text").slideToggle( 500, displayContent );
				
				/*  */
				
				IS_OPEN = true;
			
			} else {
			
				if( currentArticle != undefined && $(this).parent().attr("id") != currentArticle ) {
				
					currentArticle = $(this).parent().attr("id");					
					currentElement = $(this).parent().parent().parent().find(".text");
					
					/*  */
				
					$(this).parent().parent().parent().find(".text").slideToggle( 500, toggleComplete );
				
				} else {
				
					$(this).parent().parent().parent().find(".text").slideToggle( 500 );
					
					//
					
					IS_OPEN = false;
				
				}
			
			}
			
		}
	
	} );
	
}

function toggleComplete() {

//	console.log( currentElement );	
//	console.log( currentArticle );
	
	/*  */
	
	currentElement.find(".text_extra").html("");
	currentElement.find(".image").html("");

	//
	
	currentText = $("#" + currentArticle).find(".hidden").find(".text_extra").html();
	currentImage = $("#" + currentArticle).find(".hidden").find(".image").html();
	
	//
	
	currentElement.find(".text_extra").append( currentText );
	currentElement.find(".image").append( currentImage );
				
	/*  */
	
	currentElement.slideToggle( 500, displayContent );
	
	/*  */
	
	IS_OPEN = true;
	
}

function displayContent() {
	
//	console.log( currentElement );
	
}


/* INIT */

$(document).ready( function() {

	setMain();
	
	setButtons();
	
	setArticles();
	
} );

$(window).load( function() {

	
	
} );

$(window).resize( function() {setMain();} );

