var noHide = false;
	
	var hideFunc = function(){
		if (!noHide){
			$('#autorisation:visible').fadeOut('fast');
			$('#shader:visible').fadeOut('fast');
			$('#autorisation_:visible').fadeOut('fast');
			}
			else{
				noHide = false;
				}
 		}
		
		
	$(window).load(function(){
 		$('.cross').click(hideFunc);
 		$('body').click(hideFunc);
		
		
		$('.enter').click(function(){
		$('#autorisation_').fadeIn('fast');	
		$('#autorisation').fadeIn('fast');
		$('#shader').fadeIn('fast');
		$('#autorisation').css('left', Math.round( (parseInt($('body').outerWidth()) - parseInt($('#autorisation').outerWidth()) ) / 2 + 340) );
		return false;
			});
		
		$('#autorisation').click(function(event){
			noHide = true;
			return !(event.target.nodeName == 'DIV');
		});
		
			
	
	});

$(window).load(function(){
	$('.jcarousel-skin-tango .jcarousel-item').mouseover(function () {
		$(this).css('opacity', 1);
		return false;
		});
		
	$('body').mouseover(function(){
		$('.jcarousel-skin-tango .jcarousel-item').css('opacity', 0.4);
		 });
		 
	$('.floormaps .nav a').click(function(){
			if ($(this).parent().hasClass('selected')){
				return false;
			}
			$('.floormaps .nav li').removeClass('selected');
			$('.floormaps .floormap').hide();
			$(this).parent().addClass('selected');
			$('#' + $(this).attr('rel')).show();
			return false;
		});	
		
	});	


/*var noHide = false;
var hideFunc = function(){
	if (!noHide){
		$('#autorisation:visible').fadeOut('fast');
		$('#shader').fadeOut('fast');
		}
		else{
			noHide = false;
			}
		}

/*$(window).load(function(){
  	$('.cross').click(hideFunc);
 	$('body').click(hideFunc);
		
		
	var whiteshaderFunc = function(){
		var shader = document.createElement('div');
		$(shader).attr('id', 'shader').css('background-color', '#726f6f').css('opacity', '0.45').css('position', 'fixed').css('left', '0').css('right', '0').css('top', '0').css('bottom', '0').css('z-index', '1000');
		$('body').append(shader);
 		$(shader).click(hideFunc);
		return false;
		}
	$('.whiteshader').click(whiteshaderFunc);
	
	$('.enter').click(function(){
		$('#autorisation').fadeIn('fast');
		return false;
			});
		
	$('#autorisation').click(function(event){
		noHide = true;
		return !(event.target.nodeName == 'DIV');
	});	

});*/

/*var hideFunc = function(){
		if (!noHide){
			$('#autorisation:visible').fadeOut('fast');
			$('#shader').fadeOut('fast');
			}
			else{
				noHide = false;
				}
 		}
 		$('.cross').click(hideFunc);
 		$('body').click(hideFunc);
		
		
		$('.enter').click(function(){
		$('#autorisation_').fadeIn('fast');
		//$('#autorisation').fadeIn('fast');
		$('#shader').fadeIn('fast');
		$('#autorisation').css('left', Math.round( (parseInt($('body').outerWidth()) - parseInt($('#autorisation').outerWidth()) ) / 2 + 340) );
		
		return false;
			});
		
	$('.autorisation_form').click(function(event){
		noHide = true;
		return !(event.target.nodeName == 'DIV');
	});	*/

/*$(window).load(function(){
	
	$('.cross').click(hideFunc);
 	$('body').click(hideFunc);
	
  	$('.enter').click(function(){
		$('#autorisation_').fadeIn('fast');
		//$('#autorisation').fadeIn('fast');
		$('#shader').fadeIn('fast');
		$('#autorisation').css('left', Math.round( (parseInt($('body').outerWidth()) - parseInt($('#autorisation').outerWidth()) ) / 2 + 340) );
		
		return false;
		
	});
		
		$('#autorisation').click(function(event){
		noHide = true;
		
		});
				
	});*/
	
	


document.onkeydown = NavigateThrough;

var current_man = 0;
var max_man = -1;

function NavigateThrough (event)
{
    if (!document.getElementById) return;

    if (window.event) event = window.event;

    if (event.ctrlKey){

           var link = null;
           var href = null;

           switch (event.keyCode ? event.keyCode : event.which ? event.which : null){
              case 0x25:
                   link = document.getElementById ('PrevLink');
              break;
              case 0x27:
                   link = document.getElementById ('NextLink');
              break;
              case 0x24:
                   href = '/';
              break;
           }

           if (link && link.href) document.location = link.href;
           if (href) document.location = href;
    }
}


var cl=0, cl2='', cl3=0, oldsloi='';
$(function () {

      $(".map_all, .closemap").click(function() {    $('#map'+$(this).attr('id')).toggle();   });

      $("#main_search_button").click(function() {    $('#main_search_form').submit();   });

      $("#input_kod_prod").click(function() {
         $('.input_kod_prod').toggle();
         });

              $("#find_1").click(function() {
                      $(".finstr_").hide();
                      $(".finstr").show();

                      if (cl2 != '') $(cl2).hide();
                      cl2='.finstr', cl=1;
              });

              $('.finstr').click(function(e){        var clicked = $(e.target); cl=1, cl3=1;  });

      $().click(function(e){
                 if ( (cl == 0 ) &&  (cl2 != '') ){
                      $(cl2).hide();
                      $('.finstr_').show();
                      cl=0, cl2='';
              }  else  cl=0;
      });


       $('ul a').collapsor();


       $(".chel").each(function(){ max_man++; });
       setTimeout(viewNextPeople, 10000);

        $("#collsearch_butt").bind("click", function(){
           searchOnSubmit();
           return false;
        });

        $("#category").change();



    $('.bubbleInfo').each(function () {
        var distance = 10;
        var time = 100;
        var hideDelay = 80;

        var hideDelayTimer = null;

        var beingShown = false;
        var shown = false;



        var trigger = $('.trigger', this);
        var info = $('.popup', this).css('opacity', 0);


        $([trigger.get(0), info.get(0)]).mouseover(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            if (beingShown || shown) {
                // don't trigger the animation again
                return;
            } else {
                // reset position of info box
                beingShown = true;

                info.css({
                    top: -85,
                    left: -10,
                    display: 'block'
                }).animate({
                    top: '-=' + distance + 'px',
                    opacity: 1
                }, time, 'swing', function() {
                    beingShown = false;
                    shown = true;




                });
            }

            return false;
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer);
            hideDelayTimer = setTimeout(function () {
                hideDelayTimer = null;
                info.animate({
                    top: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () {
                    shown = false;
                    info.css('display', 'none');


                });

            }, hideDelay);

            return false;
        });
    });

 
});

function searchOnSubmit() {


      if ($("#category").val() == 0 && $("#kod_prod").val() == '') {

        alert('Введите код продукции!!!');
        $("#kod_prod").show();
        $("#kod_prod").focus();

      } else {
        $("#coll_search").submit();
      }

      return false;
}

function viewNextPeople() {


        if (current_man >= 0)
            $(".chel").eq(current_man).hide();
        current_man ++;

        if (current_man > max_man) current_man = 0;
        $(".chel").eq(current_man).show();

        setTimeout(viewNextPeople, 10000);
}

function loadPartners(pid) {

        $("#sity").load("/collection/viewlist_ajax/"+pid);

}




function getResult() {

       // alert("/voting/go_vote/"+$("#vote_num").val());
        $("#vote_frame").load("/voting/go_vote/"+$("#vote_num").val());
}

function setAnswer(id) {
        var str = "#"+"an-"+id;
        $(".opros_tr_act").attr("class","opros_tr");
        $(str).attr("class","opros_tr_act");
        $("#cur_value").attr("value",id);
}

function sendVote() {

        if ($("#cur_value").val() == 0) {
             alert("Укажите какой-нибуть вариант ответа!");
        } else {
             $("#vote_form").submit();
        }

}

function doFind(str) {

        $("#main_words").val(str);

}


function find_all(id){


        if (id.value == 0) {
                $('.find_link').show();
                $('.find_all2').hide();
        } else if (id.value == 173) {
                $('.find_link').hide();
                $('.find_all2').hide();
                $('#find_div_1').show();
                $('#find_div_3').show();
        } else if (id.value == 174) {
                $('.find_link').hide();
                $('.find_all2').hide();
                $('#find_div_2').show();
                $('#find_div_3').show();
        } else if (id.value == 175) {
                $('.find_link').hide();
                $('.find_all2').hide();
                $('#find_div_4').show();
        }

        $('#do_it').val(id.value);

}




