﻿/* User agent detect --> Begin */
	
var original_bg_image_width, original_bg_image_height;

	  function declination(a, b, c, s) {
 					 var words = [a, b, c];
 					 var index = s % 100;
					 if (index >=11 && index <= 14) { index = 0; }
  					 else { index = (index %= 10) < 5 ? (index > 2 ? 2 : index): 0; }
 					 return(words[index]);
				}

var cssFix = function() {
    var u = navigator.userAgent.toLowerCase(),
    addClass = function(el,val){
        if(!el.className) {
            el.className = val;
        } else {
            var newCl = el.className;
            newCl+=(" "+val);
            el.className = newCl;
        }
    },
    is = function(t){
        return (u.indexOf(t)!=-1)
        };
    addClass(document.getElementsByTagName('html')[0],[
        (!(/opera|webtv/i.test(u))&&/msie (\d)/.test(u))?('ie ie'+RegExp.$1)
        :is('firefox/2')?'gecko ff2'
        :is('firefox/3')?'gecko ff3'
        :is('gecko/')?'gecko'
        :is('opera/9')?'opera opera9':/opera (\d)/.test(u)?'opera opera'+RegExp.$1
        :is('konqueror')?'konqueror'
        :is('safari/')?'webkit safari'
        :is('mozilla/')?'gecko':'',
        (is('x11')||is('linux'))?' linux'
        :is('mac')?' mac'
        :is('win')?' win':''
        ].join(" "));
}();

/* User agent detect --> End */


/*
    Cufon.replace(".header_top li a, .header_top .refill, .main_description .phone, .total_price_int,  .total_price_float, .promobox_head",{fontFamily: "HeliosCondBlack"});
    Cufon.replace(".header_top .about, .header_bottom a",{fontFamily: "HeliosCond"});    
    Cufon.replace(".price .currency, .promobox_text",{fontFamily: "HeliosCond"});    
    Cufon.replace(":header, .cart_top p",{fontFamily: "HeliosLight"});    
	Cufon.replace(".pack_note_reference span, .main_order_block .note, .helios_black",{fontFamily: "HeliosBlack"});  
	Cufon.replace(".main_order_block .note i, .helios_light",{fontFamily: "HeliosLight"});  
    Cufon.replace(".header_top li a",{fontFamily: "HeliosCondBlack"});

Cufon.replace(".left_side .d-phone.cond_blk.fixpng, .left_side .d-mail",{fontFamily: "HeliosCondBlack"});

*/

	function calculatePrice(current_item_form) {
        var current_count_input = current_item_form.find('input[name="item_count"]');
		var current_minimal_count_input = current_item_form.find('input[name="min_count"]');
	    var current_price_input = current_item_form.find('input[name="item_price"]');
		var current_manual_count_input = current_item_form.find('input[name="count_input"]');
        var current_item_count = parseInt(current_count_input.val());
		var current_item_minimal_count = parseInt(current_minimal_count_input.val());
		
		if (current_item_count >= current_item_minimal_count) {
			if (current_item_count > current_item_minimal_count){
                current_item_form.find('.decrease_big').addClass('active');
			} else {
                current_item_form.find('.decrease_big').removeClass('active');
			}
			var current_item_price = parseFloat(current_price_input.val());
			var new_item_price = (current_item_count * current_item_price).toFixed(2);

			var new_item_price_int = formatNumber(parseInt(new_item_price));
			//var new_item_price_int = parseInt(new_item_price);
			
			var new_item_price_float = new_item_price.toString().split('.')[1];
	        current_manual_count_input.val(current_item_count);
			var current_visible_count = current_item_form.find('.order_count_value');
			var current_visible_price_int = current_item_form.find('.total_price_int');
			var current_visible_price_float = current_item_form.find('.total_price_float');
			current_visible_count.html(current_count_input);

			current_visible_price_int.html(new_item_price_int + ',');
			current_visible_price_float.html(new_item_price_float);
		
			Cufon.refresh();
		
		} else {
			current_count_input.val(current_item_minimal_count);
            current_item_form.find('.decrease_big').removeClass('active');
		}
	}
	
	function formatNumber(num_s,dec,thou,pnt,curr1,curr2,n1,n2){ 
		var str = ''+num_s+'';
		return str.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
	}

function popup_alert(html){
	$('#popup_alert').show().find('.rel').html(html);
	var top = $(document).scrollTop()+(($(window).height()-$('#popup_alert').outerHeight())/2);
	$('#popup_alert').css({top:top});

}

$(function() {



    $('select').sSelect();


    $('input[title]').each(function() {
        $(this).addClass('blur').val($(this).attr('title'));
        $(this).focus(function() {
            if ($(this).val() === $(this).attr('title')) {
                $(this).val('').removeClass('blur');
            }
        }).blur(function() {
            if ($(this).val().length === 0) {
                $(this).val($(this).attr('title')).addClass('blur');
            }                     
        });                    
    });

	/* -- Main page total list scripts --> begin */

	if ($('#total_order_list .count_wrapper a').length) {

		function changeTotalCount(element,input,new_count_value) {
			if (new_count_value >= 3) {
				input.val(new_count_value);
				checkInputVal(input);
				$('#watercount').html(new_count_value);
			}
		}

		function checkInputVal(input) {
			if (parseInt(input.val()) > 3) {
				input.closest('form').find('.minus').addClass('active');
				
			} 
			else  {
				input.closest('form').find('.minus').removeClass('active');
			}
		}

		$('#total_order_list input[name="count"]').each(function() {
			$(this).val();
			//checkInputVal($(this));
		});

		var input;

		$('#total_order_list .count_wrapper .minus').click(function() {
			if (parseInt(input.val()) < 4) {return false}
				
			input = $(this).closest('form').find('input[type="hidden"]');
			changeTotalCount($(this), input, parseInt(input.val()) - 1);
			var item = $('.wizard input[name="item_count"]');
			var count_input = $('input[name="count_input"]');
			var tara = $('#total_order_list .tara');
			var taracount = input.val();
			
			if (zalogcount0>taracount) taracount=0;
				else taracount = taracount - zalogcount0;
			//alert(taracount);
			 tara.html(taracount);
			 count_input.val(input.val());
			 item.val(input.val());
			  if( input.val() < 10)
			    count_input.removeClass('two_digit');
			else
				count_input.addClass('two_digit');
			  if ( input.val() < 4) {
			    $('.decrease_big').removeClass('active');	
			 }
		
			 if(typeof CalcSets == 'function') CalcSets();
			   Cufon.refresh();
			return false;
		});

		$('#total_order_list .count_wrapper .plus').click(function() {
			input = $(this).closest('form').find('input[type="hidden"]');
			changeTotalCount($(this), input, parseInt(input.val()) + 1);
			var item = $('.wizard input[name="item_count"]');
			var count_input = $('input[name="count_input"]');
			var tara = $('#total_order_list .tara');
			var taracount = input.val();
			
			if (zalogcount0>taracount) taracount=0;
				else taracount = taracount - zalogcount0;
			//alert(taracount);
			 tara.html(taracount);
			 
			 count_input.val(input.val());
			 item.val(input.val());
			 if( input.val() > 9)
				count_input.addClass('two_digit');
		
			else
				count_input.removeClass('two_digit');
			 			 
			 if ( input.val() > 3) {
			  $('.decrease_big').addClass('active')	;
			 }
			 else if (input.val() < 3) {
	                $('.decrease_big').removeClass('active');
			}
			if(typeof CalcSets == 'function') CalcSets();
			  Cufon.refresh();
			
			return false;
		});

	}

	/* -- Main page total list scripts --> end */

	

    if ($('.order_block, .wizard').length) {

        $('.catalogue_list input[name="min_count"]').each(function() {
			$(this).closest('form').find('input[name="item_count"]').val($(this).val());
			$(this).closest('form').find('input[name="count_input"]').val($(this).val());
		});

		

		$('.count_input').keydown(function(event) {
			if ( event.keyCode == 46 || event.keyCode == 8 ) {
				
		
			} else {
				if (event.keyCode < 48 || event.keyCode > 57 ) {
					event.preventDefault();
				}
			}
		}).keyup(function(event) {
			if ($(this).val().length > 0){
				var current_item_form = $(this).closest('form');
				var current_count_input = current_item_form.find('input[name="item_count"]');
				var current_value_int = parseInt($(this).val(), 10);
				var current_value_str = current_value_int.toString();
				var sync = current_count_input.val(current_value_str);
				var count_syn_insert_val =  $('#total_order_list input[name="count"]');
			    var count = $('.count');
				  count.html(sync.val());
				  count_syn_insert_val.val(sync.val());
				if (sync.val() > 3)
				 {
				 	$('.count_wrapper a.minus').addClass('active');
				 } else {
				   $('.count_wrapper a.minus').removeClass('active');	
				 }
				
			    	  
				  
				
				calculatePrice($(this).closest('form'), current_value_str);
             
				if ($(this).val().length > 1){
					
					$(this).addClass('two_digit');
				} else {
					$(this).removeClass('two_digit');
				}
				 if(typeof CalcSets == 'function') CalcSets();
			}
		}).trigger('keyup');


        $('.increase_big').click(function() {

            var current_item_form = $(this).closest('form');
            var current_count_input = current_item_form.find('input[name="item_count"]');
			var current_count_input2 = current_item_form.find('input[name="count_input"]');
            var current_item_count = parseInt(current_count_input.val());
            var new_item_count = current_item_count + 1;
               
			if(parseInt(new_item_count) > 9)
			 
				current_count_input2.addClass('two_digit');
		
			else
				current_count_input2.removeClass('two_digit');

            current_count_input.val(new_item_count);
            calculatePrice(current_item_form);
            
            if(typeof changeCount == 'function') changeCount(current_item_form);
            
              var syn = new_item_count;
              var out_count_syn = $('.count').html(syn);
              var count_syn_insert =  $('#total_order_list input[name="count"]');
              count_syn_insert.val(syn);
              if ( syn > 3) {
				 $('.count_wrapper a.minus').addClass('active')	;
			  }

          if(typeof CalcSets == 'function') CalcSets();
              Cufon.refresh();         
            return false;
        });
        
        $('.decrease_big').click(function() {
            var current_item_form = $(this).closest('form');
            var current_count_input = current_item_form.find('input[name="item_count"]');
			var current_count_input2 = current_item_form.find('input[name="count_input"]');
            var current_item_count = parseInt(current_count_input.val());
            var new_item_count = current_item_count - 1;

			if(new_item_count > 9)
				current_count_input2.addClass('two_digit');
			else
				current_count_input2.removeClass('two_digit');
                 
            current_count_input.val(new_item_count);
            calculatePrice(current_item_form);
            
            if(typeof changeCount == 'function') changeCount(current_item_form);
            
            var syn = new_item_count;
            var out_count_syn = $('.count').html(syn);
            if (syn < 4) {return false}
            var count_syn_insert =  $('#total_order_list input[name="count"]');
            count_syn_insert.val(syn);
             if ( syn < 4) {
				 $('.count_wrapper a.minus').removeClass('active');
				
			  }
            if(typeof CalcSets == 'function') CalcSets();
               Cufon.refresh(); 
            return false;
        });
        
    }
	      
	  function declination(a, b, c, s) {
 					 var words = [a, b, c];
 					 var index = s % 100;
					 if (index >=11 && index <= 14) { index = 0; }
  					 else { index = (index %= 10) < 5 ? (index > 2 ? 2 : index): 0; }
 					 return(words[index]);
				}
        /*
			$(".catalogue_list input[type='submit']").click(function(){
				var current_item_form = $(this).closest('form');
				var cart_note_block = current_item_form.find('.cart_note');
				var item_count_input = current_item_form.find('input[name="count_input"]');
				cart_note_block.find('.item_count_value').html(item_count_input.val() + ' ' + declination("единиц", "единица", 							"единицы", item_count_input.val()));
				var flying_block = current_item_form.find('.order_count input[type="text"]');
				flying_block
			  .clone()
              .css({
			  'width' : '150px',
			  'background': 'url("images/circle.png") no-repeat 0 0 transparent' ,
			  'height':'150px',
			  'border':'none',
			  'color':'#3A505E',
			  'font-size': '103px',
			  'text-align':'center',
			  'padding':'0',
			  'font-family':'Helios',
				'position' : 'absolute',
					'z-index' : '100',
					'left':flying_block.offset().left,
					'top':flying_block.offset().top
					}).addClass('flying').appendTo("body").animate({
						  	'opacity': 0,
                            'top':0,
                            'left':$('.cart_header .page').offset().left
							}, 1500, function() { 
                    $(this).remove(); 
					
              }); 
			
 		
			  Cufon.refresh();
			   cart_note_block.show();
			   $(this).addClass("ordered");
			   return false;
			   
         });
		 */
 $(document).ready(function() {	
        var pop = 0;
	//select all the a tag with name equal to modal
	$('.catalogue_list .know_more').click(function(e) {
		
		 var current_form_pop = $(this).closest('form');
		 var current_block = current_form_pop.find('#dialog.window');
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');
	
		//Get the screen height and width
		/*var maskHeight = $(current_block).height();
		var maskWidth = $(current_block).width();*/
		
	 
		//Set heigth and width to mask to fill up the whole screen
		//$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		//$('#mask').fadeIn(500);	
	    //$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		//var winH = $(window).height();
		//var winW = $(window).width();
		
	     
		//Set the popup window to center
		 $(this).next('div.window').css('top',  ($(current_form_pop).offset().top - 60));
		 $(this).next('div.window').css('left', ($(current_form_pop).offset().left - 75));
	
		//transition effect
	  
		/*$(this).next('div.window').fadeIn(1000, function() {
			  pop = 1;
		});*/ 
		$(this).next('div.window').css('display', 'block');
	});


      $('body').click(function(event){
		var parent = $(event.target).parents('.window');
		if(!parent.length) 
		if(pop == 1) {
		$('.window').hide();
		}
		
		pop = 0;
	  });


	

	 	
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('.window').hide();
	});		
	

	
	
		
	
});

   
    var bottle_img=$("#small_1");
    var cooler_img=$("#small_2");
    
	$(".bottle").click(function() {	
		  var type_id = $(this).attr("rel");
	 	 //remove
  		  $('#small_1td').empty();
		  $(this).closest("li").addClass("active");	  		
		  $(".bottle[rel!='"+type_id+"']").parent().parent().parent("li").removeClass("active");
	      $('#small_1td').html('<img id="small_1" src="" title="" alt="" class="pngfix" />');
	      $('#small_1').attr("src",$(this).attr('name'));
	      $('#small_1').attr('title',$(this).text());    
	      $('#small_1').attr('alt',$(this).text());  
	      //bottle_img.addClass("fixpng");
		  //DD_belatedPNG.fix('.fixpng');

		  if(typeof CalcSets == 'function') CalcSets();
		  
	      return false;
	});		

	$(".cooler").click(function() {	
			var type_id = $(this).attr("rel");
  		 	$('#small_2td').empty();
			$(this).closest("li").addClass("active");  		
		    $(".cooler[rel!='"+type_id+"']").parent().parent().parent("li").removeClass("active");		
	    
	     
			$('#small_2td').html('<img id="small_2" src="" title="" alt="" class="pngfix" />');
			$('#small_2').attr("src",$(this).attr('name'));
			$('#small_2').attr('title',$(this).text());    
			$('#small_2').attr('alt',$(this).text());  
			//DD_belatedPNG.fix('.fixpng');

			if(typeof CalcSets == 'function') CalcSets();
	      return false;
	});	// JavaScript Document


/*	$(".cooler").click(function() {	
			  var type_id = $(this).attr("rel");
			  cooler_img.removeClass("fixpng");	
			 $(this).closest("li").addClass("active");  		
		     $(".cooler[rel!='"+type_id+"']").parent().parent().parent("li").removeClass("active");		
	    
	     
	        cooler_img.attr("src",$(this).attr('href'));
	        cooler_img.attr('title',$(this).text());    
	        cooler_img.attr('alt',$(this).text());  
	        if(typeof CalcSets == 'function') CalcSets();
	        cooler_img.addClass("fixpng");
	      return false;
	});	// JavaScript Document*/

	if(typeof CalcSets == 'function') CalcSets();

	if ($("#map_canvas1").length!=0) 
	{

		var map;

		if (GBrowserIsCompatible()) {
		       							
										
		map = new GMap2(document.getElementById("map_canvas1"));
		map.addControl(new GSmallMapControl())


		              
				var blueIcon = new GIcon();
				blueIcon.image = "/images/yd.png";
				blueIcon.iconSize = new GSize(62, 55);
				blueIcon.iconAnchor = new GPoint(16, 50);

				markerOptions = { icon:blueIcon };	  
						
		var point = new GLatLng(55.682408,37.627248);

			var marker = new GMarker(point, markerOptions);
		        map.addOverlay(marker);
			map.setCenter(point, 15);							
		}
	}
	
	if ($("#map_canvas2").length!=0) 
	{

		var map;

		if (GBrowserIsCompatible()) {
		       							
										
		map = new GMap2(document.getElementById("map_canvas2"));
		map.addControl(new GSmallMapControl())


		              
				var blueIcon = new GIcon();
				blueIcon.image = "/images/yd.png";
				blueIcon.iconSize = new GSize(62, 55);
				blueIcon.iconAnchor = new GPoint(16, 50);

				markerOptions = { icon:blueIcon };	  
						
		var point = new GLatLng(55.6957,37.5894);

			var marker = new GMarker(point, markerOptions);
		        map.addOverlay(marker);
			map.setCenter(point, 15);							
		}
	}
	
	if ($("#map_canvas3").length!=0) 
	{

		var map;

		if (GBrowserIsCompatible()) {
		       							
										
		map = new GMap2(document.getElementById("map_canvas3"));
		map.addControl(new GSmallMapControl())


		              
				var blueIcon = new GIcon();
				blueIcon.image = "/images/yd.png";
				blueIcon.iconSize = new GSize(62, 55);
				blueIcon.iconAnchor = new GPoint(16, 50);

				markerOptions = { icon:blueIcon };	  
						
		var point = new GLatLng(56.092444,37.117562);

			var marker = new GMarker(point, markerOptions);
		        map.addOverlay(marker);
			map.setCenter(point, 15);							
		}
	}
	
});



 /*-- 3 PopUps Scripts --*/
 /*First PopUp Counter*/
$(document).ready(function() {	
		$('#info').text('Hello World');								 
	$('.popup_table img').click(function() {
	if ($(this).attr('src') == '/images/btn_popup_minus.png') { var dir = -1};
	if ($(this).attr('src') == '/images/btn_popup_plus.png') { var dir = 1};
	var cur_popcount = $(this).parents('tr').find('.popup_count').text();
	var cur_popcount = parseInt(cur_popcount); 
	cur_popcount = cur_popcount + dir;
	if (cur_popcount < 0) {cur_popcount = 0}
	$(this).parents('tr').find('.popup_count').text(cur_popcount + ' шт.')
// Close PopUps	
	})
	$('.window2 .close2').click(function() {
		$(this).parents('div.window2').hide();	
	})
//	Close PromoBox
	$('a.promo_close').click(function() {
		$('div.d-promobox').slideUp(200);	
	})
// AutoClose PromoBox
    //$('#promo_show').fadeOut(1);
	if ($("#promo_show").length>0) setTimeout("promohide()",prmoint);
	$('#promo_show').click(function() {
		promoshow()			
	})
	
	$('#refill').click( function() {
	infopop = 1;
	$('#popup_sorry').show();
	})
	
	$('.page').parents('.cart_header').css('visibility', 'visible');

	 $('.header_top li').hover(
		function() {
		$(this).find('a').css('color', '#c24f92');
		Cufon.refresh();		
	},
	function() {
		$(this).find('a').css('color', '#253F4E');
		Cufon.refresh();		
	}
	)
})

function promohide() {
	$('#promo_block').slideUp(500, function(){
		//$('#promo_show').css('display', 'block');
		$('#promo_show').fadeIn(500);
	});
}

function promoshow() {
	    $('#promo_show').fadeOut(300, function() {
			//$('#promo_show').css('display', 'none');
			$('#promo_block').slideDown(500, function(){
				setTimeout("promohide()",prmoint);
			});							
		});	}



$(function() {
   
   $('.inp1').val($('.inp1').attr('title')).focus(function() {
        if ($(this).val() === $(this).attr('title')) {
            $(this).val('');
        }        
    }).blur(function() {
        if ($(this).val().length === 0) {
            $(this).val($(this).attr('title'));
        }                        
    });
});
/*End*/
 
 /*-- End 3PopUps Scripts --*/
 
	
