var inter;
var intTime = 3500;
var AnimSpeed = 1000;
var lili = false;

$(document).ready(function () {
    
    lili = $(".left_menu_ul li").size();
    var w = parseInt($(window).width());
       
      if (w <= 1024){
          
          if ($.browser.msie && $.browser.version == '6.0'){   
              $(".bambarmia").css("width","10px");  
          }else {            
              $(".bambarmia").css("width","20px");
          }
       
   }

    if ($.browser.msie && $.browser.version == '6.0'){
        
        
    }else {
    $(".left_menu_ul li").hover(function(){
        
        var ind = $(".left_menu_ul li").index($(this));
        if (ind == '0'){ $(".left_menu_top").css("background","url(/tpl/main/images/lefter-top-hover.png) top right"); }
        var g = parseInt(lili) - 1;
        if (ind == g){ $(".left_menu_bottom").css("background","url(/tpl/main/images/lefter-bottom-hover.png) top right"); }
            $(this).children("span.erer").css("background","url(/tpl/main/images/grad_hover.png) repeat-y"); 
    },function(){
        var ind = $(".left_menu_ul li").index($(this));
        if (ind == '0'){ $(".left_menu_top").css("background","url(/tpl/main/images/lefter-top.png) top right"); }
        var g = parseInt(lili) - 1;
        
        if (ind == g){ $(".left_menu_bottom").css("background","url(/tpl/main/images/lefter-bottom.png) top right"); }
        $(this).children("span.erer").css("background","none");
    });    
    }
    
    $(window).bind("resize", resizeHandler);

	//resizeHandler();
	startScroll();
	
});

function resizeHandler() {
	
	var wihe = $(window).height();
	var topHe = $(".top").height();
	var topContHe = $("#topcontentblock").height();
	var botContHe = $("#bottomblock").height();
	
	var curWi = (wihe - topHe - topContHe - botContHe);
	if (curWi > 0) {
		//$("#centerblok").height(curWi);
	}
    
    

}



var startScroll = function () {
	var inter = setInterval(initGallery, intTime);
	//initGallery();
}

var initGallery = function () {
	var currElement;
	var allList = $(".topsliderblock");
	
	$(allList).each(function () {
		if ($(this).hasClass(".activeBlock")) {
			currElement = $(this);
		}
	});
	
	var ind = $(allList).index(currElement);
	
	if ((allList.length-1) == ind ) {
		nextElementIndex = 0;
	} else {
		nextElementIndex = ind + 1;
	}
	
	var ela = allList[nextElementIndex];
	
	$(ela).addClass("PrevActiveBlock");
	
	$(currElement).animate({opacity: 0}, AnimSpeed, function () {
		$(this).removeClass("activeBlock");
		$(this).css("opacity", "1");
		
		$(ela).addClass("activeBlock");
		$(ela).removeClass("PrevActiveBlock");
	});
	
	
	
	
}


