/**
 *	--- functions ---
 *
 *	@author		Alexander Velander <alexandervelander@gmail.com>
 *	@version	1.0
 *	@desc		JavaScriptfunktioner för Trappen Event.
 */
	/*
	 *	För att animera in nytt innehåll
	 */
	function animate(target, data, callback) {
		// Kolla om target finns
		if ( !$(target).length )
			throw new Error('Elementet target(' + target + ') finns inte.');
		// Kolla så callback är en funktion
		if ( callback && typeof callback != 'function' )
			throw new Error('Angedd callback(' + callback + ') finns inte.');
		// Tona ut gammalt innehåll
		$(target).fadeTo(300, 0, function() {
			// Spara ursprunglig bredd och höjd
			var origWidth = $(target).width();
			var origHeight = $(target).height();
			// Sätt nytt innehåll
			$(target).html(data);
			// Spara ny bredd och höjd
			var newWidth = $(target).width();
			var newHeight = $(target).height();
			// Sätt till gammal bredd och höjd
			$(target).width(origWidth);
			$(target).height(origHeight);
			// Animera till nya höjden
			$(target).animate({ width: newWidth, height: newHeight }, 400, function() {
				// Visa igen
				$(target).fadeTo(300, 1);
				// Sätt bredd och höjd till auto
				$(target).css('width', 'auto');
				$(target).css('height', 'auto');
			});
			// Kör callback
			if ( callback )
				callback();
		});
	}
	/*
	 *	För att animera nytt innehåll i popup
	 */
	function animatePopup(target, data, callback) {
		// Kolla om target finns
		if ( !$(target).length )
			throw new Error('Elementet target(' + target + ') finns inte.');
		// Kolla så callback är en funktion
		if ( callback && typeof callback != 'function' )
			throw new Error('Angedd callback(' + callback + ') finns inte.');
		// Tona ut gammalt innehåll
		$(target).fadeTo(300, 0, function() {
			// Spara ursprungliga värden för popup
			var origWidth	= $('#popup').width();
			var origHeight	= $('#popup').height();
			// Sätt nytt innehåll
			$(target).html(data);
			// Spara nya värden för popup
			var newWidth	= $('#popup').width();
			var newHeight	= $('#popup').height();
			// Sätt nya positioner
			var newTop				= $(document).scrollTop() + ($(window).height() / 2);
			var newMarginTop		= '-' + ((newHeight / 2) + 8) + 'px';
			var newMarginLeft		= '-' + ((newWidth / 2) + 15) + 'px';
			// Sätt till gamla värden
			$('#popup').width(origWidth);
			$('#popup').height(origHeight);
			// Animera till nya bredden och höjden
			$('#popup').animate({ width: newWidth, height: newHeight, top: newTop, marginTop: newMarginTop, marginLeft: newMarginLeft }, 400, function() {
				// Visa igen
				$(target).fadeTo(300, 1);
				// Sätt bredd och höjd till auto
				$('#popup').css('width', 'auto');
				$('#popup').css('height', 'auto');
			});
			// Kör callback
			if ( callback )
				callback();
		});
	}