
$('document').ready(function() {

	$('input.amount').keyup(function() {

		$('#cart').html('<div style="padding: 10px 0px 0px 40px; color: red;">Uppdaterar...</div>');

		amount = $(this).val();
		row = $(this).attr('id');
		
		if(amount == 0 && amount != ''){
			alert("Fel antal, vill ni ta bort produkter tryck på Ta bort!");
		}

		$.post('xmlhttp/changeamount.php', { row: row, amount: amount }, function (data) {

			if(data != 'error'){
				list = data.split('||');

				$('input#'+row).attr('value', list[2]);
				$('#tot').html(list[0]);
				$('#tot_amount').html(list[1]);
			}

			$.get('xmlhttp/cart.php', { ajax: 1 }, function (html) {
				$('#cart').html(html);
			});
		});

		$('#updatetext').attr('value', 'Din kundvagn har ändrats');
	});

	$('#bivForm').one("submit", function() {

		$.get("xmlhttp/subshopuser.php", function(data){
			$('#bivUser').attr('value', data);
			$('#bivForm').submit();
		});

		return false;
	});
});


function showMenu(id){
	$('#'+id).toggle();

	display = $('#'+id).css('display');
	if(display == 'block'){
		$('span.'+id).attr('style','background: url(static/images/arrow_on.gif) 13px 18px no-repeat;');
	}else{
		$('span.'+id).attr('style','background: url(static/images/arrow.gif) 15px 15px no-repeat;');
	}
}

//changes main image on product page
function changeProductMainPicture( filename, imageID, pos, totalthumbs, productID, altText) {
	
	var data = '<center><img alt="'+altText+'" align="center" src="webimages/' + filename + '" border="0" alt="" id="productImageLarge"></center>';

	$('.productimage').html(data);

	$('#product_pdf').attr('href', 'productpdf.php?productID='+productID+'&imageID='+imageID);

	resetThumbnails( totalthumbs );
	activateThumbnail( pos, true );
}

//resets class names for thumbnails on product page
function resetThumbnails( totalthumbs ) {
	for (i=0; i<totalthumbs; i++) {
		activateThumbnail( i, false );
	}
}

//sets class name for a specific thumbnail on product page
function activateThumbnail( pos, mode ) {
	
	var thumbnail = document.getElementById('thumbnailBox' + pos);
	var imgThumbnail = document.getElementById('thumbnailImage' + pos);
	
	
	if (mode) {
		thumbnail.className='productImageThumbnailBox-selected';
		imgThumbnail.className='productImageThumbnail-selected';
	}
	else {
		thumbnail.className='productImageThumbnailBox';
		imgThumbnail.className='productImageThumbnail';
	}
}

function custompop(url, width, height, status, menu) {
   win = window.open(url, 'profile_popup', 'toolbar=no,location=no,directories=no,status=' + status +  ',menubar=' + menu + ',scrollbars=yes,resizable=yes,copyhistory=no,width=' + width + ',height=' + height);
   win.focus();
}