$(document).ready(function(){
	$("a.tobasket.interrupt.modal").click(function(){  	        
		if(!$.cookie('_CLIENT')){
			var href = DIR_ROOT + "/login/?basket=1&modal=1&iframe&width=400&height=130";
			$(this).attr('href', href);
			return false;
		}
		var href=DIR_ROOT + "/basket/?";
		if($(this).hasClass("button")){
			$('form#catalogform').find('input').each(function(){
				if($(this).attr('disabled')){
					return;
				}
				href += $(this).attr("name") + "=" + $(this).val() + "&";
			});
		}else{
			href += "products[" + $(this).attr("name") + "]=+&";
		}
		if($.cookie('_BASKET_VIEW') == 'true'){
			href += 'modal=1&autoclose=2000&smallwindow&iframe&width=400&height=80';
		}else{
			href += 'modal=1&iframe&width=95%&height=500';
		}
		$(this).attr('href', href);
	});

	$("form#catalogform a.comp.interrupt").click(function(){
		var href=DIR_ROOT + "/comp/?";
		if($(this).hasClass("button")){
			$('form#catalogform').find('input').each(function(){
				if($(this).attr('disabled')){
					return;
				}
				href += $(this).attr("name") + "=" + $(this).val() + "&";
			});
		}else{
			href += "products[" + $(this).attr("name") + "]=+&";
		}
		if($.cookie('_COMP_VIEW') == 'comp-view-shop')
		{
			href += 'comp_view=comp-view-shop&modal=1&smallwindow&autoclose=2000&iframe&width=400&height=80';
			$.prettyPhoto.open(href, 'titles', 'descriptions');
			return false;
		}
		else if($.cookie('_COMP_VIEW') == 'comp-view-comp')
		{
			$(this).attr('target', '_self');
			href += 'comp_view=comp-view-comp';
		}
		else
		{
			$(this).attr('target', '_blank');
		}
		$(this).attr('href', href);
	});

	$("a.favourite.interrupt").click(function(){
		if(!$.cookie('_CLIENT')){
			var href = DIR_ROOT + "/login/?favourite=1&modal=1&iframe&width=400&height=130";
			$.prettyPhoto.open(href, 'titles', 'descriptions');
			return false;
		}
		var href=DIR_ROOT + "/favourite/?";
		if($(this).hasClass("button")){
			$('form#catalogform').find('input').each(function(){
				if($(this).attr('disabled')){
					return;
				}
				href += $(this).attr("name") + "=" + $(this).val() + "&";
			});
		}else{
			href += "products[" + $(this).attr("name") + "]=+&";
		}
		if($.cookie('_FAVOURITE_VIEW') == 'favourite-view-shop'){
			href += 'favourite_view=favourite-view-shop&modal=1&smallwindow&autoclose=2000&iframe&width=400&height=80';
			$.prettyPhoto.open(href, 'titles', 'descriptions');
			return false;
		}else if($.cookie('_FAVOURITE_VIEW') == 'favourite-view-favourite'){
			$(this).attr('target', '_self');
			href += 'favourite_view=favourite-view-favourite';
		}else{
			$(this).attr('target', '_blank');
		}
		$(this).attr('href', href);
	});

	$("a.favouriteblock.interrupt").click(function(){
		if(!$.cookie('_CLIENT')){
			var href = DIR_ROOT + "/login/?favourite=1&modal=1&iframe&width=400&height=130";
			$.prettyPhoto.open(href, 'titles', 'descriptions');
			return false;
		}
		if($.cookie('_FAVOURITE_VIEW') == 'favourite-view-favourite'){
			$(this).attr('target', '_self');
		}else{
			$(this).attr('target', '_blank');
		}
	});

	$("form#catalogform a.dropfavourite.interrupt").click(function(){
		var href=DIR_ROOT + "/favourite/?drop=1&";
		$('form#catalogform').find('input').each(function(){
			if($(this).attr('disabled')){
				return;
			}
			href += $(this).attr("name") + "=" + $(this).val() + "&";
		});
		$(this).attr('href', href);
	});

	$("a.modal.interrupt").click(function(){
		var href = $(this).attr("href");  		
		$.prettyPhoto.open(href, "", "");
		return false;
	});

	$('form#catalogform a.comp.interrupt').removeClass('interrupt');
	$('form#catalogform a.tobasket.interrupt.modal').removeClass('interrupt');
	$('a.favourite.interrupt').removeClass('interrupt');
	$('a.favouriteblock.interrupt').removeClass('interrupt');
	$('form#catalogform a.dropfavourite.interrupt').removeClass('interrupt');
	$("a.interrupt.modal").removeClass('interrupt');
});
