// global App class
var App = new function() {
  // init public scope
  this.root = '';
  this.helpers = {
	logOut : function() {
	  var btn = $('#logout');
	  var ht = $('html')[0]; 
	  if (btn.size()) {
		btn[0].onclick = function(e) {
		  ht.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)';  
		  if (confirm('Are you sure you want to log out?')) {
			return true;
		  } else {
			ht.style.filter = '';
			return false;
		  }
		};
	  }
	},
	
	loadFocus : function() {
	  var f = $('#loadfocus');
	  if (f.size()) {
		try {
		  f[0].focus();
		} catch (e) {};
	  }
	  return true;
	},
	
	confirmSave : function(m) {
	  return confirm('Are you sure you want to save' + (m.length ? ' ' : '') + m + '?\nConfirm all changes are correct before proceeding.');
	},	
	
	confirmDelete : function(m) {
	  return confirm('Are you sure you want to delete' + (m.length ? ' ' : '') + m + '?\nThis is cannot be reversed!');
	},
	
	confirmSend : function(m) {
	  return confirm('Are you sure you want to send' + (m.length ? ' ' : '') + m + '?');
	},
	
	confirmDefault : function(m) {
	  return confirm('Are you sure you want to' + (m.length ? ' ' : '') + m + '?');
	}	
  };
  
  this.init = function() {
	$(function() {
	  // get the root url
	  App.root = $('#logo a').attr('href');		   
			   
	  // init helpers
	  App.helpers.loadFocus();
	  App.helpers.logOut();
	  // init misc
	  App.initMisc();
	  
	  App.initInterface();
	});	  
  };
  this.initInterface = function () {
    var strip, pakkajacks;
	
	$('ul.lava').lavaLamp({ fx: 'easeOutBack', speed: 900 });
	
	try {
	  strip = new SWFObject(App.root + 'resources/flash/strip.swf', 'so-image-strip', '743', '110', '9');
	  strip.addParam('wmode', 'transparent');
	  strip.addParam('menu', 'false');		
	  strip.addVariable('xmlpath', App.root + 'resources/xml/strip.xml.cfm');
	  strip.write('image-strip');

	  pakkajacks = new SWFObject(App.root + 'resources/flash/pj.swf', 'so-pakkajacks', '195', '350', '9');
	  pakkajacks.addParam('wmode', 'transparent');
	  pakkajacks.write('pakkajacks');
	} catch (e) {};
  };
  this.initMisc = function () {
	// set click handlers
	$('.confirmsave').bind( 'click', function() { 
	  return App.helpers.confirmSave( this.title ); 
	});
	$('.confirmdelete').bind( 'click', function() { 
	  return App.helpers.confirmDelete( this.title ); 
	});
	$('.confirmsend').bind( 'click', function() { 
	  return App.helpers.confirmSend( this.title ); 
	});
	$('.confirmdefault').bind( 'click', function() { 
	  return App.helpers.confirmDefault( this.title ); 
	});	
	// set messages to show
	$('.message').hide().fadeIn(1500);
	// fix bg flicker in IE 6
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {};	  
  };
};
App.init();
