/**
 * @author Jeffrey Brayne
 * @copyright 2009
 * This file may not be reproduced without explicit permission
 * Application.js was developed custom for Jeffrey L. Richards
 */

 
 var Application = Class.create();
 
 Object.extend(Application.prototype, {
 	
	version: 0.1,
	
	initialize: function(){
		this.g = {};
		this.kkeys = [];
		this.konami = "38,38,40,40,37,39,37,39,66,65";
		this.so = null;
		this.hotlink = "";
		this.growls = {
			"ceremonies" : {
				content: "The Fuzzpops perform on-site ceremonies for for free",
				title: "Ceremonies",
				sticky: false,
				className: '',
				life: 15
			},
			"horns" : {
				content: "The Fuzzpops offer a full horn section!!!",
				title: "Fuzzpops Horns",
				sticky: false,
				className: "",
				life: 15
			},
			"group" : {
				content: "We are a set group... well rehearsed and polished.",
				title: "A Set Group",
				sticky: false,
				className: "",
				life: 15
			},
			"virtuosic" : {
				content: "The Fuzzpops feature five lead vocalists, virtuosic musicians and a state-of-the-art sound system.",
				title: "Virtuosic Musicians",
				sticky: false,
				className: "",
				life: 15
			}
		};
	},
	
	go: function(id){
		if($(id)){
			if(app.hotlink !== "") $(app.hotlink).toggleClassName('hot');
			var id = (typeof id === "object") ? this.id : id;
			app.hotlink = $(id).toggleClassName('hot');
		}
		var params = {};
		params.url = 'lib/html/' + id + '.html';
		params.onSuccess = function(){
			$('content').show({duration:0.3});
		};
		params.div = "content";
		params.evalScripts = true;
		$('content').fade({
			duration: 0.3,
			afterFinish: function(){
				app.updater(params);
			}
		});
	},
		
	growl: function(growl){
		var growl = app.growls[growl];
		app.g.growl(growl.content, {
			header: growl.title,
			className: growl.className,
			sticky: growl.sticky,
			life: growl.life
		});
	},
	
	growler: function(){
		var growls = ['ceremonies', 'horns', 'group', ];
		var rnd = Math.floor(Math.random() * growls.length);
		app.growl(growls[rnd]);		
	},
	
	loadmap: function(id){
		$('content').innerHTML = $(id).innerHTML;
	},
		
	request: function(params){

		new Ajax.Request(params.url, {
			method: params.method || 'POST',
			evalJS: params.evalJS || false,
			evalJSON: params.evalJSON || false,
			parameters: params.params || null,
			onLoading: params.onLoading || null,
			onSuccess: params.onSuccess || function(res){ window.status = res.status },
			onFailure: params.onFailure || function(){ Controller.onFailure(); },
			onComplete: params.onComplete || null
		});
	},
		
	run: function(gallery){
		new PeriodicalExecuter(app.growler, 20);
		app.so = new SWFObject('lib/video/player-viral.swf','ply','420','290','9','#000000');
		app.so.addParam('allowfullscreen','true');
		app.so.addParam('allowscriptaccess','always');
		app.so.addParam('wmode','opaque');
		app.so.addVariable('image', 'lib/video/jeffsings.jpg');
		//app.so.addVariable('file', 'fuzzpopslive.mp4');
		app.g = new k.Growler({location: 'br'});
		app.setMenuLinks();
		//setTimeout("app.go('video')", 1000); //default page
		app.go('video');
		app.g.growl("Welcome and thanks for visiting! Please call us at (732) 901-0041.", {
			header: "The Fuzzpops Band!",
			className: "",
			life: 15
		});
		
		/* konami code easter egg */
		document.observe('keydown', function(e) {
			app.kkeys.push( e.keyCode );
			if (app.kkeys.toString().indexOf( app.konami ) >= 0 ){
				document.stopObserving('keydown',arguments.callee);
				app.go('disclaimer');
			}
		});
	},
	
	setMenuLinks: function(){
		$$('#menu li').each(function(g){
			$(g).observe('click', app.go)
		});
	},
	
	setLinks: function(cls, funktion){
		$$(cls).each(function(link){
			link.observe('click', function(){
				funktion(this, false);
			});
		})
	},
 			
	updater: function(params){
		/**
		 * @description generic interface into Ajax.Updater();
		 */
		var div = params.div || 'content';
		new Ajax.Updater(div, params.url, {
			method: params.method || 'POST',
			parameters: params.params || null,
			evalScripts: params.evalScripts || false,
			onLoading: params.onLoading || null,
			onSuccess: params.onSuccess || null,
			onFailure: params.onFailure || function(){},
			onComplete: params.onComplete || null
		});
	}
		
 });
