var pokerwin = null;
var linkwin = null;
var aboutmewin = null;
var brandywin = null;
var chatwin = null;

var inmouseover = false;

function showBoxText(id) {
	new Effect.Appear(id, {
		duration:0.3
	});
}

function hideBoxText(id) {
	new Effect.Fade(id, {
		duration:0.3
	});
}

function showBrandyWindow() {
	if (brandywin != null) { 
		brandywin.toFront();
	} else { 
		brandywin= new Window({className:'mac_os_x', 
			title:'About Brandy', 
			top:190,
			left:340, 
			width:500,
			height:350, 
			url:'brandy.html', 
			destroyOnClose: true,
			showEffect:Effect.BlindDown, 
			hideEffect:Effect.BlindUp
			});
		brandywin.show(); 
			
		myObserver = { 
			onDestroy: function(eventName, win) { 
				if (win == brandywin) { 
					Windows.removeObserver(this);
					brandywin = null; 
				} 
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}

function showLinkWindow() {
	if (linkwin != null) { 
		linkwin.toFront();
	} else { 
		linkwin= new Window({className:'mac_os_x', 
			title:'Links and Downloads', 
			top:50,
			left:120, 
			width:500,
			height:350, 
			url:'links.html', 
			destroyOnClose: true,
			showEffect:Effect.BlindDown, 
			hideEffect:Effect.BlindUp
			});
		linkwin.show(); 
			
		myObserver = { 
			onDestroy: function(eventName, win) { 
				if (win == linkwin) { 
					Windows.removeObserver(this);
					linkwin = null; 
				} 
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}

function showChatWindow() {
	if (chatwin != null) { 
		chatwin.toFront();
	} else { 
		chatwin = new Window({className:'mac_os_x', 
			title:'Chat with Me', 
			top:120,
			left:500, 
			width:280,
			height:460, 
			resizable:false,
			url:'chat.html', 
			destroyOnClose: true,
			showEffect:Effect.BlindDown, 
			hideEffect:Effect.BlindUp
			});
		chatwin.show(); 
			
		myObserver = { 
			onDestroy: function(eventName, win) { 
				if (win == chatwin) { 
					Windows.removeObserver(this);
					chatwin = null; 
				} 
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}

function showPokerWindow() {
	if (pokerwin != null) { 
		pokerwin.toFront();
	} else { 
		pokerwin= new Window({className:'mac_os_x', 
			title:'Tarot Poker', 
			top:160,
			left:290, 
			width:500,
			height:350, 
			url:'poker.html', 
			destroyOnClose: true,
			showEffect:Effect.BlindDown, 
			hideEffect:Effect.BlindUp
			});
		pokerwin.show(); 
			
		myObserver = { 
			onDestroy: function(eventName, win) { 
				if (win == pokerwin) { 
					Windows.removeObserver(this);
					pokerwin = null; 
				} 
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}

function showAboutMeWindow() {
	if (aboutmewin != null) { 
		aboutmewin.toFront();
	} else { 
		aboutmewin = new Window({className:'mac_os_x', 
			title:'About Me', 
			top:110, 
			left:140, 
			width:500, 
			height:350,
			url:'aboutme.html',
			destroyOnClose: true,
			showEffect:Effect.BlindDown, 
			hideEffect:Effect.BlindUp
			});
		aboutmewin.show(); 
			
		myObserver = { 
			onDestroy: function(eventName, win) { 
				if (win == aboutmewin) { 
					Windows.removeObserver(this);
					aboutmewin = null; 
				} 
			} 
		} 
		Windows.addObserver(myObserver); 
	}
}


function autoOpenWindow() {
	var w = window.location.toString().toQueryParams().w;
	if (w) {
		switch (w) {
			case 'brandy':
				showBrandyWindow(); break;
			case 'about':
				showAboutMeWindow(); break;
			case 'link':
				showLinkWindow(); break;
			case 'chat':
				showChatWindow(); break;
			case 'poker':
				showPokerWindow(); break;
		}
	}
	return true;
}

function showGrowItem(obj) {
	$(obj.element).setStyle({top:'130px', left:'260px', display:'block'});
}

function showTheRest(obj) {
	$('nwbox').setStyle({top:'130px', left:'260px', display:'block'});
	$('nebox').setStyle({top:'130px', left:'260px', display:'block'});
	$('ebox').setStyle({top:'130px', left:'260px', display:'block'});
	$('sebox').setStyle({top:'130px', left:'260px', display:'block'});
	$('sbox').setStyle({top:'130px', left:'260px', display:'block'});
	$('swbox').setStyle({top:'130px', left:'260px', display:'block'});
	$('wbox').setStyle({top:'130px', left:'260px', display:'block'});
}

function moveBox(id, xamt, yamt) {
	new Effect.Move(id, {
		delay:3.0,
		duration:1.5,
		x:xamt,
		y:yamt
	});
}

function divAppear(id, delayamt) {
	new Effect.Appear(id, {
		delay:delayamt,
		duration:0.5
	});
}

function startAnims() {

	new Effect.Fade('throbber', {
		duration:0.5
	});

	new Effect.BlindDown('swoosh', {
		delay:0.5,
		duration:1.5		
	});

	new Effect.Appear('nbox', {
		delay:1.5,
		beforeSetup:showGrowItem,
		duration:1.5,
		afterFinish:showTheRest
	});

	moveBox('nwbox', -260, -130);
	moveBox('nbox',     0, -130);
	moveBox('nebox',  260, -130);
	moveBox('wbox',  -130,    0);
	moveBox('ebox',   130,    0);
	moveBox('swbox', -260,  130);
	moveBox('sbox',     0,  130);
	moveBox('sebox',  260,  130);
			
	divAppear('dlbox',      4.5);
	divAppear('tpbox',      4.7);
	divAppear('aboutbox',   4.9);
	divAppear('chatbox',    5.1);
	divAppear('brandybox',  5.3);

	divAppear('shinmalogo',  6.3); 

	autoOpenWindow.delay(6.8);
}

Event.observe(window, 'load', function() {
	startAnims();
	
	Event.observe('tpimg', 'click', showPokerWindow);
	Event.observe('linkimg', 'click', showLinkWindow);
	Event.observe('aboutmeimg', 'click', showAboutMeWindow);
	Event.observe('brandyimg', 'click', showBrandyWindow);
	Event.observe('chatimg', 'click', showChatWindow);
	
	Event.observe('tpimg', 'mouseover', function(e) {showBoxText('pokertxt');});
	Event.observe('linkimg', 'mouseover', function(e) {showBoxText('linktxt');});
	Event.observe('aboutmeimg', 'mouseover', function(e) {showBoxText('aboutmetxt');});
	Event.observe('brandyimg', 'mouseover', function(e) {showBoxText('brandytxt');});
	Event.observe('chatimg', 'mouseover', function(e) {showBoxText('chattxt');});
	
	Event.observe('tpimg', 'mouseout', function(e) {hideBoxText('pokertxt');});
	Event.observe('linkimg', 'mouseout', function(e) {hideBoxText('linktxt');});
	Event.observe('aboutmeimg', 'mouseout', function(e) {hideBoxText('aboutmetxt');});
	Event.observe('brandyimg', 'mouseout', function(e) {hideBoxText('brandytxt');});
	Event.observe('chatimg', 'mouseout', function(e) {hideBoxText('chattxt');});
});

