$('document').ready( function () {
	/* INIT */

	// Hide confirm-overlay div...
	$('div.confirm-overlay').hide();
	$('div.confirm-alert').hide();

	$('a#confirm-overlay').click(function () {
		$('div.confirm-overlay').hide();
		$('div.confirm-alert').hide();
	});
});

function imgSwap(oImg) {
	var strOver  = "_on"; // image to be used with mouse over
	var strOff = "_off";  // normal image
	var strImg = oImg.src;
	if (strImg.indexOf(strOver) != -1) {
		oImg.src = strImg.replace(strOver,strOff);
	} else {
		oImg.src = strImg.replace(strOff,strOver);
	}
}

function changeProductMainPicture( filename, imageID, pos, totalthumbs ) {
	var ih = '<a href="productimage.php?imageID=' + imageID + '" onclick="return popup(this, \'prodimage\', 420, 420, \'no\', \'no\', \'yes\')"><img alt="Klicka f&ouml;r st&ouml;rre bild" align="center" src="webimages/' + filename + '" border="0" id="productImageLarg class="productimage"></a>';

	var largeImageTD = document.getElementById('productImageLargeTD');
	largeImageTD.innerHTML = ih;

	resetThumbnails( totalthumbs );
	activateThumbnail( pos, true );
}

function resetThumbnails( totalthumbs ) {
	for (i=0; i<totalthumbs; i++) {
		activateThumbnail( i, false );
	}
}

function activateThumbnail( pos, mode ) {
	var thumbnail = document.getElementById('thumbnailBox' + pos);
	var imgThumbnail = document.getElementById('thumbnailImage' + pos);

	if (mode) {
		thumbnail.className='productImageThumbnail-selected';
		imgThumbnail.className='productImageThumbnail-selected';
	} else {
		thumbnail.className='productImageThumbnail';
		imgThumbnail.className='productImageThumbnail';
	}
}


/* Output email-addess */
function safemail (part1, part2, text) {
	var email = part1 +'@'+ part2;

	if (! text) text = email;

	document.write('<a href="mailto:'+ email +'">'+ text +'</a>');
}

function popup (url, name, width, height, status, menu, resizable) {
	var prop = 'toolbar=no,location=no,directories=no,scrollbars=yes,copyhistory=no,';
	prop += 'status='+ (status ? 'yes' : 'no') +',';
	prop += 'resizable='+ (resizable ? resizable : 'yes') +',';
	prop += 'menu='+ (menu ? 'yes' : 'no') +',';
	prop += 'width='+ (width ? width : 500) +',';
	prop += 'height='+ (height ? height : 400);

	var win = window.open(typeof(url) == 'string' ? url : url.href, name, prop);

	win.focus();
	
	return false;
}

function freshpopup (url, width, height, status, menu, resizable) {
	var time = new Date();
	var name = Math.floor((Math.random() * Math.round(time.getTime())));

	var prop = 'toolbar=no,location=no,directories=no,scrollbars=yes,copyhistory=no,';
	prop += 'status='+ (status ? 'yes' : 'no') +',';
	prop += 'resizable='+ (resizable ? resizable : 'yes') + ',';
	prop += 'menu='+ (menu ? 'yes' : 'no') +',';
	prop += 'width='+ (width ? width : 500) +',';
	prop += 'height='+ (height ? height : 400);

	var win = window.open(typeof(url) == 'string' ? url : url.href, name, prop);
	win.focus();
	
	return false;
}

function setCookie (key, value) {
	document.cookie = key + "=" + value + "; path=/";
}

function getCookie (key) {
	var cookie = document.cookie.split(';');
	var name = key + "=";

	for(var i = 0; i < cookie.length; ++i) {
		var c = cookie[i];

		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length);
		}

		if (c.indexOf(name) == 0) {
			return c.substring(name.length, c.length);
		}
	}

	return null;
}

function delCookie (key) {
	document.cookie = key + "=; expires=-86400000; path=/";
}


function selectToUrl (selObj) {
	if (selObj && selObj.value) {
		document.location.href = selObj.value;
	}

	return false;
}

