// JavaScript Document

$(document).ready(function(){
	
	//yandex map for contacts					   
	if (document.getElementById("YMapsID")) 
		{
		var map = new YMaps.Map(document.getElementById("YMapsID"));
		map.setCenter(new YMaps.GeoPoint(37.627349, 55.654421), 13);
		var placemark = new YMaps.Placemark(map.getCenter());
			placemark.name = "Наш адрес";
			placemark.description = "115201, г. Москва, Каширский проезд. д.23 ";
			map.addOverlay(placemark);
		YMaps.Events.observe(placemark, placemark.Events.MouseEnter, function (obj) {
					obj.setStyle("default#greenPoint");
				});
		YMaps.Events.observe(placemark, placemark.Events.MouseLeave, function (obj) {
					obj.setStyle();
				});
		}
	
	
	function cssmenuhover(){        
		if(!document.getElementById("cssmenu"))                return;       
		var lis = document.getElementById("cssmenu").getElementsByTagName("LI");        
		for (var i=0;i<lis.length;i++)        
			{                
			lis[i].onmouseover=function(){this.className+=" iehover";}                
			lis[i].onmouseout=function() {this.className=this.className.replace(new RegExp(" iehover\\b"), "");}        
			}
		}
	if (window.attachEvent)        window.attachEvent("onload", cssmenuhover);
	
	// Right navy
	$('ul.right_navy li a').click(function(){
		if ( $(this).next('ul').length > 0 ) {
			$(this).parent('li').toggleClass('active').siblings().removeClass('active');
			return false;
		} else {
			return true;
		}
	})
	
	
	// Right promo blocks
	$('div.clickable_block').click(function(){
		window.location = $(this).find('a').attr('href');
		return false;
	})
	/*
	// Colorbox
	if ( $('.price_popup_btn').length > 0 ) {
		$('.price_popup_btn').colorbox({inline: true, href:"#price_popup", transition: "none"});
	}
	*/
	
	$('.form-bottle').each(function (i, form) {
        $(form).submit(function () {
            var totalQty = 0;
            $(form).find('.buy_block_2 input').each(function () {
                totalQty += parseInt($(this).val());
            });

            if (totalQty > 0) {
                return true;
            }
            
            $.colorbox({
                transition: 'none',
                width: 240,
                html: $(form).clone().prepend('<div class="text_in_price_popup">Укажите количество товара.</div>'),
                onComplete: function() {
                    $('#cboxContent form').submit(function () {
                        $(this).find('.buy_block_2 input').each(function () {
                            totalQty += parseInt($(this).val());
                        }); 
                        
                        if (totalQty > 0) {
                            return true;
                        }  
                        
                        $(this).children('.text_in_price_popup').css('color', '#ae0000');
                        return false;                     
                    });
                }
            });
            
            return false;	
        });
	});
	
	//обратный звонок
	
	
	// дополнительные фото
	
		$('#addiphoto1').click(function() {
			photo=$(this).clone();
			photo.attr('width','149');
			photo.attr('height','250');
			
		  $.colorbox({
                transition: 'none',
                width: 200,
                html: photo
            });
	});
		$('#addiphoto2').click(function() {
		 photo=$(this).clone();
			photo.attr('width','149');
			photo.attr('height','250');
			
		  $.colorbox({
                transition: 'none',
                width: 200,
                html: photo
            });
	});
		$('#addiphoto3').click(function() {
		 photo=$(this).clone();
		photo.attr('width','149');
			photo.attr('height','250');
		  $.colorbox({
                transition: 'none',
                width: 200,
                html:photo
            });
	});
	
	$('#backcall').click(function() {
		  $.colorbox({
                transition: 'none',
                width: 540,
                html: '<div class="text_in_price_popup"><h1>Заказать звонок</h1><form action="/contacts/feedback.html" id="backcall_form" method="post">    <input type="hidden" name="posting" value="1">    <ul class="list_type_1">        <li><div class="field_name">Ваше имя:</div><div class="field_option rc6 styled_block"><input name="f_Name" type="text" value=""></div><div class="cb"></div></li>        <li><div class="field_name">Контактный телефон:</div><div class="field_option"><div class="phone_prefix fl">+ 7</div><div class="phone_full rc6 styled_block fr"><input name="f_Phone" type="text" value=""></div></div><div class="cb"></div></li><li><div class="field_name">Сообщение:</div><div class="field_option rc6 styled_block"><textarea name="f_Message" cols="" rows=""></textarea></div><div class="cb"></div></li>        <li><div class="field_name ti">&nbsp;</div><div class="field_option"><input type="submit" value="Отправить" class="styled_sbm_btn"></div><div class="cb"></div></li>    </ul></form> </div>  ',
                onComplete: function() {
                    $(this).html("asasdasd");
				
                        return false;                     
                    
                
				}
            });
	});
            
          
  //coctails begin
  	$('#coctailname1,#coctailimg1').click(function() {
		desc=$('#coctailsdesc1').html();
		
		$.colorbox({
                transition: 'none',
                width: 400,
                html: "<span class='text_in_price_popup'>"+desc+"</span"
               
            });
	});
	$('#coctailname2,#coctailimg2').click(function() {
		desc=$('#coctailsdesc2').html();
		
		$.colorbox({
                transition: 'none',
                width: 400,
              html: "<span class='text_in_price_popup'>"+desc+"</span"
               
            });
	});
	$('#coctailname3,#coctailimg3').click(function() {
		desc=$('#coctailsdesc3').html();
		
		$.colorbox({
                transition: 'none',
                width: 400,
               html: "<span class='text_in_price_popup'>"+desc+"</span"
               
            });
	});
	$('#coctailname4,#coctailimg4').click(function() {
		desc=$('#coctailsdesc4').html();
		desc
		$.colorbox({
                transition: 'none',
                width: 400,
              html: "<span class='text_in_price_popup'>"+desc+"</span"
               
            });
	});
  
  
  
  //coctails end
  
  
	// Brands list
	$("ul.labels li:visible").each(function() {
		var th = $(this);
		var ind = $("ul.labels li:visible").index(th);
		var len = $("ul.labels li:visible").length;
		if (ind % 5 == 0 || ind > (len - len % 5) ) {
			$("div", th).css("display","none");
		} else {
			$("div", th).css("display","block");
		}
	});	
	
	$('.js-carousel').each(function () {
        $(this).jcarousel({
            buttonPrevHTML: '<div class="carousel_btn_prev ti">&nbsp;</div>',
            buttonNextHTML: '<div class="carousel_btn_next ti">&nbsp;</div>',
            wrap: 'circular',
            visible: 9    
        });
	});
	
	$('button').click(function() {		
	var arr=new Array();
	var arr2=new Array();
	var vars="";
	var counter=0;
	$('.buy_block_2 > input').each(function (){
		arr[counter]=$(this).attr("name");
		arr2[counter]=$(this).attr("value");
		vars+=counter!=0 ? "&" :"";
		vars+=arr[counter]+"="+arr2[counter];
		counter++;
	});
	vars+="&sid="+$('#sid').attr('value');
	
$.ajax({
   type: "POST",
   url: "/basket2.php",
   data: vars,
   success: function(msg){
	  $("#basket-block").html(msg);
	  
      $.colorbox({onOpen:function(){ 
 $('#cboxClose').remove(); },
                transition: 'none',
                width: 250,
                html: '<h1 style="margin-top:30px;margin-left:20px;">Добавлено в корзину</h1><script type="text/javascript">setTimeout(\'$.colorbox.close();\', 1000)</script>'                
            });
	}
 });
	});
	
	
	$('#savebasket').click(function() {		
	var arr=new Array();
	var arr2=new Array();
	var vars=""; 
	var vars0="";
	var counter=0;
	$('.fl > input').each(function (){
		arr[counter]=$(this).attr("name");
		arr2[counter]=$(this).attr("value");
		vars+=counter!=0 ? "&" :"";
		vars+=arr[counter]+"="+arr2[counter];
		counter++;
	});
	vars0=vars+"&sid="+$('#sid').attr('value');
	vars=vars0+"&type=0";
	
$.ajax({
   type: "POST",
   url: "/basket2.php",
   data: vars0,
   success: function(msg){
	  $("#basket-block").html(msg);
     
	}
 });
 
 $.ajax({
   type: "POST",
   url: "/basket2.php",
   data: vars,
   success: function(msg){
	  $("#basket-table-block").html(msg);
      $.colorbox({onOpen:function(){ 
 $('#cboxClose').remove(); },
                transition: 'none',
                width: 150,
                html: '<h1 style="margin-top:30px;margin-left:10px;">Сохранено</h1><script type="text/javascript">setTimeout(\'$.colorbox.close();\', 1000)</script>'                
            });
	}});
	
 });
 
	
	
	
	$('a.youtube').colorbox({
	   iframe: true, innerWidth: 600, innerHeight: 400,
	   href: function() {return this.href.replace(new RegExp("watch\\?v=", "i"), 'embed/')},
	});
});

function promocheck(promocod)
	{
	if (!promocod) return;
	else
		{
		$.ajax({
		   type: "POST",
		   url: "/comondor.php",
		   data: "promocod="+promocod,
		   success: function(msg){
			 alert(msg);
			}
		 });
		//document.cookie='promocod =' +promocod;
		}
	}

