String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

$(document).ready(function() {
	// Add hover effects to image list
	$(".content-view-full .modell .bilder .bilde").hover(
		function () {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);
	
	// add navigation
	$(".content-view-full .modell .modell-image-nav .bildegruppe").click(function() {
		var groupId = $(".group-id", this).attr("value");
		$(".bildegrupper").scrollTo("#" + groupId, 400);
	});
	
	// Add image selection
	$(".content-view-full .modell .bilder .bilde").click(function(e) {
		$(".content-view-full .modell .bilder .bilde.selected").removeClass("selected");
		$(this).addClass("selected");
		
		var image = $(".target_image", this).attr("value");
		var caption_header = $(".attribute-header", this).text();
		var caption = $(".attribute-content", this).text().trim();
		if(!caption) {
			caption = $('.attribute-description').text().trim();
		}		
		
		$("#showroom .bilde img").attr("src", image);
		$("#showroom .bilde .caption h3").text(caption_header);
		$("#showroom .bilde .caption .attribute-content").text(caption);		
	});
	
	$($(".content-view-full .modell .bilder .bilde")[0]).click();
});
