$(document).ready(function() {
	if($('#cmpTable')[0] != null){
		refreshTable();
	}
	if($('#cmpBanner p span.hideComparison')[0] != null){
		$('#cmpBanner').attr('style','display:none');
	}
});

function addProductToCmpTable(id){
	submitAjaxem(
		{'url' : 'exec.php', 'command' : 'item:compareAdd', 'add_id' : id},
		null, 
		function(resp){
	     	var tekst = resp.newText;
			var div = resp.newDiv;
			$('#cmpBanner p').html(tekst);
			$('#cmpBanner div#cmpGoTo').html(div);
			$('#cmpBanner').attr('style','display:block');
		},
		'popup',
		{popupHost:'addItemToComparisonTableLink'+id, duration:1500}
	);
}

function delProductFromCmpTable(id){
	submitAjaxem(
		{'url' : 'exec.php', 'command' : 'item:compareDel', 'del_id' : id},
		null, 
		function(resp){
			$('#cmpTable .product'+id).remove();
			refreshTable();
		},
		'blank'
	);
}

function deleteAllProductsFromCmpTable(){
	submitAjaxem(
		{'url' : 'exec.php', 'command' : 'item:compareDelAll' },
		null, 
		function(resp){
			$('#cmpBanner').attr('style','visibility:hidden; position:absolute;');
		},
		'popup',
		{popupHost:'cmpBanner', duration:1500}
	);
}

function refreshTable(){
	$('#cmpTable').width($('#cmpTable th').length * $('#cmpTable th').css('width'));
}

