
/*	---------------------------------------------------------------------------
	CLASS:		Layout(el[,columns])
	AUTHOR:		Ryan J. Salva, http://www.capitolmedia.com
	LICENSE:	MIT License, <http://en.wikipedia.org/wiki/MIT_License>	
	REVISED:	January 2008
	EXAMPLE:	<div id="Wrapper"><div id="Left">Foo</div><div id="Right">Bar</div></div>
				var x = new Layout('Wrapper',['Left','Right']);
	ABOUT:		Utility function designed to fix any layout using aboslute positioning for each column
				Adjusts the page to make wrapper as tall as the highest column (left, right, etc.)
				Most Capitol Media websites use the column ids: Left, Right, Middle and Canvas	
*/

var Layout = new Class({
	initialize: function(el,columns){
		this.columns = columns;
		this.el = $(el);
		if (!$defined(this.el)) return false;
		
		this.el.setStyle('overflow','hidden');
		this.columns.each(function(col,index) {
			this.columns[index] = $(col);
		}.bind(this));
		this.columns = this.columns.clean();
		this.el.set('tween', {duration: 100});
		this.periodical = this.update.bind(this).periodical(200);
	},
	update: function() {
		var y = 0;
		this.columns.each(function(col,index) {
			var h = col.getCoordinates().height;
			if(h > y) y = h;
		});
		this.el.tween('height',y);
	}
});


/*	---------------------------------------------------------------------------
	CLASS:		Element
	METHOD:		fix();
	ABOUT:		Fixes alpha transparency in IE6
	REVISED:	February 27, 2008
*/

Element.implement({
	fix: function(){
		if(!Browser.Engine.trident) return this;
		var src;
		var size = this.getSize();
		if(this.get('tag')=='img'){
			src = this.get('src');
			if(src.indexOf('.png') < 0) return this;
			this.set('src', '/site/x.gif');
		} else {
			var bg = this.getStyle('background-image');
			if(bg && bg!='none')
				src = bg.match(/\(([^)]+)\)/)[1];
			if(src.indexOf('.png') < 0) return this;
		}
		if (src) {
			if(this.getStyle('display')=='inline' && !['input', 'textarea', 'button'].contains(this.get('tag'))) {
				this.setStyles({
					'display': 'block',
					'width': size.x,
					'height': size.y
				});
			}
			this.setStyles({
				'background': '',
				'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", src="'+src+'", sizingMethod="crop")'
			});
		}
		return this;
	}
});
if(Browser.Engine.trident4) window.addEvent('domready', function() {
	$$('img[src$=png]').fix();
});



//	---------------------------------------------------------------------------
//	CLASS:		Menu()
//	AUTHOR:		Ryan J. Salva
//	REVISED:	December 2007
//
//	Creates a drop-down menu for navigation. Also Corrects Windows IE support 
//	for LI:hover and adds an <IFRAME> behind drop-down menus to keep the 
//	menu above <SELECT> elements.
//
//	REQUIREMENTS:
//	Styles found in default.css
//	
//	TESTED IN:
//	Windows: IE 6, Firefox 1, Opera 8
//	Mac: IE 5.2, Firefox 1, Safari 1

var Menu = new Class({
	Implements: Options,
	options: {
		iframe: false,
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(el,options){
		this.el = $(el);
		if (!$defined(this.el)) return false;
		this.setOptions(options);
		
		this.el.getElements('li').each(function(li,index) {
			li.addEvent('mouseenter',function() {
				this.addClass('hover');
			});
			li.addEvent('mouseleave',function() {
				this.removeClass('hover');
			});
		});
		if (this.options.iframe) this.addIframe();
	},
	addIframe: function() {
		this.el.getElements('ul').each(function(ul,index) {
			var coord = ul.getCoordinates();
			var iframe = new Element('iframe',{'src':'about:blank','styles':{
				overflow:'hidden',
				border:0,
				width: coord.width,
				height: coord.height,
				left: 0,
				top: 0,
				zIndex: -10,
				opacity: 0
			}});
			iframe.injectTop(ul);
			ul.setStyle('z-index',99);
		});
	}
});



//	---------------------------------------------------------------------------
//	CLASS:		FormTip(selector,options)
//	AUTHOR:		Ryan J. Salva
//	REVISED:	December 2008

var FormTip = new Class({
	Implements: Options,
	options: {
		className: 'FormTip',
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(selector,options){
		this.setOptions(options);
		this.els = $$(selector);
		this.els.each(function(el,index){
			el.addEvent('focus',this.show.bindWithEvent(this));
			el.addEvent('blur',this.hide.bindWithEvent(this));
		}.bind(this));
	},
	show: function(e) {
		var e = new Event(e);
		var el = e.target;
		if ($type(el) != 'element') return false;
		var title = el.getAttribute('title');
		if (!$defined(title)) return false;
		var pos = el.getPosition(el.getOffsetParent());
		var width = el.getWidth();
		this.tip = new Element('div',{'class':this.options.className,'styles':{
			opacity: 0,
			position: 'absolute',
			left: pos.x + width,
			top: pos.y
		}}).setText(title);
		this.tip.inject(el.getParent(),'inside');
		this.tip.tween('opacity',1); 
	},
	hide: function() {
		this.tip.remove();
	}
});


//	---------------------------------------------------------------------------
//	CLASS:		Ticker()
//	AUTHOR:		Ryan J. Salva
//	REVISED:	January 2008
//

var Ticker = new Class({
	Implements: Options,
	options: {
		speed: 1000,
		delay: 5000,
		direction: 'vertical',
		onComplete: Class.empty,
		onStart: Class.empty
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		if (this.items.length <= 0) return false;
		var w = 0;
		var h = 0;
		if(this.options.direction.toLowerCase()=='horizontal') {
			h = this.el.getCoordinates().height;
			this.items.each(function(li,index) {
				w += li.getCoordinates().width;
			});
		} else {
			w = this.el.getCoordinates().width;
			this.items.each(function(li,index) {
				h += li.getCoordinates().width;
			});
		}
		this.el.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w,
			height: h
		});
		this.fx = new Fx.Morph(this.el,{duration:this.options.speed,onComplete:function() {
			var i = (this.current==0)?this.items.length:this.current;
			this.items[i-1].injectInside(this.el);
			this.el.setStyles({
				left:0,
				top:0
			});
		}.bind(this)});
		this.current = 0;
		this.next();
	},
	next: function() {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		var pos = this.items[this.current];
		this.fx.start({
			top: -pos.offsetTop,
			left: -pos.offsetLeft
		});
		this.next.bind(this).delay(this.options.delay+this.options.speed);
	}
});
