
// debug
if (!"console" in window)
	window.console = {log:function(){}};

jQuery(document).ready(function($){





//table color
$("tr:even").addClass("even");
$("tr:odd").addClass("odd");

$("td:even").addClass("even");
$("td:odd").addClass("odd");

//listing color
$("div.wrapper div.ib div.content ul li:even").addClass("even");
$("div.wrapper div.ib div.content ul li:odd").addClass("odd");


	// menu
	$(".menu.main > li")
		.bind("mouseenter",function(){
			var self = $(this).addClass("active"),
				drop = self.children(".dropdown"),
				link = self.children("a");
			if (drop.size() > 0){
				link.addClass("ui-corner-top");
				drop.show();
			} else {
				link.addClass("ui-corner-all")
			}

		})
		.bind("mouseleave",function(){
			var self = $(this);
			self.children(".dropdown").hide();
			self.removeClass("active");
		});

        var total = $('#slider img').length;
        var rand = Math.floor(Math.random()*total);        
        $('#slider').nivoSlider({
            effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
            animSpeed:800, // Slide transition speed
            pauseTime: 3000, // How long each slide will show
            startSlide:0, // Set starting Slide (0 index)
            controlNav:true,
            directionNav:true, // Next & Prev navigation
            directionNavHide:true, // Only show on hover
            controlNavThumbs:false, // Use thumbnails for Control Nav
            controlNavThumbsFromRel:false, // Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', // Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
            keyboardNav:true, // Use left & right arrows
            pauseOnHover:true, // Stop animation while hovering
            manualAdvance:false, // Force manual transitions
            captionOpacity:0.8, // Universal caption opacity
            prevText: 'Назад', // Prev directionNav text
            nextText: 'Вперед' // Next directionNav text
        });
        $('#slider').data('nivo:vars').stop = true;
        
	$(".sub .active a").click(false);

	/*$(".asside.menu").children("ul").children("li").children("a").click(function(){
		$(".asside.menu li ul").slideUp();
                window.location = $(this).attr('href');
		$(this).next().slideDown();
		$(".asside.menu ul > li > a").removeClass("active");
		$(this).addClass("active");
		return false;
	});*/
        
        //$("#ajaxSearch_input").focus(function(){$(this).val('')});
        $("#smb").click(function(){
            document.forms["ajaxSearch_form"].submit();
        });
        //$("#ajaxSearch_input").blur(function(){$(this).val('Поиск')});
        //$("#ajaxSearch_input").val('Поиск');
        //$("#ajaxSearch_output").hide();
        $("img.ib").click(function(){
            document.getElementById('ajaxSearch_output').setStyle('opacity','0');
            $("input.ib").val('');
        });
        
        $("input.ib").focus(function(){
            $(this).val('');
        });
        
        $('a.lightbox').lightBox();
        
        $("tr:nth-child(2)").addClass("color");
        
        $(".asside.menu").children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').has('ul').addClass('category');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').filter(function (index) { 
            return $(this).children("ul").length < 1; 
        }).addClass('product');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').filter(function (index) { 
            return $(this).children("ul").length < 1; 
        }).addClass('product');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').filter(function (index) { 
                    return $(this).children("ul").length < 1; 
        }).addClass('product');
        $(".asside.menu").children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').children("ul").children('li').filter(function (index) { 
                    return $(this).children("ul").length < 1; 
        }).addClass('product');
        
        
        $("li.active.product").parent("ul").parents("li.active").addClass('active_parent');
        
});     





function checkform(){
    document.getElementById('error').innerHTML='';
    if(document.getElementById('name_from').value.length < 2){
        var ni = document.getElementById('error');
        //var newp = document.createElement('p');
        //newp.setAttribute('style','color:red');
        ni.innerHTML = 'Имя должно содержать минимум 2 символа!';
        //ni.appendChild(newp);
        document.getElementById('name_from').setAttribute('class','ui-corner-all error');
        document.getElementById('error').style.display = 'block';
        return false;
    }else{
        document.getElementById('name_from').setAttribute('class','ui-corner-all');
    }
    reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
    if (!document.getElementById('email_from').value.match(reg)){
        var ni = document.getElementById('error');
        //var newp = document.createElement('p');
        //newp.setAttribute('style','color:red');
        ni.innerHTML = 'Пожалуйста введите корректный email.';
        //ni.appendChild(newp);
        document.getElementById('email_from').setAttribute('class','ui-corner-all error');
        document.getElementById('error').style.display = 'block';
        return false;
    }else{
         document.getElementById('email_from').setAttribute('class','ui-corner-all');
    }
    reg = /[-+]?[0-9]*\.?[0-9]+//*^(\+\d)*\s*(\(\d{3}\)\s*)*\d{3}(-{0,1}|\s{0,1})\d{2}(-{0,1}|\s{0,1})\d{2}$/*/;
    if(!document.getElementById('tel').value.match(reg)){
        var ni = document.getElementById('error');
        //var newp = document.createElement('p');
        //newp.setAttribute('style','color:red');
        ni.innerHTML = 'Пожалуйста введите корректный номер телефона.'+' <br/>';
        /*ni.appendChild(newp);*/
        document.getElementById('tel').setAttribute('class','ui-corner-all error');
        document.getElementById('error').style.display = 'block';
        return false;
    }else{
         document.getElementById('tel').setAttribute('class','ui-corner-all');
    }
    document.forms["feedbackForm"].submit();
}
/*
var TimeToFade = 1000.0;

function fade(eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
   
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
  }
  
    //setTimeout("document.body.removeChild(document.getElementById('test'));",1000);
    
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
  
}*/
function fade(id){
    jQuery(document.body).fadeIn('2');
}










