Object.extend(Event, {
  _domReady : function() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;

    if (this._timer)  clearInterval(this._timer);
    
    this._readyCallbacks.each(function(f) { f() });
    this._readyCallbacks = null;
},
  onDOMReady : function(f) {
    if (!this._readyCallbacks) {
      var domReady = this._domReady.bind(this);
      
      if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", domReady, false); 
        
        /*@cc_on @*/
        /*@if (@_win32)
            document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
            document.getElementById("__ie_onload").onreadystatechange = function() {
                if (this.readyState == "complete") domReady(); 
            };
        /*@end @*/
        
        if (/WebKit/i.test(navigator.userAgent)) { 
          this._timer = setInterval(function() {
            if (/loaded|complete/.test(document.readyState)) domReady(); 
          }, 10);
        }
        
        Event.observe(window, 'load', domReady);
        Event._readyCallbacks =  [];
    }
    Event._readyCallbacks.push(f);
  }
});


var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }};

var ThinkTekLabs = new Class.create();
ThinkTekLabs = {
	initialize : function(){

	},
	
	calcLeft : function(el, add){
		var ret =  $(el).offsetLeft + add;
		return ret.toString();
	},
	
	calcTop : function(el, add){
		
		var ret =  $(el).offsetTop + add;
		return ret.toString();
	},
	
	
	
	puffElement : function(el, o){
		
		Element.setStyle(el,{left:ThinkTekLabs.calcLeft('mainCanvas',o.leftAdd) + 'px'});
		Element.setStyle(el,{top:ThinkTekLabs.calcTop('mainCanvas',o.topAdd) + 'px'});
		Effect.Appear(el,{duration: 2.0});
		setTimeout(function(){Effect.Fade(el,{duration: 2.5})},2000);	
	},
	
	
	showFinal : function(){
		
		Element.makePositioned('mainCanvas');

		setTimeout(function(){
		Element.setStyle('worldOf',{left:ThinkTekLabs.calcLeft('mainCanvas',270) + 'px'});
		Element.setStyle('worldOf',{top:ThinkTekLabs.calcTop('mainCanvas',144) + 'px'});
		Effect.Appear('worldOf',{duration: 3.5});
		}, 500);

		setTimeout(function(){
		Element.setStyle('learnMore',{left:ThinkTekLabs.calcLeft('mainCanvas',360) + 'px'});
		Element.setStyle('learnMore',{top:ThinkTekLabs.calcTop('mainCanvas',240) + 'px'});
		Effect.Appear('learnMore',{duration: 3.5});
		}, 1250);		
		
	},
	
	showIntro : function(){
		Element.makePositioned('mainCanvas');
		
		setTimeout(function(){
			ThinkTekLabs.puffElement('imagine', {leftAdd:400,topAdd:100});
			
		}, 500);
		
		setTimeout(function(){
			ThinkTekLabs.puffElement('create', {leftAdd:310,topAdd:275});	
		}, 2500);
		
		setTimeout(function(){
			ThinkTekLabs.puffElement('discover', {leftAdd:380,topAdd:125});	
		}, 4800);		

		setTimeout(function(){
			ThinkTekLabs.puffElement('invent', {leftAdd:350,topAdd:200});	
		}, 7000);			
		
		
		setTimeout(function(){
		Element.setStyle('worldOf',{left:ThinkTekLabs.calcLeft('mainCanvas',270) + 'px'});
		Element.setStyle('worldOf',{top:ThinkTekLabs.calcTop('mainCanvas',144) + 'px'});
		Effect.Appear('worldOf',{duration: 3.5});
		}, 10000);

		setTimeout(function(){
		Element.setStyle('learnMore',{left:ThinkTekLabs.calcLeft('mainCanvas',360) + 'px'});
		Element.setStyle('learnMore',{top:ThinkTekLabs.calcTop('mainCanvas',240) + 'px'});
		Effect.Appear('learnMore',{duration: 3.5});
		}, 10700);		

	},
	
	
	hookMain : function(){

        Event.onDOMReady(function(){
		ThinkTekLabs.showIntro();
		/*
	        if (Cookie.get('TTLIntro')!='complete'){
	        ThinkTekLabs.showIntro();
	        Cookie.set('TTLIntro','complete',1);
	        }
	        else
	        {
		        ThinkTekLabs.showFinal();
	        }
		*/
        });

        Event.observe(window,'resize', function(e){
		    Element.setStyle('worldOf',{left:ThinkTekLabs.calcLeft('mainCanvas',270) + 'px'});
		    Element.setStyle('worldOf',{top:ThinkTekLabs.calcTop('mainCanvas',144) + 'px'});
		    Element.setStyle('learnMore',{left:ThinkTekLabs.calcLeft('mainCanvas',360) + 'px'});
		    Element.setStyle('learnMore',{top:ThinkTekLabs.calcTop('mainCanvas',240) + 'px'});	
		});

	}
};