var lastTime1 = 0;
var times = {};
function timeliClick()
            {
                var li = $(this);
                var ul = li.parent();
                var li2 = $('#sel2 li');
                var ul2 = li2.parent();
//				ul.prev().attr('value', $('#_time_selected').attr('value'));

                if (ul.hasClass('open'))
                {
                    ul.removeClass('open');
                   
                    if (ul.parent().attr('id') != 'sel2') li.prependTo(ul);
                    var cur = parseInt($("#sel1 li:first").attr('class'));

					//if (cur >= 9) $('#_time_message').css({'display' : 'block'});
					//else $('#_time_message').css({'display' : 'none'});

					if (ul.parent().attr('id') != 'sel2')
						list2Display(cur);

                    ul.prev().attr('value', $(this).attr('class'));
					ul2.prev().attr('value', $(this).attr('class'));

                    if (ul.parent().attr('id') == 'sel2') li.prependTo(ul);
					else {
						ul2.prev().attr('value', $('#sel2 li:first').attr('class'));
					}

//					if (ul.parent().attr('id') != 'sel2') lastTime1 = ul.prev().attr('value');

//alert($("#sel1 li").parent().prev().attr('value'));
//alert($("#sel2 li").parent().prev().attr('value'));

                }
                else
                {
                    $("#search ul").removeClass('open');
                    ul.addClass('open');
                }
            }

function list2Display(cur)
{
					var li2 = $('#sel2 li');
					var ul2 = li2.parent();
					var cobj = eval('times.v' + cur);
if (!cobj) return;
	$(li2).each(function (i, item) { $(item).css({'display':'none'}); })
	for (var i = cobj.length-1; i >= 0; i--)
	{
		$("#sel2 li." + cobj[i]).show();
		$("#sel2 li." + cobj[i]).prependTo(ul2);
	}
}


$(document).ready(function(){


    $('li.water, li.production, li.our_services').hover(function() {
        $('.drop_down', this).show();
    }, function() {
        $('.drop_down', this).hide();
    })


 
/*
	$(".sms2").hover(
      function () {
        $(this).addClass('sms3')
      }, 
      function () {
        $(this).removeClass('sms3')
      }
    );
*/
    $('div.sms1').hover(function() {
        $('div.sms4').show()
    }, function() {
        $('div.sms4').hide()
    })

if ($('body').nivoZoom)
{
	$('body').nivoZoom({
		speed:500, // Скорость увеличения
		zoomHoverOpacity:0.8, // прозрачность увеличенного фото
		overlay:false, // наложение отсутствует
		overlayColor:'#333', // цвет наложения на картинку
		overlayOpacity:0.5, // прозрачность наложения
		captionOpacity:0.8 // Прозрачность подписи
	});
}

		if ($("#water_name li:visible:first-child").attr("pack") == 'yes') {
			$("#amount .pack").show()
			} else {
			$("#amount .pack").hide()	
			}
			
        $('#update select').each(
            function(index, select)
            {
                $(this).css({'display':'none'});
                var ul = $(document.createElement("ul"));

                $(select).after(ul);

                $('option', select).each(
                    function(i, item)
                    {
                        ul.append('<li class="'+$(item).val()+'"><span>' + $(item).text() + '</span></li>');
                    });
            });

		list2Display(7);
		

		$('#sel1 li.19, #sel1 li.22').css({'background-color' : '#7bc800'});
		$('#sel1 li.19 span, #sel1 li.22 span').css({'color' : '#ffffff'});
		$('#sel2 li.22, #sel2 li.24').css({'display' : 'none', 'background-color' : '#7bc800'});
		$('#sel2 li.22 span, #sel2 li.24 span').css({'color' : '#ffffff'});

      $("#update li").live("click", timeliClick);


			
$("#d img").css({width: $("#crumb").width()})
$("#crumb img").width($("#crumb span").width())

				$('#slider').slider({max:5, value:5, slide: function(event, ui) {
				$("#slider input").val(ui.value);
				$("#slider span").eq(ui.value).children().css({opacity:1}).parent().siblings().children().css({opacity:0.4})
				
				$("#water_name li").show().not("#water_name li[class*='"+ui.value+"']").hide();
				$("#order label input:hidden").val($("#water_name li[class*='"+ui.value+"']").eq(0).attr('value'));
				$("#amount input:count").val($("#water_name li[class*='"+ui.value+"']").eq(0).attr('min'))

      
					
					$("#amount input:count").val($("#water_name li:visible:first-child").attr('min'))
					
					
					
		if ($("#water_name li[class*='"+ui.value+"']").eq(0).attr("pack") == 'yes') {
			$("#amount .pack").show()
			} else {
			$("#amount .pack").hide()	
			}
					

			}
});			
				$("#order label input:hidden").val($("#water_name li[class*='5']").eq(0).attr('value'))
				$("#water_name li").show().not("#water_name li[class*='5']").hide()
                    //var cur_id = $("#water_name li").val();
                    var min = $("#min_counts input:min").val()
                    //var min = $("#min_counts input:min["+cur_id+"]").val()

                    $("#amount input:count").val()
                    //$("#amount input:count").val($("#water_name input:min"+$("#water_name li").attr('value')).attr('value'))
                
				$("#slider input").val(5);
				$("#slider span").eq(5).children().css({opacity:1}).parent().siblings().children().css({opacity:0.4})
				
				$("#amount input:count").val($("#water_name li:visible:first-child").attr('min'));
				
				
$("#amount input:count").change(function () {
			if ($("#amount input:count").val() < $("#water_name li:visible:first-child").attr('min')) {
			$("#completeWrap .dis").show()}	
			else {$("#completeWrap .dis").hide()}										  
 })

$("#increase").click(
    function () 
    {
        var count = $('#amount input').val();
        count++;
        $("#amount input").val(count);
		if ($("#amount input:count").val() < $("#water_name li:visible:first-child").attr('min')) {
			$("#completeWrap .dis").show()}	
			else {$("#completeWrap .dis").hide()}	
    }
)
$("#decrease").click(
    function () 
    {
        var count = $('#amount input').val();
        count--;
        if(count<$("#water_name li:visible:first-child").attr('min') || count<1) { count = $("#water_name li:visible:first-child").attr('min'); }
        $("#amount input").val(count);
	if ($("#amount input:count").val() < $("#water_name li:visible:first-child").attr('min')) {
			$("#completeWrap .dis").show()}	
			else {$("#completeWrap .dis").hide()}
    }
)

$("#basket img").width($("#basket a").width())	
$("#catalog form div img").parent().not("#nav, .desc, .desc2").prepend('<img src="./image/shadow.png" class="shadow" style="width:'+ $("#catalog form div").width() +'" />')


$("#list").prepend('<img src="./image/shadow_crumb.png" />')
$(".spec div img").parent().not("#nav, .desc, .desc2").prepend('<img src="./image/special.png" style="position:absolute; left:-20px; top:-20px;" />')
$("#basket a").prepend('<img src="./image/shadow_crumb.png" />')
$("#switch strong").prepend('<span></span>')

 $("#open").click(
      function () {
		
		$('body').prepend('<img id="blabla" src="./image/opa8.png" style="position:absolute; left:0; z-index:5; height: '+  $('#page').height() +'; width:100%" />')	
		$('#authorization form').animate({width: 370}, 500)	
		$("#open").animate({right: 328}, 500)		
		 $("#blabla").click(
			function () {
				$('#authorization form').animate({width: 0}, 500)	
				$("#open").animate({right: 0}, 500)		
				 $("#blabla").remove()
			});		
		});		
 
  $("#nav .not").click(
      function () {
		$('body').prepend('<img id="blabla" src="./image/opa8.png" style="position:absolute; left:0; z-index:5; height: '+ $('#page').height() +'; width:100%" />')
		$("body").append('<div id="message"><h2>Вы не авторизированны</h2><div id="nav"><a href="#">Войти</a> <a href="./cabinet/register/">Зарегистрироваться</a> <a href="./zakaz/">Продолжить оформление заказа</a></div></div>')
		return false
		});	
  
    $("#contact a").click(
      function () {
			/* $(this).next().show()
			$(this).remove() */
 		$('body').prepend('<img id="blabla" src="./image/opa8.png" style="position:absolute; left:0; z-index:5; height: '+ $('#page').height() + "px" +'; width:100%;" />')
		$("body").prepend('<div id="map"><div><h2>' + $(this).attr('title') + '</h2><img src="' + $(this).attr('href') + '" /><a href="#">Закрыть</a></div></div>')		
			 $("#map a, #blabla").click(
				function () {
				$("#map, #blabla").remove()
				return false
				});	 			  
		return false
		});
	
	    $("#prev_photo a img").parent().click(
      function () {

 		$('body').prepend('<img id="blabla" src="./image/opa8.png" style="position:absolute; left:0; z-index:5; height: '+ $('#page').height() + "px" +'; width:100%;" />')
		$("body").prepend('<div id="big_photo" style="top:' + parseInt($(this).offset().top  - 350) + 'px; left:' + parseInt($(this).offset().left) + 'px"><div><img src="' + $(this).attr('href') + '" /></div></div>')		
			 $("#big_photo, #blabla").click(
				function () {
				$("#big_photo, #blabla").remove()
				return false
				});	 			  
		return false
		});

	
	 $("#ask h2").click(
      function () {
		$(this).css({border:'none',  cursor:'auto'});
		$('#ask fieldset').slideDown()
		});


	 $("#water_name li").click(
      function () {
		t = $(this)
		ul = t.parent()
		if (ul.hasClass("open") != true) {ul.addClass('open');
		}
		else {	
		ul.removeClass('open')
		t.prependTo(ul)
		
		
			$("#amount input:count").val(t.attr('min'))
			
		$("#order label input:hidden").val(t.attr('value'))
		}
		
		if (t.attr("pack") == 'yes') {
			$("#amount .pack").show()
			} else {
			$("#amount .pack").hide()	
			}
		}
    );
	 
	 
	 $("#content #news .title a").parents('dl').children('dt').animate({opacity: 0.2}, 200);
	  $("#content #news .title  a").hover(
      function () {
		$(this).parents('dl').children('dt').animate({opacity: 1}, 200);
		},
		function () {			
		$(this).parents('dl').children('dt').animate({opacity: 0.2}, 200);
		}
    );



});
