$(document).ready(function () {
	
	$('a.add_compare').click(function(event) {
				event.preventDefault();
				var hostname = window.document.location.hostname;

    			var $add = $( this ),
					id = $add.attr( 'id' ),
					url = $add.attr( 'href' ),
					tag = 'ajax-antmark',
					$img = $add.find('img'),
					action = 'add';
				
				$img.attr({ src: 'http://' + hostname + '/modules/plugins/compare/img/loader.gif' });
				$('#compare-list').css('opacity','0.5');
				
    			$.post( url, { action: action, id: id, ajax: 'true', tag: tag} ,
								function(res) {
									if(res){	
										$img.attr({ src: 'http://' + hostname + '/modules/plugins/compare/img/added.png' });
										$('#compare-list').css('opacity','1');
										$('#compareBox').html(res);
										
									}else{
										$img.attr({ src: 'http://' + hostname + '/modules/plugins/compare/img/denied.png' });
									}
      						}
    					);
	});
		
	$('a.remove_compare').click(function(event) {
			event.preventDefault();
			var hostname = window.document.location.hostname;

			var $remove = $( this ),
				id = $remove.attr( 'id' ),
				url = $remove.attr( 'href' ),
				tag = 'ajax-antmark',
				$img = $remove.find('img'),
				action = 'remove';
			
			$img.attr({ src: 'http://' + hostname + '/modules/plugins/compare/img/loader.gif' });
			$('#compare-list').css('opacity','0.5');
			
			$.post(url, { action: action, id: id, ajax: 'true', tag: tag} ,
							function(res) {
								if(res){
									$('#compare-list').html('<div class="notification information br6 png_bg"><a href="#" class="close"></a><div>'+ res + '</a></div></div>');	
								}else{
									$('#'+id).hide();
								}
								$remove.hide();
								$('#compare-list').css('opacity','1');			
						}
					);
	});
});
