$(document).ready(function(){
       
// korzina
	$('#korzina_r_button input').click(function(){
	 if($('#korzina').width()<'319'){
	   $('#korzina').animate({width : '319px'}, 400)
}else{
	   $('#korzina').animate({width : '58px'}, 600);
}
	 return false;
  });
	// END korzina
$('.messages-section  .message-item:first').addClass('show');
	

$('#content img').parents('a').each(function(){
	url = $(this).attr("href");
	var regV = /\.jpg|\.png|\.gif/gi;     // шаблон
		var result = url.match(regV);  // поиск шаблона в юрл
	 
	// вывод результата
	if (result) {
	    $(this).addClass('lightbox');
		$('.lightbox').lightBox();
	} 
		
});



var countRev = 1;
var maxRev = $('.message-item').length;

$('#slider img').click(function(){
	document.location.href=$(this).attr('alt');
});

$('.next-otziv').click(function(){
	if(countRev < maxRev) { $('.message-item.show').removeClass('show').next('.message-item').addClass('show');  countRev++;}
	return false;
});
$('.prev-otziv').click(function(){
	if(countRev > 1) {$('.message-item.show').removeClass('show').prev('.message-item').addClass('show');  countRev--;}
	return false;
});
	
refreshBindBasket();
 
  $('.zakaz_button').click(function(){
	AddToBasket($(this).attr('href'));
	if($('#korzina').width()<'319'){
	   $('#korzina').animate({width : '319px'}, 400)
	}	
	return false;
  });
  
  ////аякс добавление в корзину
  function AddToBasket(id) {
		$.post('/menu/add_to_basket.php',{'id':id},function(data){
		refreshBasket();		
	});
  }
  function DelOutBasket(id,qw) {
		$.post('/menu/add_to_basket.php',{'id':id,'act':'del','qw':qw},function(data){
		refreshBasket();		
	});
  }
  
  ////обновление обработчика кликов
  function refreshBindBasket() {
	 $('a.plus').each(function(){
		  $(this).bind('click',function(){
				AddToBasket($(this).attr('href'));
				if($(this).attr('title') == 'pizzaitem'){AddToBasket('148');}
				return false;	
		  });
	  });
	  $('a.minus').each(function(){
		  $(this).bind('click',function(){
		
				DelOutBasket($(this).attr('href'),$(this).attr('alt'));
				if($(this).attr('title') == 'pizzaitem'){ DelOutBasket($('.boxpizzadel').attr('title'),$('.boxpizzadel').attr('alt'));}
				return false;	
		  });
	  });
  }
  ////обновление корзины
  function refreshBasket() {
	$.post('/',function(data){
	//	alert($(data).find('#korzina_bg table').html());
		$('#korzina_bg table').html($(data).find('#korzina_bg table').html());
		$('#top_group_text').html($(data).find('#top_group_text').html());
		
		refreshBindBasket();
	});
  }	

	
	
	
	// menu
	$('#menu_r_button input').click(function(){
	 if($('#menu').width()<'231'){
	   $('#menu').animate({width : '231px'}, 400)
  }else{
	   $('#menu').animate({width : '58px'}, 600);
   }
	 return false;
  });
	// END menu
	
	// online

	$('#online_l_button input').click(function(){
	 if($('#online').width()<'295'){
	   $('#online').animate({width : '295px'}, 600)

}else{
	   $('#online').animate({width : '52px'}, 600);

   }
	 return false;
  });
	// END online

	// Верхняя менюшка
	$("#header_menu td a:contains(Меню)").hover(function(){
		$('.ddmenu').show("fast");
		},function(){
		$('.ddmenu').hide("fast");
	});
	$(".ddmenu").hover(function(){
	},
	function (){
		$('.ddmenu').toggle("fast");
	}
	);

// Тесто
$('#horizontal li  ul  li:last').addClass('end');
$('#horizontal a:contains(Меню)').attr('href','#');

	$('.testo_text').click(function(){
	    $(this).next('.testo_slide').animate({right : '125px'}, 600);
		
	});
     $('.testo_text').click(function(){
	    
		if($('.testo_slide').attr('right' == '125')){
	      $(this).next('.testo_slide').animate({right : '1px'}, 600);
	}
		return false;
	});
	// END Тесто
});

$(document).ready(function(){

  // LeftMenu
  $('#side .lmenu ul li').hover(function(){
    $(this).children('.submenu').show();
  },function(){
    $(this).children('.submenu').hide();
  });
  // END LeftMenu
  
  // Top Menu 
  $('#menu ul li').hover(function(){
    $(this).addClass('hover');
  },function(){
    $(this).removeClass('hover');
  });
  // END Top Menu
  
  // Search
  $("input.inpt_txt_search").click(function(){
    var value = $(this).val();
    if(value == "Поиск"){$(this).val("");}
  });
  $("input.inpt_txt_search").blur(function(){
    var value = $(this).val();
    if(value == ""){$(this).val("Поиск");}
  });
  // END Search
  
  // Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");	
	});
  // END Expand Panel	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});
  // END Collapse Panel		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});
  // END Switch buttons from "Log In | Register" to "Close Panel" on click	
  
  // Message Box
  $('a.messagebox').click(function(){
    var elem = $(window);
    var scrollTop = $(window).scrollTop();
    scrollTop = scrollTop+150;
    var ewidth = elem.width();
    var rwidth = ewidth/3; 
    $('.complain').fadeIn(400);
    var css_s = {
        'position' : 'absolute',
        'top' : scrollTop+'px',
        'left' : rwidth+'px',
        'background' : '#fff',
        'z-index' : '9999'
    };
    $('.complain').css(css_s);
    return false;
  });
  $('.facebox_overlay').click(function(){
    $('.complain').fadeOut(400);
  }); 
  $('.complain .close').click(function(){
    $('.complain').fadeOut(400);
    return false;
  }); 
    
  // Scroller
  $jScroller.add('#scrl','#scrl_cont','left',2, true);
  $jScroller.start();
  // END Scroller
  
  $("a[rel=fancy]").fancybox({
  	'overlayShow'	: true,
  	'opacity'		: true,
  	'transitionIn'	: 'elastic',
  	'transitionOut'	: 'elastic'
  });
  
	function formatText(index, panel) {
		return index + "";
	};
	$(function () {
		$('.channel').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 600,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",                // Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});
		$("#slide-jump").click(function(){
			$('.channel').anythingSlider(6);
		});
	});
	var panel = $('.thumbNav a.cur').text();
	$('.anons li[rel=panel-'+panel+']').show('400');
	$('.thumbNav a').click(function(){
		$('.anons li').hide();
		var panel = $(this).text();
		$('.anons li[rel=panel-'+panel+']').show('400');
	});
	// Опрос
	$('.otvets .open a').click(function(){
		if($(this).parent("div").parent("div").parent("div").children(".otvet").is(":hidden")){
			$(this).parent("div").parent("div").parent("div").children(".otvet").slideDown("slow");
			$(this).parent("div").toggleClass("open");
			$(this).parent("div").toggleClass("open_open");
			$(this).html("Скрыть");
		}else{
			$(this).parent("div").parent("div").parent("div").children(".otvet").slideUp("slow");
			$(this).parent("div").toggleClass("open");
			$(this).parent("div").toggleClass("open_open");
			$(this).html("Скрыть");
		}
	});
	$('#opros .but').click(function(){
		var file_link=$("#opros").attr("action");
		var vopros=$("#opros input[name='vopros']").val();
		var otvet=$("#opros input[name='otv']:checked").val();
		
     	$.post(file_link+"&vopros="+vopros+"&otvet="+otvet, {}, function(html){
     		$("#opros").html(html);
    	});
		return false;
	});
	// END Опрос

	// Phones Split
	$('#content .right span.phone div').each(function(){
		var txt = $(this).html();
		var newtxt = txt.replace(/(\w+)\s(\S+)/, "($1) <b>$2</b>");
		//alert(newtxt);
		$('#content .right span.phone').addClass('edited')
		$(this).html(newtxt);
	});
	if($('#content .right span.phone').attr('class')!='phone edited'){
	$('#content .right span.phone').each(function(index){
		//alert('11');
		var txt = $(this).text();
		var newtxt = txt.replace(/(\w+)\s(\S+)/, "($1) <b>$2</b>");
		//alert(newtxt);
		$(this).html(newtxt);
	});}
	// END Phones Split
	
	
});
