var Site = {
	init: function(){
		Site.hideNavs();
		Site.hideNavs_2();
		// Site.makeOptionSlider();
		// Site.fontResizer();
		//only do this on pages that have sub-navigation
		// if($('content').getFirst().getTag() == "ul"){
		// 	Site.subNavOvers();
		// }
		//Site.fontChanger();
		// if($('content').hasClass("form")){
		//	Site.submitForm();
		//	Site.textareaSizer();
		//}
	},
	start:function(){
		Site.appearText();
		Site.appearText_2();
		//Site.optionsDrop();
	},
	hideNavs:function(){
		$$('#tab_left ul li').each(function(el){
			el.setStyle('marginLeft', '135px');
		});
	},
	hideNavs_2:function(){
		$$('#tab_top ul li').each(function(el){
			el.setStyle('marginTop', '40px');
		});
	},
	makeOptionSlider:function(){
		//hide the tab so it can animate later
		$('opener').setStyle('marginTop', '-40px');
		//make the options menu slide out when clicked
		var slideOpts = new Fx.Slide('options', {duration: 500, transition:Fx.Transitions.Circ.easeOut});
		slideOpts.hide();
		var moveButton = new Fx.Style('opener','top', {duration: 500, transition:Fx.Transitions.Circ.easeOut});
		$('opener').addEvent('click',function(ev){
			new Event(ev).stop();
			slideOpts.toggle();	
			if($('opener').getStyle('top') == $('options').getStyle('height')){
				moveButton.start(0);
			}else{
				moveButton.start($('options').getStyle('height'));
			}
		});
	},
	fontChanger:function(){
		//add clicks
		$('changeVerdana').addEvent('click', function() {
			Cookie.set("font-family", "verdana"); //save this for 1 year
			$('container').setStyle('font-family','Verdana, Arial, Helvetica, sans-serif');
		});
		$('changeGeneva').addEvent('click', function() {
			Cookie.set("font-family", "geneva"); //save this for 1 year
			$('container').setStyle('font-family','Geneva, Arial, Helvetica, sans-serif');
		});
		$('changeGeorgia').addEvent('click', function() {
			Cookie.set("font-family", "georgia"); //save this for 1 year
			$('container').setStyle('font-family','Georgia, "Times New Roman", Times, serif');
		});
		//check for a cookie and set the style
		if(Cookie.get("font-family") == "geneva"){
			$('container').setStyle('font-family','Geneva, Arial, Helvetica, sans-serif');
		}else if(Cookie.get("font-family") == "georgia"){
			$('container').setStyle('font-family','Georgia, "Times New Roman", Times, serif');
		}else{
			//do nothing, leave default
		}
	},
	fontResizer:function(){
		//resize the font to different pixel values
		 var resize = new Fx.Style('container', 'font-size', {duration: 1000});
		$('fontLarge').addEvent('click', function() {
			resize.start(13);
			Cookie.set("font-size", "large"); //save this for 1 year
		});
		$('fontMed').addEvent('click', function() {
			resize.start(11);
			Cookie.set("font-size", "medium"); //save this for 1 year
		})
		$('fontSmall').addEvent('click', function() {
			resize.start(9);
			Cookie.set("font-size", "small"); //save this for 1 year
		})
		//check for font size cookie
		if(Cookie.get("font-size") == "large"){
			resize.set(13);
		}else if(Cookie.get("font-size") == "small"){
			resize.set(9);
		}else{
			//do nothing, leave default
		}
	},
	subNavOvers: function(){		
		var normalSize=10, smallSize=5, fullSize=20;
		var subnavs = $$("#subnav li a");
		var fx = new Fx.Elements(subnavs, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
		subnavs.each(function(sublink, i) {
			sublink.addEvent("mouseenter", function(event) {
				var pad = {};
				pad[i] = {
					paddingRight: [sublink.getStyle("paddingRight").toInt(), fullSize],
					paddingLeft: [sublink.getStyle("paddingLeft").toInt(), fullSize]
					}
				subnavs.each(function(other, j) {
					if(i != j) {
						var pr = other.getStyle("paddingRight").toInt();
						var pl = other.getStyle("paddingLeft").toInt();
						if(pl != smallSize) pad[j] = {
							paddingLeft: [pl, smallSize],
							paddingRight: [pr, smallSize]
						};
					}
				});
				fx.start(pad);
			});
		});
		 
		$("subnav").addEvent("mouseleave", function(event) {
			var pad = {};
			subnavs.each(function(sublink, i) {
				pad[i] = {
					paddingRight: [sublink.getStyle("paddingRight").toInt(),normalSize],
					paddingLeft: [sublink.getStyle("paddingLeft").toInt(), normalSize]
				}
			});
			fx.start(pad);
		})
	},
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#tab_left ul li');
		var slidefxs = [];
		sideblocks.each(function(el, i){
			timer += 200;
			slidefxs[i] = new Fx.Style(el, 'marginLeft', {
				duration: 600,
				transition: Fx.Transitions.backOut,
				wait: true
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 10);

		}, this);
		
		//Over animations for main navigation
		var normalSize=0, smallSize=10, fullSize= -9;
		var navs = $$("#tab_left ul li a");
		var fx = new Fx.Elements(navs, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
		navs.each(function(navlink, i) {
			navlink.addEvent("mouseenter", function(event) {
				var change = {};
				change[i] = {
					// color: [navlink.getStyle("color"), navOverColor],
					marginLeft: [navlink.getStyle("marginLeft").toInt(), fullSize]
					}
				navs.each(function(other, j) {
					if(i != j) {
						var col = other.getStyle("color");
						var ml = other.getStyle("marginLeft").toInt();
						if(ml != smallSize) change[j] = {
							marginLeft: [ml, smallSize],
							color: [col, "#FFFFFF"]
						};
						
					}
				});
				fx.start(change);
			});
		});
		$$("#tab_left ul").addEvent("mouseleave", function(event) {
			var change = {};
			navs.each(function(navlink, i) {
				change[i] = {
					color: [navlink.getStyle("color"),"#cccccc"],
					marginLeft: [navlink.getStyle("marginLeft").toInt(), normalSize]
				}
			});
			fx.start(change);
		});
	},
	// #######################################################
	appearText_2: function(){
		var timer = 0;
		var topblocks = $$('#tab_top ul li');
		var slidefxt = [];
		topblocks.each(function(el, i){
			timer += 200;
			slidefxt[i] = new Fx.Style(el, 'marginTop', {
				duration: 600,
				transition: Fx.Transitions.backOut,
				wait: true
			});
			slidefxt[i].start.delay(timer, slidefxt[i], 10);

		}, this);
		
		//Over animations for main navigation
		var normalSize=0, smallSize=10, fullSize= -9;
		var navs = $$("#tab_top ul li a");
		var fx = new Fx.Elements(navs, {wait: false, duration: 300, transition: Fx.Transitions.Back.easeOut});
		navs.each(function(navlink, i) {
			navlink.addEvent("mouseenter", function(event) {
				var change = {};
				change[i] = {
					// color: [navlink.getStyle("color"), navOverColor],
					marginTop: [navlink.getStyle("marginTop").toInt(), fullSize]
					}
				navs.each(function(other, j) {
					if(i != j) {
						var col = other.getStyle("color");
						var ml = other.getStyle("marginTop").toInt();
						if(ml != smallSize) change[j] = {
							marginTop: [ml, smallSize],
							color: [col, "#FFFFFF"]
						};
						
					}
				});
				fx.start(change);
			});
		});
		$$("#tab_top ul").addEvent("mouseleave", function(event) {
			var change = {};
			navs.each(function(navlink, i) {
				change[i] = {
					color: [navlink.getStyle("color"),"#5a5a5a"],
					marginTop: [navlink.getStyle("marginTop").toInt(), normalSize]
				}
			});
			fx.start(change);
		});
	},
	// ###########################################################
	optionsDrop: function(){
		dropIn = new Fx.Style('opener', 'marginTop', {
			duration: 300,
			transition: Fx.Transitions.Circ.easeOut,
			wait: true
		});
		//workaround for z-index bug in firefox/mootools
		//and IE6 for not supporting position:fixed;
		if(!window.gecko && !window.ie6){
			$('opener').setStyle('position','fixed');
			$('options').setStyle('position','fixed');
			$('container').setStyle('position','absolute');
		}
		dropIn.start.delay(2000, dropIn, 0);
	},
	submitForm: function(){
		$('form').addEvent('submit', function(e) {
			//Prevent the submit event
			new Event(e).stop();
			var response = $('response').empty().addClass('ajax-loading').setStyle('height',$('form').getStyle('height'));
			this.send({
				update: response,
				evalScripts:true,
				onComplete: function() {
					response.removeClass('ajax-loading');
				}
			});
		});
	},
	textareaSizer: function(){
		//options
		tbResizeAmount = 50;				//amount each button press will resize by
		tbResizeDuration = 700;				//how long each resize takes
		tbResizeTransition = Fx.Transitions.Expo.easeOut; //the transition :P
		tbMinSize = 75; 					//always leave a min size or it looks strange
		tbMaxSize = 400;					//set to 0 for no maximum
		tbDescription = 'textbox size: ';	//text to display next to the buttons
		tbSkipClass = 'nogrow';				//a class defined on textareas that you do NOT want to resize
		
		//make new arrays of elements
		tbEffects = [];
		tbGrowers = [];
		tbShrinkers = [];
		
		//select each textarea without the class to skip
		$$('textarea').each(function(el,i){
			if (!el.hasClass(tbSkipClass)){
				Site.makeButtons(el,i);
			}					 					 
		});
	},
	makeButtons: function(textbox,i){
		//create the elements
		wrapper = new Element('div').addClass('tbSizeChanger').setStyle('width',textbox.getStyle('width')).injectAfter(textbox);
		tbGrowers[i] = new Element('a').setStyles({'float':'right','display':'block'}).setProperty('href','#').addClass('tbLarger').injectInside(wrapper).setHTML('+');
		tbShrinkers[i] = new Element('a').setStyles({'float':'right','display':'block'}).setProperty('href','#').addClass('tbSmaller').injectInside(wrapper).setHTML('-');
		new Element('div').addClass('tbSizeText').setHTML(tbDescription).setStyle('float','right').injectInside(wrapper);
		new Element('div').setStyle('clear','both').injectInside(wrapper);
		//create new effect
		tbEffects[i] = new Fx.Style(textbox, 'height', {duration: tbResizeDuration ,transition: tbResizeTransition});
		//add click events
		tbGrowers[i].addEvent('click', function(ev){
			new Event(ev).stop();
			toSize = textbox.getStyle('height').toInt()+tbResizeAmount;
			if(toSize >= tbMaxSize && tbMaxSize !=0){
				tbEffects[i].start(tbMaxSize);
			}else{
				tbEffects[i].start(toSize);
			}
		});
		tbShrinkers[i].addEvent('click', function(ev){
			new Event(ev).stop();
			toSize = textbox.getStyle('height').toInt()-tbResizeAmount;
			if(toSize <= tbMinSize){
				tbEffects[i].start(tbMinSize);
			}else{
				tbEffects[i].start(toSize);
			}
		});
	}
};
window.addEvent('domready', Site.init);
window.addEvent('load', Site.start);