/*
 *  Log.js
 *  MerlinWeb
 *
 *  Created by Andreas Känner on 20.05.08.
 *  Copyright 2008 ProjectWizards. All rights reserved.
 *
 */

var LogAreaController = Base.extend({
	constructor: function(mainViews, logContainer, testLogContainer, currentLogContainer) {
		this.base();
		this.mainViews = mainViews;
		this.logContainer = logContainer;
		this.testLogContainer = testLogContainer;
		this.setCurrentLog(currentLogContainer);
		this.loggerWidth = parseInt(this.currentLog.style.width)+36;
		$$('.yui-log')[1].style.backgroundColor = '#eeffee';
	},
	
	isLogAreaVisible: function() {
		return parseInt(this.mainViews[0].style.right) == this.loggerWidth;
	},
	
	setCurrentLog: function(log) {
		this.currentLog = log;
		var visible = this.isLogAreaVisible() ? true : false;
		if(this.currentLog == this.logContainer) {
			this.logContainer.style.display = visible ? '' : 'none';
			this.testLogContainer.style.display = 'none';
		}else{
			this.testLogContainer.style.display = visible ? '' : 'none';
			this.logContainer.style.display = 'none';			
		}
	},
	
	toggleLogArea: function() {
		var right = this.isLogAreaVisible() ? 6 : this.loggerWidth;
		for(var i=0; i<this.mainViews.length; i++)
			this.mainViews[i].style.right = right+"px";
		this.setCurrentLog(this.currentLog);
	},

	toggleLog: function() {
		this.setCurrentLog(this.currentLog == this.logContainer ? this.testLogContainer : this.logContainer);
	},
	
	clearVisibleLog: function() {
		if(this.currentLog.id == 'logger')
			logger.clearConsole();
		else if(this.currentLog.id == 'testLogger') {
			YAHOO.tool.TestRunner.clear();
			testLogger.clearConsole();
		}
	}
	
});
var logAreaController = new LogAreaController($$('.mainView'), $('logger'), $('testLogger'), $('testLogger'));

function runUnitTests() {
	if(tests) {
		tests.run();
	}
}

var guiTestActive = false;

function startGUITest() {
	if(guiTest)
		guiTest.run(function() {
			$('guiTestButton').innerHTML = "&gt;";
			$('guiTestButton').style.color = "#0a0";
			guiTestActive = false;
		});
	guiTestActive = true;
}

function stopGUITest() {
	if(guiTest)
		guiTest.stop();
	guiTestActive = false;
}

function toggleGUITest() {
	var button = $('guiTestButton');
	if(!guiTestActive) {
		button.innerHTML = "||";
		button.style.color = "#f00";
		startGUITest();
	}else{
		button.innerHTML = "&gt;";
		button.style.color = "#0a0";
		stopGUITest();
	}
}