jQuery(function() {
    // Menu toggle for the container links
    jQuery(".menuLink.containerLink").click(function() {
        var nextElement = jQuery(this).next();

        if (jQuery(nextElement).hasClass('menuContainer')) {
            jQuery(nextElement).slideToggle();
        } else {
            if (jQuery(nextElement).next().hasClass('menuContainer')) {
                jQuery(nextElement).next().slideToggle();
            }
        }

        return false;
    });
	
    jQuery('img', '#innerContent').click(function(){
        if(!jQuery(this).hasClass('skipImageDialog')) {
            showImage(this);
        }
    });
});

function showImage(element){
    $("#imageDialog").html('Ladevorgang...');
    $("#imageDialog").dialog({
        title: 'Bildansicht',
        modal: true
    });		
	
    var imagePathSmall = jQuery(element).attr('src');
    var imagePathBig   = imagePathSmall.replace(/small/i, "big");

    var dialogImage = new Image();
	
    dialogImage.onload = function() {
        $("#imageDialog").remove();
		
        $("body").prepend("<div id='imageDialog'></div>");
        $("#imageDialog").html(this);
		
        $("#imageDialog").dialog({
            title: 'Bildansicht',
            modal: true,
            width: this.width + 15 + 'px',
            close: function(event, ui) {
                $("#imageDialog").remove();
                $("body").prepend("<div id='imageDialog'></div>");
            }
        });
    };
	
    dialogImage.src = imagePathBig;
}
