﻿var flipId = 0; 

function flipTile(fId, tileNo, newBannerNo) {
    flipStep(fId, tileNo, newBannerNo, 1);
}

function flipStep(fId, tileNo, newBannerNo, step) {
    var delta, timeOut, newWidth;    
        
    if (fId == flipId) {
        
        if (navigator.appName == "Microsoft Internet Explorer") {
            delta = 18;  timeOut = 5;        
        } else
        {
            delta = 15;  timeOut = 25;        
        }

        if (step == 1) {
            newWidth = parseInt(document.getElementById('banner' + tileNo).style.width) - delta;

            if (newWidth > 0) {
                document.getElementById('banner' + tileNo).style.width = String(newWidth) + 'px';
                setTimeout('flipStep(' + fId + ', ' + tileNo + ', ' + newBannerNo + ', 1)', timeOut);
            } else {
                document.getElementById('banner' + tileNo).src = 'images/ui/banner' + newBannerNo + '/' + tileNo + '.png';
                setTimeout('flipStep(' + fId + ', ' + tileNo + ', ' + newBannerNo + ', 2)', timeOut);
            }
        } else 
        {
            newWidth = parseInt(document.getElementById('banner' + tileNo).style.width) + delta;

            if (newWidth >= 117) {
                document.getElementById('banner' + tileNo).style.width = '117px';
            } else {
                document.getElementById('banner' + tileNo).style.width = String(newWidth) + 'px';
                setTimeout('flipStep(' + fId + ', ' + tileNo + ', ' + newBannerNo + ', 2)', timeOut);
            }
        }
    }
}

function flipBanner(newBannerNo) {
    flipId += 1;

    setTimeout('flipTile(' + flipId + ', 1, ' + newBannerNo + ')', 100);
    setTimeout('flipTile(' + flipId + ', 2, ' + newBannerNo + ')', 300);
    setTimeout('flipTile(' + flipId + ', 3, ' + newBannerNo + ')', 500);
    setTimeout('flipTile(' + flipId + ', 4, ' + newBannerNo + ')', 700);
    setTimeout('flipTile(' + flipId + ', 5, ' + newBannerNo + ')', 900);
    setTimeout('flipTile(' + flipId + ', 6, ' + newBannerNo + ')', 1100);
    setTimeout('flipTile(' + flipId + ', 7, ' + newBannerNo + ')', 1300);
    setTimeout('flipTile(' + flipId + ', 8, ' + newBannerNo + ')', 1500);
}
