var images;
var item = 0;

$(document).ready(function () {
    if ($('#rotating-image').size() > 0) {
        $('#rotating-image').css('height', $('#rotating-image img').eq(0).height() + 'px');
	if($('#rotating-image').css('height') == '0px')
	{
		$('#rotating-image').css('height', '170px'); // to a default height
	}
        $('#rotating-image').css('overflow', 'hidden');
        $('#rotating-image img').css('position', 'absolute');
        images = $('#rotating-image img');
        var t = setTimeout("animate()", 7000);
    }
});

//fix if image is loaded last and the height isn't set on dom ready
$(window).load(function () {
    if ($('#rotating-image').size() > 0) {        
        $('#rotating-image').css('height', $('#rotating-image img').eq(0).height() + 'px');    
    }
});

function animate() {
    prev = item;
    item++;
    if (item == images.size())
        item = 0;

    images.eq(prev).fadeOut('slow');
    images.eq(item).fadeIn('slow');

    var t = setTimeout("animate()", 7000);
}

var ImageList = new Array();
var PreloadImageList = new Array();
var itemBG = 0
var imagesBG;
$(document).ready(function () {
    if (ImageList.length > 0) {
        $("#container-main").prepend("<div id='rotate' align='center' style='position:relative;top:0;height:0;'></div>");
        for (var i = ImageList.length; i > 0; i--) {
            $("#container-main #rotate").prepend("<div class='rotating-big-image' style='position:absolute;top:0;height:533px;width:100%;overflow:hidden; background:url(" + ImageList[i - 1] + ") no-repeat top center;" + (i == 1 ? "" : "display:none;") + "'></div>");
        }
        imagesBG = $('div.rotating-big-image');
        $("#container-main").css("background-image", "none");
        $(".container-header").css("position", "relative");

        var t = setTimeout("animateBig()", 7000);
    }
});

function animateBig() {
    prev = itemBG;
    itemBG++;
    if (itemBG == imagesBG.size())
        itemBG = 0;

    imagesBG.eq(prev).fadeOut('slow');
    imagesBG.eq(itemBG).fadeIn('slow');

    var t = setTimeout("animateBig()", 7000);
}
