

/**
 * Shows the image carousel.
 */
function showImageCarousel() {
	var images = jQuery(".bildekarusell img");
	if (images.length > 0) {
		var image = images[randomNumber(images.length)];
		//jQuery(image).removeClass("hidden");
		jQuery(image).fadeIn('slow');
		jQuery(image).wait();
		jQuery(image).fadeOut('slow',showImageCarousel);
		
	}
}

    jQuery.fn.wait = function(time, type) {
        time = time || 7000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                jQuery(self).dequeue();
            }, time);
        });
    };



/**
 * Returns a random number. 
 * @param maxValue The max value of the random number to generate. 
 */
function randomNumber(maxValue) {
	return Math.floor(Math.random() * maxValue);
}


/**
 * Toggles edit mode.
 */
function editmode() {
	var href = window.location.href;
	if (href.indexOf("p_edit=true") != -1) {
		window.location.href = href.replace("true", "false");
	} else if (href.indexOf("p_edit=false") != -1) {
		window.location.href = href.replace("false", "true");
	} else if (href.indexOf("?") != -1) {
		window.location.href = href + "&p_edit=true";
	} else {
		window.location.href = href + "?p_edit=true";
	}
}


/**
 * Sets the height of the bottom left column according to the height of the bottom right column.
 */
function setLeftColumnHeight() {
	var leftHeight = $("div.region_bottom div.region_left").height();
	var rightHeight = $("div.region_bottom div.region_center_full").height();
	if (leftHeight < rightHeight) {
		// the nyhetsListe has 10px of padding
		$("div.region_bottom div.region_left div.nyhetsListeForside").height(rightHeight - 10);
	}
}

/**
 * Displays textoverlay on project overview map.
 */
function showDetails(element) {
	var id = '#'+element+' .text';
	var iddot = '#'+element;
       var textoverlay = '#textoverlay';
	jQuery('#textoverlay').html('<div class="float_right" onclick="javascript:jQuery(textoverlay).hide();" style="cursor:pointer;text-decoration:underline;color:#012774;">Lukk</div>' + jQuery(id).html());
	var top = jQuery(iddot).css('top');
	var left = jQuery(iddot).css('left');
	jQuery('#textoverlay').css({'top':top,'left':left,'postition':'absolute'});
	jQuery('#textoverlay').show();
}
