var busy = false;
var background = 0;
var background_delay = 10000;

function slideSwitch(next_photo) {
    function changeBackground() {
        if ($("#background01").css('display') == 'none') {
            $("#background01").attr('src', backgrounds[background]);
            $("#background02").fadeOut(1000);
            $("#background01").fadeIn(1000);
        } else {
            $("#background02").attr('src', backgrounds[background]);
            $("#background01").fadeOut(1000);
            $("#background02").fadeIn(1000);
        }
    }

    if (!busy) {
        busy = true;
        clearTimeout(timer);
        timer = setInterval("slideSwitch(1)", background_delay);
        
        if (!next_photo) {
            if (background == 0) background = backgrounds.length - 1;
            else background--;
        } else {
            if (background == (backgrounds.length - 1)) background = 0;
            else background++;
        }

        bckimg = new Image();
        bckimg.src = backgrounds[background];

        if ($.browser.msie) {
            function testImg() {
                if (bckimg.complete != null && bckimg.complete == true) {
                    changeBackground();
                    return;
                }
                setTimeout(testImg, 300);
            }
            setTimeout(testImg, 300);
        }
        else bckimg.onload = changeBackground;
        bckimgnew = new Image();
        bckimgnew.src = backgrounds[background + 1];
        busy = false;
    }
    else { clearTimeout(timer); timer = setTimeout("slideSwitch(1)", 1500); }
}

$(function() {
    timer = setInterval("slideSwitch(1)", background_delay);
});

function intro() {
    document.getElementById('loaderImg').style.visibility = 'hidden';

    h = document.getElementById('content').offsetHeight;
    document.getElementById('contentBar').style.height = h + 'px';

    document.getElementById('content').style.display = 'none';
    document.getElementById('contentBar').style.width = '1px';

    $('#contentBar').animate({ opacity: 1 }, 0);
    $('#contentBar').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/resources/media/bg.png', sizingMethod='crop')");

    document.getElementById('loaderContent').style.display = 'none';

    $('#loading').animate({ height: 1 }, 500, function() {
        $('#bgGrid').animate({ height: '100%' }, 500, function() {
            $('#contentBar').animate({ width: '100%' }, 500, "swing",
					function() {
					    $('#content').fadeIn(1000);
					    document.getElementById('contentBar').style.height = 'auto';
					}
				);
        });
    });
}
	


