$(function(){
	
  $("a[rel^='prettyPhoto']").prettyPhoto();
  
  
  $('input.mo').livequery('click', function(){
	  var input = $('input.phone');
	  var meta = input.metadata();
	  var phone = input.val();
	  var url = meta.url + '?phone=' + phone;
	  $.get(url, function(html){
		  var dialog = $(html).filter('.dialog').dialog({
			  modal: true
		  });
	  });
  });
  $('div.cornerable').livequery(function(){
    $(this).corner('round 4px').parent('div:first').css('padding', '1px').corner("round 5px");
  });
  $('div.box').livequery(function(){
    $(this).corner('round 4px').parent('div:first').css('padding', '1px').corner("round 5px cc:#e4e1dc");
  });
  
//  $('a.author').click(function(){
//		$.ajax({url: '/author', success: function(data){
//			$(data).filter('.dialog').dialog({
//				bgiframe: true,
//				resizable: false,
//				height:360,
//				modal: true,
//				title: $(data).filter('span'),
//				overlay: {
//					backgroundColor: '#000',
//					opacity: 0.5
//				},
//				buttons: {
//					'ОК': function() {
//						$(this).dialog('close');
//					}
//				}
//			});
//		}});
//		return false;
//	});
  
	$('form#searchForm input').focus(function(){
		$(this).addClass('black');
		if (this.value=='Поиск...') this.value = ''
	}).blur(function(){
		$(this).removeClass('black');
		if (this.value=='') this.value = 'Поиск...';
	});
  
  
  $('a.addcart').livequery('click', function(event){
	  	event.stopPropagation();
	  	event.preventDefault();
		$.ajax({url: $(this).attr('href'), success: function(html){
			$(html).filter("#dialog").dialog({
				bgiframe: true,
				resizable: false,
				height:160,
				modal: true,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'ОК': function() {
						$(this).dialog('close');
					}
				}
			});
			$("#cartInfo").html($(html).filter("#informationText"));
		}});
		return false;
	});
});


var attachCartEvents = function(){
	$('a.cartitem').click(function(){
		if ($(this).attr('qty')==1){
			if (!confirm('Вы желаете удалить данный продукт из корзины?')) return false;
		}	
		$.ajax({url: $(this).attr('href')+"?rnd="+Math.random(), success: function(html){
			$("#cartInfo").html($(html).filter("#informationText"));
			$("#cartData").html($(html).filter("#itemsInfo"));
		}});
		return false;
	});
}

