
function backgroundScale()
{
    var imageRatio       = 1.75;
    var windowHeight     = document.body.clientHeight;
    var windowWidth      = document.body.clientWidth;
    var windowScale      = windowWidth / windowHeight;
    var targetWidth      = windowHeight * imageRatio;
    var targetWidthFull  = windowWidth;
    var leftPos          = - (targetWidth - windowWidth) / 2;
    var leftPosFull      = 0;

    if (windowScale <= imageRatio)
    {
        $('#rotator img').attr("width", targetWidth);
        $('#rotator').css("left", leftPos);
    } 
    else
    {
        $('#rotator img').attr("width", targetWidthFull);
        $('#rotator').css("left", leftPosFull);
    }
}

$(window).resize(function()
{
    var imageRatio       = 1.75;
    var windowHeight     = document.body.clientHeight;
    var windowWidth      = document.body.clientWidth;
    var windowScale      = windowWidth / windowHeight;
    var targetWidth      = windowHeight * imageRatio;
    var targetWidthFull  = windowWidth;
    var leftPos          = - (targetWidth - windowWidth) / 2;
    var leftPosFull      = 0;

    if (windowScale <= imageRatio)
    {
        $('#rotator img').attr("width", targetWidth);
        $('#rotator').css("left", leftPos);
    } 
    else 
    {
        $('#rotator img').attr("width", targetWidthFull);
        $('#rotator').css("left", leftPosFull);
    }
    mainBaseResize();
});

function mainBaseResize()
{
    if(($('body').height() >= 800) && ($('#mainBase').height() <= 500)){
        $('#mainBase').height($('body').height() - 445 + "px");
    }
}


$(document).ready(function(){
	//$('body').css({background: #fff});
    backgroundScale(); 
	//theRotator();
});

// FUF 
function theRotator() {
	$('#rotator img').css({opacity: 0.0});
	$('#rotator img:first').css({opacity: 1.0});
	setInterval('rotate()',20000);
}
 
function rotate() {	
	var current = ($('#rotator img.show')?  $('#rotator img.show') : $('#rotator img:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('#rotator img:first') :current.next()) : $('#rotator img:first'));	

	//var sibs = current.siblings();
	//var rndNum = Math.floor(Math.random() * sibs.length );
	//var next = $( sibs[ rndNum ] );
 	// Подключаем эффект растворения/затухания для показа картинок, css-класс show имеет больший z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);
 
	 //Прячем текущую картинку
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
};
