function createCookie(name,value) {
	document.cookie = name+"="+value+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=",ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

newClass('iconLink', 'FLImage');
	addVar('link', '');
	addMethod('inputDown', function() {
		window.open($('link'));
		return true;
	});
endClass();

var theContext;
window.onload= function() { theContext=newObject('FLContext', 'initAsBody', main); };
function main(context) {
	var mainWindow = newObject('FLWindow','initWithFrame', new FLRect(0,0,500,500));
	context.get('contentView').send('addSubview', mainWindow);
	mainWindow.send('centerWithOffset',0,0);
	var topBar = newObject('FLView', 'initWithFrame', new FLRect(0,-1,500,35));
	topBar.get('image').send('imageWithURL', (pyro.browser.isWebkit || pyro.browser.isGecko)?'images/ConstructionTop.png':'images/Construction.png');
	topBar.get('image').set('curve', new FLCurve(15,15,0,0));
	mainWindow.send('addSubview', topBar);
	var bottomBar = newObject('FLView', 'initWithFrame', new FLRect(0,465,500,35));
	bottomBar.get('image').send('imageWithURL', (pyro.browser.isWebkit || pyro.browser.isGecko)?'images/ConstructionBottom.png':'images/Construction.png');
	bottomBar.get('image').set('curve', new FLCurve(0,0,15,15));
	mainWindow.send('addSubview', bottomBar);
	var aTitle = newObject('FLLabel', 'initWithFrame', new FLRect(0,70,400,50));
	aTitle.set('text','Welcome to HTML5').set('textAlign', 'center').set('bold', true).set('fontSize', 24);
	mainWindow.send('addSubview', aTitle);
	aTitle.send('centerXWithOffset',0,0);
	var theMessage = newObject('FLLabel', 'initWithFrame', new FLRect(0,145,400,150));
	theMessage.set('text','This is a next generation web application framework based on HTML5.  It is still in the early alpha stages, but it\'s slowly progressing daily.').set('textAlign', 'center').set('textWrap', true).set('bold', true).set('fontSize', 18);
	mainWindow.send('addSubview', theMessage);
	theMessage.send('centerXWithOffset',0,0);
	var BrowserText = newObject('FLLabel', 'initWithFrame', new FLRect(0,290,450,20));
	BrowserText.set('text','To view properly, this page requires the browsers below:').set('textAlign', 'center').set('textWrap', true).set('bold', true).set('fontSize', 12);
	mainWindow.send('addSubview', BrowserText);
	BrowserText.send('centerXWithOffset',0,0);
	var SafariLink = newObject('iconLink', 'initWithURL', 'images/Safari.png');
	SafariLink.set('link', 'http://www.apple.com/safari/').set('frame', new FLRect(146.66,320,64,64));
	mainWindow.send('addSubview', SafariLink);
	var FirefoxLink = newObject('iconLink', 'initWithURL', 'images/Firefox.png');
	FirefoxLink.set('link', 'http://www.mozilla.com/en-US/firefox/firefox.html').set('frame', new FLRect(220,320,64,64));
	mainWindow.send('addSubview', FirefoxLink);
	var OperaLink = newObject('iconLink', 'initWithURL', 'images/Opera.png');
	OperaLink.set('link', 'http://www.opera.com/browser/next/').set('frame', new FLRect(294.66,320,64,64));
	mainWindow.send('addSubview', OperaLink);
	var blogButton = newObject('FLButton', 'initWithFrame', new FLRect(0,420, 96, 25));
	blogButton.get('label').set('text', 'Blog')
	blogButton.set('normalImage', newObject('FLImage', 'initWithURL', 'images/AquaButtonD.png')).set('mousedownImage', newObject('FLImage', 'initWithURL', 'images/AquaButtonDownD.png')).set('action', loadBlog);
	mainWindow.get('contentView').send('addSubview', blogButton);
	blogButton.send('centerXWithOffset',0,0);
	
	function changeText(ani) {
		if(ani.keyFrame == ani.keyFrames.length) {
			aTitle.send('animateText', 'Under Construction', 1.0, false); 
			BrowserText.send('animateValue', 'fontColor', new FLColor(0.3,0.3,0.3,1.0));
			SafariLink.send('animateValue', 'opacity', 1.0);
			FirefoxLink.send('animateValue', 'opacity', 1.0);
			OperaLink.send('animateValue', 'opacity', 1.0);
		} else if(ani.keyFrame == ani.keyFrames.length-1) {
			theMessage.send('animateValue', 'fontColor', new FLColor(0.3,0.3,0.3,1.0));
		}
	}
	
	if(!readCookie('loadblog') || readCookie('loadblog')=='false') {
		mainWindow.set('color', new FLColor(0.9,0.9,0.9,0.0));
		BrowserText.set('fontColor', new FLColor(0.3,0.3,0.3, 0.0));
		theMessage.set('fontColor', new FLColor(0.3,0.3,0.3,0.0));
		context.set('color', new FLColor(0.5,0.5,0.5,1.0));
		SafariLink.set('opacity', 0);
		FirefoxLink.set('opacity', 0);
		OperaLink.set('opacity', 0);
	
		var x=mainWindow.get('frame').origin.x, y=mainWindow.get('frame').origin.y,
		keyFrames = [new FLRect(x,y,500,500), new FLRect(x,y-35,500,500), new FLRect(x,y,500,500), new FLRect(x,y-15,500,500), new FLRect(x,y,500,500), new FLRect(x,y,500,500)],
		durations=[1,0.3,0.3,0.2,0.2,2],
		types=[FLAnimationLinear,FLAnimationSmooth,FLAnimationSmooth,FLAnimationSmooth,FLAnimationSmooth,FLAnimationLinear];
		mainWindow.set('frame', new FLRect(x,-500,500,500));
		mainWindow.send('keyFrameValue', 'frame', keyFrames, durations, types, function() {mainWindow.send('animateValue', 'color', new FLColor(0.9,0.9,0.9,1.0), 0.5);}, changeText);
	} else {
		createCookie('loadblog', 'false');
		aTitle.set('text', 'Under Construction'); 
		context.set('color', new FLColor(1.0,1.0,1.0,1.0));
		mainWindow.set('color', new FLColor(0.9,0.9,0.9,1.0));
		BrowserText.set('fontColor', new FLColor(0.3,0.3,0.3, 1.0));
		theMessage.set('fontColor', new FLColor(0.3,0.3,0.3,1.0));
		context.send('animateValue', 'color', new FLColor(0.5,0.5,0.5,1.0));
		
		var x=mainWindow.get('frame').origin.x, y=mainWindow.get('frame').origin.y, frame = new FLRect();
		frame = new FLRect(mainWindow.get('frame').origin.x,mainWindow.get('frame').origin.y,500,500);
		mainWindow.set('frame', new FLRect(frame.origin.x,document.body.clientHeight,500,500)).send('animateValue', 'frame', frame, 1.0);
	}	
	
	function loadBlog() {
		createCookie('loadblog', 'true');
		context.send('animateValue', 'color', new FLColor(1.0,1.0,1.0,1.0));
		mainWindow.send('animateValue', 'frame', new FLRect(mainWindow.get('frame').origin.x,document.body.clientHeight, mainWindow.get('frame').size.width, mainWindow.get('frame').size.height),1.0,undefined, function() { 
			window.location='http://www.granitw.net/objective/'; window.onunload = function() {};
			});
	}
}