var resizeWinOnce=false;

function browserOk()
{
	// Check which browser is being used.
	// Exclude Opera because of problems getting the site to display properly under any version.
	// Exclude versions of Explorer and Netscape earlier than 4 because of lack of full support for javascript and style sheets.
	// First check for the Opera browser.
	// navigator.appName will return either Navigator or Microsoft Explorer - depending on the version.
	// Need to check if the word 'Opera' is contained in the navigator.userAgent string instead.
	var browserOk=true;
	if (navigator.userAgent.indexOf('Opera',0) > -1) browserOk=false;
	else if (navigator.userAgent.indexOf("MSIE")>-1) // Microsoft Explorer
	{
		var versionPos=navigator.userAgent.indexOf('MSIE')+5;
		if (parseInt(navigator.userAgent.substring(versionPos)) <5) browserOk=false;
	}
	else if (navigator.appName=="Netscape" && parseInt(navigator.appVersion) < 5) browserOk=false;
	return browserOk;
}

function setWindowSize()
{
	var resizeWindow=false;
	if (window.outerWidth) // used by Netscape and Mozilla
	{
		if (window.outerWidth<800 || window.innerHeight<425) resizeWindow=true;
	}
	else if (document.body.offsetWidth) // used by Explorer
	{
		if (document.body.offsetWidth<800 || document.body.offsetHeight<430) resizeWindow=true;
	}
	else self.resizeWinOnce=true; // prevent repeat calling.
	
	if (resizeWindow)
	{
		if (window.screenX) // Netscape and Mozilla
		{
			var xPos=window.screenX;
			var yPos=window.screenY;
			var minPosition=-4; // Netscape's top left position is -4,-4 , not 0,0
		}
		else if (window.screenLeft) // Explorer
		{
			var xPos=window.screenLeft;
			var yPos=window.screenTop-114; // screenTop gives the top position of the inner window - ie. exluding title and menu bar etc.
			var minPosition=0;
		}

		var newWidth=Math.min(window.screen.availWidth,800);
		var newHeight=Math.min(window.screen.availHeight,572);
		var moveWindow=false;
		if (xPos<minPosition)
		{
			xPos=minPosition;
			moveWindow=true;
		}
		else if (xPos+newWidth> window.screen.availWidth)
		{
			xPos=window.screen.availWidth-newWidth;
			moveWindow=true;
		}
		
		if (yPos<minPosition)
		{
			yPos=minPosition;
			moveWindow=true;
		}
		else if (yPos+ newHeight > window.screen.availHeight)
		{
			yPos=window.screen.availHeight-newHeight;
			moveWindow=true;
		}
		
		if (moveWindow) moveTo(xPos,yPos);
		resizeTo(newWidth,newHeight);
		self.resizeWinOnce=true;
	}
}

function resizeOnce()
{
	// Called by the onResize event handler in the body of the main windows. Included to deal with the possibility that the window restore button is
	// selected when the window is currently maximised. If the previous 'restore' size is too small for the site, this function sets it to the 'correct'
	// size. The 'resizeWinOnce' variable is then set to true to enable the user to adjust the size if required.
	if (!self.resizeWinOnce) setWindowSize();
}

function setUp()
{
	setWindowSize();
	var displayLocation="startup.php"; // default url to replace blank.html in DisplayData frame.
	if (top.showOrderOption) // returning to site after a failed credit / debit card transaction.
	{
		top.orderBy=0; // set order option to card.
		displayLocation="order_opt_frame.html";
	}
	else if (self.location.search)
	{
		if (self.location.search.indexOf("c1i") > -1) displayLocation="wall-clocks-1-images.html";
		else if (self.location.search.indexOf("c1d") > -1) displayLocation="wall-clocks-1-design.html";
		else if (self.location.search.indexOf("c2i") > -1) displayLocation="wall-clocks-2-images.html";
		else if (self.location.search.indexOf("c2d") > -1) displayLocation="wall-clocks-2-design.html";
		else if (self.location.search.indexOf("ld") > -1) displayLocation="table-lamps-design.html";
		else if (self.location.search.indexOf("li") > -1) displayLocation="table-lamps-images.html";
		else if (self.location.search.indexOf("vd") > -1) displayLocation="wooden-vases-design.html";
		else if (self.location.search.indexOf("vi") > -1) displayLocation="wooden-vases-images.html";
		else if (self.location.search.indexOf("sb") > -1) // skittles buy
		{
			top.currentSkittleImage=8;
			displayLocation="table-skittles.html";
		}
		else if (self.location.search.indexOf("sh") > -1) // skittles history
		{
			top.currentSkittleImage=7;
			displayLocation="table-skittles.html";
		}
		else if (self.location.search.indexOf("sd") > -1) // skittles design
		{
			top.currentSkittleImage=6;
			displayLocation="table-skittles.html";
		}
		else if (self.location.search.indexOf("sr") > -1) // skittles rules
		{
			top.currentSkittleImage=5;
			displayLocation="table-skittles.html";
		}
		else if (self.location.search.indexOf("si") > -1) // skittles images
		{
			top.currentSkittleImage=0;
			displayLocation="table-skittles.html";
		}
		else if (self.location.search.indexOf("lf") > -1) displayLocation="info_lin_frame.html";
		else if (self.location.search.indexOf("sm") > -1) displayLocation="sitemap.html";
		else if (self.location.search.indexOf("fb") > -1) displayLocation="contact.html";
		else if (self.location.search.indexOf("ad") > -1) displayLocation="info_artdeco_frame.html";
	}
	top.DisplayData.location.replace(displayLocation);
}

