$(document).ready(function(){


	initMultiImage();


});


function initMultiImage() {
	$('.multiImage').each(function() {
		var theDiv = $(this);
		var elements = $.trim($(this).text()).split("#");
		
		var imgContainer = $('<div />').addClass('imgContainer');			
	
		$(elements).each(function(index, obj) {
			var e = obj.split(";");
			$('<span />')
			.html("<a id='IMG_" + e[0] + "' href='/admin/common/getImg.asp?FileID=" + e[0] + "' title='" + e[1] + "' class='colorbox' rel='produktbilder'><img src='/admin/common/GetImg.asp?FileID=" + e[0] + "&amp;xsize=224' /></a><span class='caption'>" + e[1] + "</span>"
			)
			.attr('class', 'img_' + index)
			.appendTo(imgContainer);//.insertBefore(theDiv);
		});
		
		imgContainer.insertBefore(theDiv);
	});
}



function ShowImg(ID)
{
	window.open('/admin/common/ShowImage.asp?FileID=' + ID + '&NoProps=True', 'Image' + ID, 'height=150,width=150,resizable=no,menubar=no,location=no,scrollbars=no,status=no,toolbar=no')
}

function ShowItemImage(ItemId, ImageNr)
{
	window.open('/pages/ItemImageCaption.aspx?ItemId=' + ItemId + '&ImageNr=' + ImageNr, 'ItemImage' + ItemId, 'height=500,width=720,resizable=yes,menubar=no,location=no,scrollbars=yes,status=no,toolbar=no')
}

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display ? "" : "block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display ? "" : "block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display ? "" : "block";
	}
}

function toggleMultipleLayers(layers)
{
	var arr = layers.split(",");
	for (var i = 0; i < arr.length; i++)
	{
		toggleLayer(trim(arr[i]));
	}
}


// Removes leading whitespaces
function lTrim(value)
{
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function rTrim(value)
{
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim(value)
{
	return lTrim(rTrim(value));
}
