// dead-bones.com JavaScript @ 2008 contreforme sàrl
var _pops,_popready;
function raiseTheDeads(){
	// intro animations
	if($('logger')) var deadTransition = new Fx.Transition(Fx.Transitions.Bounce,3);
	if(!location.search && (window.ie7 || !window.ie)){
		var bannerFx	= new Fx.Styles($('banner'),{duration:600,transition: deadTransition.easeInOut}).set({
			'height':434,
			'margin-top':0,
			'padding-top':0,
			'opacity':0
		});
		var menuFx		= new Fx.Styles($('menu'),{duration:600,transition: deadTransition.easeInOut}).set({
			'opacity':0
		});
		var contentFx	= new Fx.Styles($('content'),{duration:600,transition: deadTransition.easeInOut}).set({
			'opacity':0
		});
		var footerFx	= new Fx.Styles($('footer'),{duration:600,transition: deadTransition.easeInOut}).set({
			'opacity':0
		});
		
		bannerFx.start({
			'opacity':1
		}).chain(function(){
			menuFx.start({
				'opacity':1
			}).chain(function(){
				contentFx.start({
					'opacity':1
				}).chain(function(){
					footerFx.start({
						'opacity':1
					}).chain(function(){
						bannerFx.options.transition = Fx.Transitions.Cubic.easeOut;
						bannerFx.start({
							'padding-top':132,
							'margin-top':-132,
							'height':150
						})
					});
				});
			});
		});
		_deadBanner = true;
	}
	
	// set target _blank to external links
	$each($$('#site a'),function(element) {
		if(element.getAttribute('rel') == 'external'){
			element.setAttribute('target','_blank');
		}
	});
}
function pop(source,type,w,h,id){
	if(!_pops.contains(source) && _popready){
		_pops.include(source);
		_popready = false;
		var img,x,y;
		
		img = new Element('img',{
			'id':'imgbox',
			'alt':'',
			'width':1,
			'height':1,
			'src':source,
			'style':{
				'opacity':0
			}
		}).inject($('site'));
		
		var imgFx = new Fx.Styles(img,{duration:500,transition: Fx.Transitions.Cubic.easeInOut});
		
		img.addEvent('click',function(ev){
			var ev = new Event(ev).stop();
			imgFx.start({
				'width':1,
				'height':1,
				'opacity':0
			}).chain(function(){
				img.remove(); // bye bye img
				_pops.remove(source);
				_popready = true;
			});
		});
		
		x = Math.ceil((window.getHeight()-h)/2)+window.getScrollTop();
		y = Math.ceil((window.getWidth()-w)/2)+window.getScrollLeft();
		if(x<0) x = 10;
		if(y<0) y = 10;
	
		imgFx.start({
			'top':x,
			'left':y,
			'width':w,
			'height':h,
			'opacity':1
		});
	}
	return false;
}
window.addEvent('domready', function(){
	_pops = [];
	_popready = true;
	raiseTheDeads();
});