function swapDivs(from_id, to_id)
{
    from = document.getElementById(from_id);
    to = document.getElementById(to_id);

    from.style.display = 'none';
    to.style.display = 'block';

    return false;
}

intervalId = 0;
rotateInterval = 6000;
currentItem = 1;
totalItems = 3;
if ( _SITE == 'freeads' )
{
    itemNames = ["twitter", "motors", "smsbumpup"];
    itemUrls = ["http://twitter.com/ukfreeads", "http://"+_SITE_URL_MY+"/placead/start", "http://"+_SITE_URL_HOME+"/smsbumpup"];
}
else
{
    itemNames = ["generic", "motors", "pets"];
    itemUrls = ["http://"+_SITE_URL_MY+"/placead/start", "http://"+_SITE_URL_MY+"/placead/start", "http://"+_SITE_URL_HOME+"/smsbumpup"];
}


imageLoaded = new Array();
imageNames = ["main", "bottomleft", "larrow", "1", "2", "3", "rarrow", "bottomright"];

function loadImages()
{
	for (var counter = 0; counter < itemNames.length; counter++)
	{
		for (var imgcounter = 0; imgcounter < imageNames.length; imgcounter++)
		{
			imageLoaded[itemNames[counter]+'_'+imageNames[imgcounter]] = new Image();
			imageLoaded[itemNames[counter]+'_'+imageNames[imgcounter]].src = "http://static2."+_SITE_DOMAIN+"/whitelabel/"+_SITE+"/homepageads/"+itemNames[counter]+"/"+imageNames[imgcounter]+".gif";
		}
	}
}

function rotateAds()
{
	// Swap the current with the new
	newItem = currentItem + 1;
	if (newItem > totalItems)
		newItem = 1;

	swapAds(itemNames[currentItem - 1], itemNames[newItem - 1], newItem - 1);
	currentItem = newItem;

	return false;
}

/**
 * Swap the current ad with the new one by changing the background images
 */
function swapAds(currentAd, newAd, newAdIndex)
{
	/*alert(currentAd);
	alert(imageLoaded[newAd+'_main'].src);
	document.images.img_main.src = imageLoaded[newAd+'_main'].src;

	return;
	*/
	for (var imgcount = 0; imgcount < imageNames.length; imgcount++)
	{
		document.images["img_"+imageNames[imgcount]].src = imageLoaded[newAd+'_'+imageNames[imgcount]].src;
	}

    // Change the URL
    $('main_url').href = itemUrls[newAdIndex];

	return;
}

function loadAd(index)
{
	if (index < 1)
		index = 1;
	else if (index > totalItems)
		index = totalItems;

	swapAds(itemNames[currentItem - 1], itemNames[index - 1], index - 1);

	// index is the new currentItem.
	currentItem = index;

	// Stop rotating now...
	clearInterval(intervalId);

	// Return false so we don't fall through on the click
	return false;
}

function getImgTag(url)
{
	return '<img src="'+url+'" border="0" />';
}

function stopRotating()
{
	clearInterval(intervalId);
}

