var onload_functions = {
		welcome:function(){
			var welcome_fx = new Fx.Styles($('welcome_img'),{
				duration:1500,
				wait:false,
				onComplete:function(){
					show_birthdate(),show_maintxt()
				}
			});
			var start_fx = function(){
				welcome_fx.start({
					'width':'300px',
					'left':'100px'
				});
			}
			var maintxt_fx = new Fx.Styles($$('#maintxt img')[0],{
				duration:1300,
				wait:false,
				onComplete:function(){
					maintxt_fx.start({
						'height':'115px',
						'width':'350px',
						'top':'0px',
						'left':'0px'
					});
				}
			})
			var show_maintxt = function(){
				maintxt_fx.start({
					'height':'5px',
					'width':'5px',
					'top':'-120px',
					'left':'0px'
				});
			}
			var birthdate_fx = new Fx.Styles($$('#birthdate img')[0],{
				duration:800,
				wait:false,
				onComplete:function(){
					birthdate_fx.start({
						'height':'500px',
						'width':'500px',
						'top':'0px',
						'left':'0px'
					});
				}
			})
			var show_birthdate = function(){
				birthdate_fx.start({
					'height':'25px',
					'width':'25px',
					'top':'-10px',
					'left':'0px'
				});
			}
			
			start_fx.delay(1500);
		},
		philosophy:function(){
			new sliding_tabs($('philosophy').getElements('.phil_menu_item'),$('philosophy').getElements('.phil_body'),{
				active_tab_class:'active_item',
				tab_margin_left:'30px',
				tab_margin_right:'30px',
				container_reposition: true,
				container:'container',
				offset:-100,
				outer_container:'window'
			});
		},
// talisman function
italisman:function(){
			var italisman_fx = new Fx.Styles($('italisman_img'),{
				duration:10,
				wait:false,
				onComplete:function(){
					show_rtalisman()
				}
			});
			var start_fx = function(){
				italisman_fx.start({
					'width':'5px',
					'left':'-200px'
				});
			}
			var rtalisman_fx = new Fx.Styles($$('#rtalisman img')[0],{
				duration:3000,
				wait:false,
				onComplete:function(){
					rtalisman_fx.start({
						'height':'500px',
						'width':'500px',
						'top':'0px',
						'left':'0px'
					});
				}
			})
			var show_rtalisman = function(){
				rtalisman_fx.start({
					'height':'1px',
					'width':'1px',
					'top':'0px',
					'left':'0px'
				});
			}
			
			start_fx.delay(500);
		}
	};

function load(){
	remove_dotted_outlines();
	
	var new_top_nav = (window.getHeight()-$('navigation_container').getStyle('height').toInt()-100)/2;
	new_top_nav = new_top_nav < 0?'100px':new_top_nav+'px';
	$('navigation_container').setStyle('top',new_top_nav);
	var new_top_cont = (window.getHeight()-400)/2;
	new_top_cont = new_top_cont < 0?'100px':new_top_cont+'px';
	$('container').setStyle('top',new_top_cont);
	$('outer_container').setStyle('display','block');
	
	init_navigation();
	var start_content = 'welcome';
	
	var _arg = document.location.href.split(/\?/);
	if(_arg[1])
		_arg = _arg[1].split(/=/);
	if(_arg[1])
		start_content = _arg[1];
		
	replace_content(start_content);
}

function loadgall(){
	remove_dotted_outlines();
	
	var new_top_nav = (window.getHeight()-$('navigation_container').getStyle('height').toInt()-100)/2;
	new_top_nav = new_top_nav < 0?'100px':new_top_nav+'px';
	$('navigation_container').setStyle('top',new_top_nav);
	var new_top_cont = (window.getHeight()-400)/2;
	new_top_cont = new_top_cont < 0?'100px':new_top_cont+'px';
	$('container').setStyle('top',new_top_cont);
	$('outer_container').setStyle('display','block');
	
	init_navigation();
	var start_content = 'gall';
	
	var _arg = document.location.href.split(/\?/);
	if(_arg[1])
		_arg = _arg[1].split(/=/);
	if(_arg[1])
		start_content = _arg[1];
		
	replace_content(start_content);
}

function replace_content(elm_name){
	//resize and position
	if($$('#content div')[0])
		$('content').setStyle('height',$$('#content div')[0].getStyle('height'));
	else
		$('content').setStyle('height',0);
	var content_fx = new Fx.Style($('content'),'height',{
		'duration':800,
		'transition':Fx.Transitions.Back.easeOut,
		'onComplete':function(){
			$('content').effect('opacity',{duration:300}).start(1);
			$('content').setStyle('height','auto');
		}
	});
	var container_fx = new Fx.Style($('container'),'top',{duration:800});
	var navigation_fx = new Fx.Style($('navigation_container'),'top',{duration:800});
	
	//fade out
	$('content').effect('opacity',{
		'duration':300,
		'onComplete':function(){
			//replace content
			//$('content').empty();
			$('content').setHTML('');
			var new_el = $(elm_name+'_hidden').clone();
			new_el.setProperty('id',elm_name);
			new_el.injectInside($('content'));
			if(onload_functions[elm_name])
				onload_functions[elm_name]();
				
			//reposition and fade in
			var new_top = (window.getHeight()-$$('#content div')[0].getStyle('height').toInt()-100)/2;
			content_fx.start($$('#content div')[0].getStyle('height'));
			container_fx.start(new_top+'px');
			
			var nav_top = (window.getHeight()-$('navigation_container').getStyle('height').toInt()-100)/2;
			navigation_fx.start(nav_top+'px');
		}
	}).start(0);
}
//initialize navigation buttons
function init_navigation(){
	var buttons = [];
	var timer = 100;
	$$('.link_img').each(function(el,i){
		buttons.extend([new link_button(el,$$('.link_text')[i],$$('.link_shadow')[i],i%2==0)])
		el.setStyles({
			'display':'block',
			'top':(buttons[i].img_top.toInt()+buttons[i].dim.toInt()/2)+'px',
			'left':(buttons[i].img_left.toInt()+buttons[i].dim.toInt()/2)+'px'
		});
		buttons[i].onload_fx.delay(timer,buttons[i]);
		timer+=200;
	});
	$$('.link_text').each(function(el,i){
		el.addEvent('mouseenter',buttons[i].mouse_enter.bind(buttons[i]));
		el.addEvent('mouseleave',buttons[i].mouse_leave.bind(buttons[i]));
		el.addEvent('mousedown',buttons[i].mouse_leave.bind(buttons[i]));
		el.addEvent('mouseup',buttons[i].mouse_enter.bind(buttons[i]));
	});
}

var link_button = new Class({
	initialize : function(image,text,shadow,odd){
		this.dim = '95px';
		this.pos = {
			'top' : image.getStyle('top'),
			'left': image.getStyle('left')
		};
		this.font_size = text.getStyle('font-size');
		this.image = image;
		this.text = text;
		this.offset=-2;
		if(odd){
			this.offset=2;
		}
		this.text_top = text.getStyle('top').toInt();
		this.text_left = text.getStyle('left').toInt();
		this.shadow = shadow;
		this.img_top = image.getStyle('top');
		this.img_left = image.getStyle('left');
		this.image_fx = new Fx.Styles(this.image,{duration:500,wait:false});
		this.snap_fx = new Fx.Styles(this.image,{duration:1500,wait:false,transition:Fx.Transitions.backOut});
		this.text_fx = new Fx.Styles(this.text,{duration:300,wait:false});
		this.font_size = this.text.getStyle('font-size');
		this.text_position = {
			top:this.text.getStyle('top'),
			left:this.text.getStyle('left')
		}
		this.image.makeDraggable({
			'onComplete':function(){
			this.snap_fx.start(this.pos)
			}.bind(this)
		});
	},
	onload_fx : function(){
		this.image_fx.start({
			'height':[0,this.dim],
			'width':[0,this.dim],
			'left':this.img_left,
			'top':this.img_top
		})
	},
	mouse_enter : function(){
		this.text_fx.start({
			'top':(this.text_top - 2)+'px',
			'left':(this.text_left + this.offset)+'px'
		});
	},
	mouse_leave : function(){
		this.text_fx.start({
			'top':this.text_top+'px',
			'left':this.text_left+'px'
		});
	}
});

//removes dotted outlines from links
function remove_dotted_outlines(){
	$$('a').each(function(el,i){
		el.addEvent('mousedown',function(e){
			this.blur();
		    this.hideFocus = true;
		});
		el.addEvent('mouseout',function(e){
			this.blur();
		    this.hideFocus = false;
		});
		el.addEvent('mouseup',function(e){
			this.blur();
		    this.hideFocus = false;
		});
	});
}