
var loadFlash = function() {
	
	var flashFrame = new Element('div', {id: 'testFlash'});
	flashFrame.inject($('flash_frame'), 'top');
	
	var oSize = window.getSize();
	
	// Load flash
	var obj = new Swiff('http://www.profinvest.com.au/assets/flash/many_colours/Colours.swf', {
		container: flashFrame,
		width: oSize.x,
		height: oSize.y,
		params: {
			wmode: 'opaque',
			bgcolor: '#000000',
			scale: 'noScale'
		},
		vars: {
			flashVarText: 'External Text'
		}
	});
	
}

var loadSmallFlash = function() {
	
	var flashFrame = new Element('div', {id: 'testFlash'});
	flashFrame.inject($('flash_frame'), 'top');
	
	var oSize = window.getSize();
	
	// Load flash
	var obj = new Swiff('http://www.profinvest.com.au/assets/flash/many_colours/Corner.swf', {
		container: flashFrame,
		width: 60,
		height: 60,
		params: {
			wmode: 'transparent',
			bgcolor: '#000000',
			scale: 'noScale'
		},
		vars: {
			flashVarText: 'External Text'
		}
	});
	
}

/*
A screen which starts in the top right corner
and can be expanded to fill the window
(blocking all other content)
*/
var foldScreen = new Class({

	initialize: function(oScreen, strImgClosed, strImgOpen) {
		this.oScreen = oScreen;
		this.strImgClosed = strImgClosed;
		this.strImgOpen = strImgOpen;
		
		// initial state: closed
		this.state = 0;
		// Set background
		//this.oScreen.setStyle('background', '#000 url('+this.strImgClosed+') no-repeat bottom left');
		this.oScreen.setStyle('cursor', 'pointer');
		
		// Initial dimensions
		var oSize = oScreen.getSize();
		this.initHeight = oSize.y;
		this.initWidth = oSize.x;
		
		var parent = this;
		
		// Create Morpher
		this.myFx = new Fx.Morph(
			this.oScreen,
			{
				duration: 400,
				transition: Fx.Transitions.Cubic.easeOut,
				onComplete: function() { parent.morphComplete() }
			}
		);
		
	},
	
	morphComplete: function() {
		if(this.state == 1) {
			
			// Load flash into frame
			var flashFrame = new Element('div', {id: 'testFlash'});
			flashFrame.inject(this.oScreen, 'top');
			
			flashFrame.addEvent('click', function() {
				event.cancelBubble = true;
			});
			
			var oSize = window.getSize();
			
			// Load flash
			var obj = new Swiff('http://www.profinvest.com.au/assets/flash/many_colours/Colours.swf', {
				container: flashFrame,
				width: oSize.x,
				height: oSize.y,
				params: {
					wmode: 'opaque',
					bgcolor: '#000000',
					scale: 'noscale'
				},
				vars: {
					flashVarText: 'External Text'
				}
			});
			
		} else {
		
			var flashFrame = new Element('div', {id: 'testFlash'});
			flashFrame.inject($('flash_frame'), 'top');
			$('flash_frame').setStyle('background', '');
			
			var oSize = window.getSize();
			
			// Load flash
			var obj = new Swiff('http://www.profinvest.com.au/assets/flash/many_colours/Corner.swf', {
				container: flashFrame,
				width: 60,
				height: 60,
				params: {
					wmode: 'transparent',
					bgcolor: '#000000',
					scale: 'noscale'
				},
				vars: {
					flashVarText: 'External Text'
				}
			});
		
		}
	},
	
	toggleScreen: function() {
		if(this.state == 0) {
			this.fillScreen();
			//alert('Opening');
			//this.oScreen.setStyle('background', '#000 url('+this.strImgOpen+') no-repeat bottom left');
			this.state = 1;
		} else {
			this.closeScreen();
			//alert('Closing');
			//this.oScreen.setStyle('background', '#000 url('+this.strImgClosed+') no-repeat bottom left');
			this.state = 0;
		}
	},
	
	fillScreen: function() {
		var winDim = window.getScrollSize();
		
		this.myFx.start({
			'height': [this.initHeight, winDim.y],
			'width': [this.initWidth, winDim.x]
		});
	},
	
	closeScreen: function() {
		var winDim = window.getScrollSize();
		
		this.myFx.start({
			'height': [winDim.y, this.initHeight],
			'width': [winDim.x, this.initWidth]
		});
	}

});

/////////////////////
// Wrapper functions called by Flash ExternalInterface
function CloseColourFrame() {
	$('flash_frame').empty();
	myScreen.toggleScreen();
}

function OpenColourFrame() {
	$('flash_frame').empty();
	$('flash_frame').setStyle('background', '#000');
	myScreen.toggleScreen();
}

// Handle fscommands from flash
function Corner_DoFSCommand(command, args) {
 alert(command);	
 if (command == "OpenColourFrame") {
 	OpenColourFrame();
 }
 
 if (command == "CloseColourFrame") {
 	CloseColourFrame();
 }
}
/////////////////////

var windowSize = function() {
	var winDim = window.getScrollSize();
	$("window_size").innerHTML = winDim.x+", "+winDim.y;
}

var viewSize = function() {
	var winDim = window.getSize();
	$("view_size").innerHTML = winDim.x+", "+winDim.y;
}

window.addEvent('domready', function() {
	
	myScreen = new foldScreen($('flash_frame'), 'corner.jpg', 'corner_dn.jpg');
	
	loadSmallFlash();
	// Add event listener
	/*
	$('flash_frame').addEvent('click', function() {
		if(myScreen.state != 1) {
			this.empty(); // remove any child nodes before tweening
			myScreen.toggleScreen();
		}
	});*/
	
	// Check / write cookie
	var coloursDisplayed = Cookie.read('PIS_COLOURS_DISPLAYED');
	
	if(coloursDisplayed == null) {
		OpenColourFrame();
		// set cookie so this is not displayed again
		var coloursDisplayedCookie = Cookie.write('PIS_COLOURS_DISPLAYED', true, {duration: 365});
	}
	
});