/****************************
BACKGROUND.JS

Generates a random background
****************************/
IsMSIE = navigator.appVersion.indexOf('MSIE') != -1;


// Number of images
var num_images = 4;

// File extension
var file_ext   = "png";

function randomBackground(UseDir) {
	Dirs = new Array('appliances', 'furniture');
	
	var randomNumber = Math.random();
	
	if (!UseDir)
		var UseDir = Dirs[Math.round(randomNumber * (Dirs.length - 1))];
	
	var ImageNum = Math.round(randomNumber * num_images);
	
	var imageFileName = "/images/rotating_header_images/" + UseDir + '/' + ImageNum + "." + file_ext;
	
	with (document.getElementById('RandomBackground').style) {
		background += "url(" + imageFileName + ")";
		backgroundAttachment = 'fixed';
		backgroundPosition = 'top right';
		backgroundRepeat = 'no-repeat'; 
	}
}

// Opens window
function openGenWindow(filename, opt) {
	window.open(filename, "genWindow", opt);
}

function changeImg(imgName, newSrc) {
	document[imgName].src = newSrc;
}




// opacity() and changeOpac() functions from http://brainerror.net/scripts/javascript/blendtrans/
function opacity(id, opacStart, opacEnd, millisec) {
    
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

// change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

InOut = 0;
function fadeLogos() {
	if (InOut) {
		opacity('LogoAppliances', 100, 0, 1500);
		opacity('LogoFurniture', 0, 100, 1500);
		InOut = 0;
	}
	else {
		opacity('LogoAppliances', 0, 100, 1500);
		opacity('LogoFurniture', 100, 0, 1500);
		InOut = 1;
	}
}

// GENERATES EMAIL ADDRESS "SAFE" FROM HARVESTERS
function generateAntiSpiderEmail(Username, DomainName, TLD, OutputText, NoLink) {
	EmailAddress = Username + "&#64;" + DomainName + "&#46;" + TLD;
	OutputText   = ((OutputText)?OutputText:EmailAddress);
	
	document.write((NoLink)?OutputText:"<a href=\"ma" + "il" + "to:" + EmailAddress + "\">" + OutputText + "</a>");
}