
minWidth = 262;
maxWidth = 632;
Animate = false;

$(document).ready(function()
{
		$('.menu ul').css('paddingLeft', ($('.menu').width() - $('.menu ul').width())/2);
    $('.enter, .enterPic').click(function(){if ($('#enterForm').css('display') == 'block') $('#enterForm').slideUp(1500); else $('#enterForm').slideDown(1500);});
    
    $('#box1, #box2, #box3').append('<div title="   " class="overbox"></div><div class="text"></div><div  title="   "  class="grLeft"></div><div title="   " class="grRight"></div>');
    
    $('.introMenu a').click(function(){
        link = $(this).attr('href');
        if ($('#box1').width() == maxWidth)
            HideBox1()
        else if ($('#box2').width() == maxWidth)
            HideBox2();
        else if ($('#box3').width() == maxWidth)
            HideBox3();
        $('.grLeft, .grRight').hide();
        $('#text1,#text2,#text3').animate({top: 35}, 2000);
        $('.show').animate({height: 128}, 2000);
        $('#box1, #box2, #box3').animate({height: 100}, 2000);
        $('#inner1, #inner2, #inner3').animate({height: 100}, 2000, function(){
            location.href = link;
        });
        return false;
    });

	// строка, которая нужна для правого выравнивания картинки
//	$('#inner3 img').css('left', '-370px');
	

	$(document).pngFix();
	
	MegaAnimationGo();
	
	$('#inner1').cycle({ 
        fx:    'fade',                 
        next: '#inner1',
        delay: 2000,
        speed: 1000,
        timeout: 0,
        after: onAfter1,
        before: onBefore1
    });
    
    $('#inner2').cycle({ 
        fx:    'fade',                 
        next: '#inner2',
        delay: 2000,
        speed: 1000,
        timeout: 0,
        after: onAfter2,
        before: onBefore2
    });
    
    $('#inner3').cycle({ 
        fx:    'fade',                 
        next: '#inner3',
        delay: 2000,
        speed: 1000,
        timeout: 0,
        after: onAfter3,
        before: onBefore3
    });
    
    $('.text').hide();

});

function MegaAnimationGo()
{
    $('#box1').click(function(){

		$('#enterForm').hide();
	    if (!Animate)
	    {   
	        if ($(this).width() == maxWidth)
	        {
	        }
	        else if ($('#box2').width() == maxWidth)
	            HideBox2()
	        else if ($('#box3').width() == maxWidth)
	            HideBox3();
	        else
	            ShowBox1();
	    }
	        
	});
	
	$('#box2').click(function(){

		$('#enterForm').hide();
	    if (!Animate)
	    {
	        if ($(this).width() == maxWidth)
	        {
	        }        
	        else if ($('#box1').width() == maxWidth)
	            HideBox1()
	        else if ($('#box3').width() == maxWidth)
	            HideBox3();
	        else
	            ShowBox2();
	    }
	});
	
	$('#box3').click(function(){
		$('#enterForm').hide();
	    if (!Animate)
	    {
	        if ($(this).width() == maxWidth)
	        {
	        }
	        else if ($('#box1').width() == maxWidth)
	            HideBox1()
	        else if ($('#box2').width() == maxWidth)
	            HideBox2();
	        else
	            ShowBox3();
	    }
	});
}

function onAfter1(){if (!Animate) $('#box1 .text').css('left', parseInt($(this).attr('class').split(' ')[1])).css('top', parseInt($(this).attr('class').split(' ')[0])).html(this.alt).show();}
function onBefore1(){$('#box1 .text').hide();}
function onAfter2(){if (!Animate) $('#box2 .text').css('left', parseInt($(this).attr('class').split(' ')[1])).css('top', parseInt($(this).attr('class').split(' ')[0])).html(this.alt).show();}
function onBefore2(){$('#box2 .text').hide();}
function onAfter3(){if (!Animate) $('#box3 .text').css('left', parseInt($(this).attr('class').split(' ')[1])).css('top', parseInt($(this).attr('class').split(' ')[0])).html(this.alt).show();}
function onBefore3(){$('#box3 .text').hide();}

function HideBox1()
{
    Animate = true;
    $('.text').hide();
    $('#box1 .overbox').show();
    $('#box1 img').show();
    MegaAnimationGo();
    $('#box1').css('zIndex', 5);
    $('#box2').css('zIndex', 2);
    $('#box3').css('zIndex', 1);
    $('#box2').animate({marginLeft: '-=180px'}, 1000);    
    $('#box1').animate({width: minWidth}, 1000, function(){$('#text1').fadeIn(1000, function(){Animate = false;});});
}

function ShowBox1()
{
    Animate = true;
    $('#box1 .overbox').hide();
    $('#box1').css('zIndex', 5);
    $('#box2').css('zIndex', 2);
    $('#box3').css('zIndex', 1);
    $('#text1').fadeOut(1000, function(){
        $('#box2').animate({marginLeft: '+=180px'}, 1000);
        $('#box1').animate({width: maxWidth}, 1000, function(){
            Animate = false;
            $('#box1 .text').show();
        });
    });
}

function HideBox2()
{
    Animate = true;
    $('.text').hide();
    $('#box2 .overbox').show();
    $('#box1').css('zIndex', 1);
    $('#box2').css('zIndex', 5);
    $('#box3').css('zIndex', 1);    
    $('#box2').animate({width: minWidth, marginLeft: -141}, 1000, function(){$('#text2').fadeIn(1000, function(){Animate = false;});});
}

function ShowBox2()
{
    Animate = true;
    $('#box2 .overbox').hide();
    $('#box1').css('zIndex', 1);
    $('#box2').css('zIndex', 5);
    $('#box3').css('zIndex', 1);
    $('#text2').fadeOut(1000, function(){
        $('#box2').animate({width: maxWidth, marginLeft: -316}, 1000, function(){
            Animate = false;
            $('#box2 .text').show();
        });
    });
}

function HideBox3()
{
    Animate = true;
    $('.text').hide();
	// строка, которая нужна для правого выравнивания картинки
	//$('#inner3 img').animate({ marginLeft: '-370px'}, 1000);
    $('#box3 .overbox').show();
    $('#box1').css('zIndex', 1);
    $('#box2').css('zIndex', 2);
    $('#box3').css('zIndex', 5);
    $('#box2').animate({marginLeft: '+=180px'}, 1000);
    $('#box3').animate({width: minWidth}, 1000, function(){$('#text3').fadeIn(1000, function(){Animate = false;});});
}

function ShowBox3()
{
    Animate = true;
    $('#box3 .overbox').hide();
    $('#box1').css('zIndex', 1);
    $('#box2').css('zIndex', 2);
    $('#box3').css('zIndex', 5);
    $('#text3').fadeOut(1000, function(){

	// строка, которая нужна для правого выравнивания картинки
	//$('#inner3 img').animate({ marginLeft: 0}, 1000);

        $('#box2').animate({marginLeft: '-=180px'}, 1000);
        $('#box3').animate({width: maxWidth}, 1000, function(){
            Animate = false;
            $('#box3 .text').show();
        });
    });
}
