 

function getWinSize(win) 
{ 
    if(!win) win = window; 
    var s = new Object(); 
    if(typeof win.innerWidth != 'undefined') 
    { 
        s.width = win.innerWidth; 
        s.height = win.innerHeight; 
    } 
    else 
    { 
         var obj = getBody(win); 
         s.width = parseInt(obj.clientWidth); 
         s.height = parseInt(obj.clientHeight); 
    } 
    return s; 
} 

function getBody(w) 
{ 
    return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null; 
} 

var setupToolTips = function(){
	$('animation').getElements('img').hide();
	$('tops').destroy();
	$('pyramid').destroy();
	$('fullPyramid').show();
	//store titles and text
	$$('.tipArea').each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
		element.removeProperty('title');
		element.addEvents({
			mouseenter: function(){
				$('tipLayer').show();
				$('tip-title').set('html', this.retrieve('tip:title'));
				$('tip-text').set('html', this.retrieve('tip:text'));
			},
			mouseleave: function(){
				// Morphes back to the original style
				$('tipLayer').hide();
			},
			mousemove : function(e){
				$('tipLayer').setStyle("left", e.event.clientX + 5).setStyle("top", e.event.clientY + 5);
			}
		});

	});
	
	//create the tooltips
	var tipz = new Tips('.tipz',{className: 'tipLayer',fixed: false,hideDelay: 50,showDelay: 50
});
	


}

var showTops = function(){
	
	$('top1Img').show().get('tween', {property: 'opacity'}).start(1).chain(
	 function(){
		$('top2Img').show().get('tween', {property: 'opacity'}).start(1).chain(
		function(){
		      $('top3Img').show().get('tween', {property: 'opacity'}).start(1).chain(
		      function(){
				setupToolTips();
		      })
		})	
	});
	      
}

var checkVisibility = function(){
	var top = $('pyramidTrigger').getCoordinates().top;
	var height = $(document).getScroll().y + getWinSize().height;
	if(true || height >= top){
		$(document).removeEvent("scroll", checkVisibility);
				
		$('bottomImg').show().get('tween', {property: 'opacity'})
				.start(1).chain(function(){
			$('leftImg').show().get('morph').start(
					{
						'height': 148,
						'width': 221,
						'left': 54
			});
			$('rightImg').show().get('morph').start(
					{
						'height': 148,
						'width': 223,
						'left': -1
			}).chain(function(){
				$('middleImg').show().get('morph').start({'height': 105,'width': 274, 'left':138}).chain(
					function(){
						$('circleImg').show().get('tween', {property: 'opacity'})
						  .start(1).chain(function(){
						    $('lowerhalfImg').show().fade('in');
						    $('upperhalfImg').show().fade('in');
						    showTops();
						});
					}
				);
				$('topImg').show().get('morph').start({'height': 133,'width': 153, 'left': (550 - 153) / 2, 'top' : -1});
			});
		});
		return true;
	}
	return false;
}; 




window.addEvent('domready',function() {
	$('animation').getElements('img').hide();
	$('bottomImg').fade('out');
	$('circleImg').fade('out');
	$('lowerhalfImg').fade('out');
	$('upperhalfImg').fade('out');	
	$('tops').getElements('img').fade('out');
	$('leftImg').get('morph').set({	'height': 147,'width': 0,});
	$('rightImg').get('morph').set({'height': 147,'width': 0,'left': 274});
	$('middleImg').get('morph').set({	'height': 0,'width': 548, 'position' :'absolute', 'bottom': 0});
	$('topImg').get('morph').set({'height':0,'position':'absolute', 'top':0, 'width':548});
	$('animation').setStyle('visibility', 'visible');
	attachToScroll = function(){
		if(checkVisibility() == false){
			$(window).addEvent("scroll", checkVisibility);
		}
	};

	attachToScroll.delay(1000);
});