$(document).ready(function(){

    var preload = new Array();
    $(".hovered").each(function() {
    	s = $(this).attr("src").replace(".png", "_hover.png");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');

    $(".hovered").hover(
  	      function(){
  		    var src = $(this).attr("src").replace(".png", "_hover.png");
  		    $(this).attr("src", src);
  	      }, function() {
   	          var src = $(this).attr("src").replace("_hover.png", ".png");
  	          $(this).attr("src", src);
  	      }
	);
    
    $(".menu ul a").each(function(){
        if(window.location.href.slice(window.location.href.indexOf('?'))==$(this).attr("href")){
		$(this).find("li").css("background-image",$(this).find("li").css("background-image").replace(".png", "_.png"));
	}
    });
    
    lastBlock = $("#a1");
    maxWidth = 750;
    minWidth = 60;	

    $(".slider ul li .slide").click(
      function(){
        $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
		$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
		var src = $(lastBlock).find('.slideimg').attr("src").replace("_.png", ".png");
		$(lastBlock).find('.slideimg').attr("src", src);
		lastBlock = this;
		var src = $(lastBlock).find('.slideimg').attr("src").match(/[^\.]+/) + "_.png";
		$(lastBlock).find('.slideimg').attr("src", src);
      }
    );

    $(function() {  
    	$(".slogan1").jCarouselLite({  
    	        vertical: true,  
    	        visible: 3,  
    	        auto:5000,  
    	        speed:1000  
    	    });  
    	});  
    $(function() {  
    	$(".slogan").jCarouselLite({  
    	        vertical: true,  
    	        visible: 3,  
    	        auto:5000,  
    	        speed:1000  
    	    });  
    	});  

    $('#tab-container').easyTabs();
    
});


var image1 = $('<img />').attr('src', 'images/m1_.png');
var image1 = $('<img />').attr('src', 'images/m2_.png');
var image1 = $('<img />').attr('src', 'images/m3_.png');
var image1 = $('<img />').attr('src', 'images/m4_.png');
var image1 = $('<img />').attr('src', 'images/m5_.png');
var image1 = $('<img />').attr('src', 'images/m6_.png');

y = new Object();
function httpRequest() {
	if (window.XMLHttpRequest) {
        requestObj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        requestObj = new ActiveXObject("Msxml2.XMLHTTP");
        if (!requestObj) {
            requestObj = new ActiveXObject("Microsoft.XMLHTTP");
        };
    };
};


function sendRequest (url, data, ndiv) {
	y = ndiv;
	document.getElementById(ndiv).innerHTML = "<center><img src='images/ajax-loader.gif' alt='' style='position: relative; top: 5em;' /></center>";
	httpRequest();
	requestObj.onreadystatechange = responseServer;
	requestObj.open('POST',url,true);
	requestObj.setRequestHeader("Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8");
	requestObj.send(data);
};
function responseServer() {
    if (requestObj.readyState == 4) {
    	var status = requestObj.status;
    	if (status == 200) {
    		addSelect(y);
    	} else if (status == 400) {
    		alert('Неправильный запрос');
    	} else if (status == 500) {
    		alert('Внутреняя ошибка на сервере');
    	} else if (status == 503) {
    		var time = requestObj.getResponseHeader('Retry-After')*1000;
    		alert('Сервер перегружен. Запрос будет повторен через: '+time+' секунд');
    		setTimeout(sendRequest(url,path),time);
    	} else {
    		alert('Ошибочный ответ сервера');
    	};
    };
};
function addSelect(ndiv) {
	var docTEXT = requestObj.responseText;
	document.getElementById(ndiv).innerHTML = docTEXT;
};
function loadnew(){
	var divid = $("#tab-container ul li.active a").attr("href");
	divid = divid.replace("#","");
	sendRequest('splash_'+divid+'.inc.php?loadnew=1', 1, divid);
}