var DEFAULT_WALLPAPER_TITLE = 'Wallpaper';
var DEFAULT_360_TITLE = '';
var WALLPAPER_URL = '/homepage.popups.wallpaper.htm';

//sPath: path to wallpaper image
//optPageTitle: optional title of popup window (otherwise default is used)
function openWallpaper(sPth, optPageTitle) {
	var wHnd;
	if(sPth) {		
		wHnd = _popit(WALLPAPER_URL, 'wallpaper', '900','700');		
		setValues(wHnd, sPth, optPageTitle);						
	}
}

function setValues(wHnd, sPth, optPageTitle) {
		if (wHnd.document.getElementById('pWallpaper')) {
			wHnd.document.getElementById('pWallpaper').src = sPth;
			if(optPageTitle)
				wHnd.document.title = optPageTitle;
			else
				wHnd.document.title = DEFAULT_WALLPAPER_TITLE;				
		} else {
			setTimeout(function () { setValues(wHnd, sPth, optPageTitle); }, 500);
		}
}

// sType is either 'mov' or 'swf'
function open360(sPth, sType) {
	if (sType=="swf") {
		var wHnd = _popit('/popups/360flash.html', '360',609,338);		
		setDivValue(wHnd,'ufo360Movie',sPth);
		setTitle(wHnd,'Infiniti.com - 360 degree View');
	}
	if (sType=="mov") {
		var wHnd = _popit('/popups/360mov.html', '360',640,600);		
		setDivValue(wHnd,'360Path',sPth);
		setDivValue(wHnd,'videoTitle','2006 QX56 360&deg; Spin');
		setTitle(wHnd,'Infiniti.com - 360 degree View');
	}
}

function setDivValue(wHnd,eDiv,value) {
	if (wHnd.document.getElementById(eDiv)) {
		wHnd.document.getElementById(eDiv).innerHTML = value;
	} else {
		setTimeout(function () { setDivValue(wHnd,eDiv,value); }, 500);
	}
}

function setTitle(wHnd,value) {
	if (wHnd.document.title) {
		wHnd.document.title = value;
	} else {
		setTimeout(function () { setTitle(wHnd,value); }, 500);
	}
}

//open a new, centered window to specified document
function _popit(sPth, sName, width, height) {
	var wHnd;
	wHnd = window.open(sPth, sName,
			   'width=' + width + ', height=' + height + 
			   ', menubar=false, scrollbars, top=' + (screen.height - height) / 2 + ', ' +
			   'left=' + (screen.width - width) / 2 );
	wHnd.focus();
	return wHnd;
}

function openFXScreensaver() {
	var wHnd;
	wHnd = _popit('/fx/screensaver.html', 'screensaver', 260, 300);		
}

function initEmbed(eDiv,sPath,sWidth,sHeight) {
	var sPlugins = "http://www.apple.com/quicktime/download/";
	eDiv.innerHTML = '<embed id="eEmbed" src="'+sPath+'" controller="TRUE" width="'+sWidth+'" height="'+sHeight+'" bgcolor="#ffffff" border="0" pluginspage="'+sPlugins+'"></embed>';
}
