// MonthlyPromoNavigationMenu.ascx.js

var _rotatePromoInterval; // interval at which the promos are changed
var _currentPromo = 0; // index of the currently displayed promo
var _promoCount = 0; // number of promos
var _thumbnailMenuId; // ID of the thumbnail menu table

//
// Display the specified promo in the Monthly Promo box		
//
function DisplayPromo(fileName, promotionLink, linkType, imageMapName, imageMap) {

	// TODO: avoid hardcoding control names ?
    if (fileName != "") {
        // Get DIVs
        imageDiv = document.getElementById('imageSection');
        flashDiv = document.getElementById('flashSection');

        // Detect if it's a flash file
        isFlash = (fileName.indexOf('.swf') != -1);
        if (isFlash) {
            // Show the right DIV
            imageDiv.style.display = 'none';
            flashDiv.style.display = 'block';
            
            flashDiv.innerHTML = '<object width="420" height="300"><param name="movie" value="' + fileName + '"><embed src="' + fileName + '" width="420" height="300"></object>';
        }
        else // it's an image
        {
            if ((imageMap != "")&&(imageMapName != ""))
                imageDiv.innerHTML = imageMap + '<img id="ThisMonthImg" style="display: none" usemap="#' + imageMapName + '" />';
            else
                {
                    var _internalCode = "45";
                    var _externalCode = "46";
                    var _target ="_self";
    
                    if (linkType == _internalCode)
                       _target="_self";
                    else if (linkType == _externalCode)
                        _target="_blank";

                    if (promotionLink != "") {
                        promotionLink = promotionLink + ' target=' + _target;
                        imageDiv.innerHTML = '<a href=' + promotionLink + '><img id="ThisMonthImg" style="display: none" /> </a>';
                    }
                    else {
                        imageDiv.innerHTML = '<img id="ThisMonthImg" style="display: none" />';
                    }
                }
            
            // Show the right DIV						
            imageDiv.style.display = 'block';
            flashDiv.style.display = 'none';

            thisMonthImg = document.getElementById('ThisMonthImg');
            thisMonthImg.src = fileName; 
            thisMonthImg.style.display = 'block';
            thisMonthImg.alt = promotionLink;
            
            if (linkType != "")
                thisMonthImg.setAttribute("linktype", linkType);
        }
    }
}	

//
// Start the interval (specified in milliseconds) at which to rotate the promos
//
function BeginRotatePromos(interval, currentPromo, promoCount)
{
	// Initialize working variables
	_currentPromo = currentPromo;
	_promoCount = promoCount;
	
    var divContainer = document.getElementsByTagName("div"); 
    for (var w = 0; w < divContainer.length; w++) 
    {
        if(divContainer[w].id.indexOf("PromoList") != -1 )
        {
            _thumbnailMenuId = divContainer[w].id;
        } 
    } 
	
	// Start the timer
	_rotatePromoInterval = setInterval('RotatePromo()', interval);
}

//
// End promo rotation
//
function EndRotatePromos()
{
    clearInterval(_rotatePromoInterval);
    window.scrollTo(0, 0);
}
	
//
// Display the next promo in the list
//
function RotatePromo()
{
	// Get to next promo. When the last promo is reached, go back to the first.
	if (_currentPromo >= _promoCount-1)
	{
		_currentPromo = 0;
	}
	else
	{
		_currentPromo++;
	}

	thumbnailMenu = document.getElementById(_thumbnailMenuId);
	thumbnails = thumbnailMenu.getElementsByTagName('img');
	image = thumbnails[_currentPromo];

	if (image != null) {
	    DisplayPromo(image.getAttribute('src2'), image.getAttribute('Link'), 
	    image.getAttribute('linktype'),image.getAttribute('imagemapname'), image.getAttribute('imagemap'));
	}
}

