window.onload = homeFx;

function homeFx()
{
	//Main Item Hover
	var buttons = $$('.block a');
	var buttonFx = new Fx.Elements( buttons, { wait: false, duration: 1000, unit: 'em', transition:Fx.Transitions.Circ.easeOut } );
	buttons.each( function( button, i ) {
		button.addEvent( 'mouseenter' , function( e ) {
			var obj = {}
			obj[i] = {
				'bottom': [button.getStyle( 'bottom' ).toFloat(), 1]
			};
			buttons.each( function( other, j ) {
				if( other != button ) {
					var mt = other.getStyle( 'bottom' ).toFloat();
					if( mt != 0 )
						obj[j] = { 'bottom': [mt, 0] };
				}
			});
			buttonFx.start( obj );
		});
	});
	
	if( $('main_items') ) {
		$('main_items').addEvent( 'mouseleave', function( e ) {
			var obj = {}
			buttons.each( function( other, j ) {
				obj[j] = { 'bottom': [other.getStyle( 'bottom' ).toFloat(), 0] };
			});
			buttonFx.start( obj );
		});
	}
		
	var qbuttons = $ES('.quote');
	var qbuttonFx = new Fx.Elements( qbuttons, { wait: false, duration: 550, unit: 'em', transition:Fx.Transitions.Circ.easeOut } );
	qbuttons.each( function( button, i ) {
		button.addEvent( 'mouseenter' , function( e ) {
			var obj = {};
			var bg = button.getStyle( 'background-color' );
			if('transparent' == bg){
				bg = 'ffffff';
			}
			obj[i] = {
				'background-color': [bg, '8c0000'],
				'text-indent': [button.getStyle( 'text-indent' ).toFloat(), 1]
			}
			qbuttons.each( function( other, j ) {
				if( other != button ) {
					var mt = other.getStyle( 'text-indent' ).toFloat();
					if( mt != 0 ) {
						obj[j] = {
							'background-color': [button.getStyle( 'background-color' ), '004f8c'],
							'text-indent': [mt, 0]
						}
					}
				}
			});
			qbuttonFx.start( obj );
		});
	});
	
	if( $('main_items') ) {
		$('main_items').addEvent( 'mouseleave', function( e ) {
			var obj = {}
			qbuttons.each( function( other, j ) {
				obj[j] = {
					'background-color': [other.getStyle( 'background-color' ), '004f8c'],
					'text-indent': [other.getStyle( 'text-indent' ).toFloat(), 0 ]
				}
			});
			qbuttonFx.start( obj );
		});
	}
	
	if( $( 'other_types' ) ) {
		$( 'other_types' ).addEvent( 'click', function() {
			if($( 'hidden_types' ))
				$( 'hidden_types' ).setStyle( 'display', 'block' ).effect( 'height', { duration: 350, unit: 'em', transition:Fx.Transitions.Circ.easeOut } ).start( 6 );
		});
	}
	
}

window.addEvent( 'domready', function () {
	new SmoothScroll();
} );

function fixIeDropDown(select){
	var select = (typeof select == "string") ? document.getElementById(select) : select;

	// THIS FUNCTION IS ONLY CONCERNED WITH INTERNET EXPLORER NON-MULTIPLE SELECT NODES THAT HAVE A SPECIFIC WIDTH DEFINED
	if(!select.attachEvent || navigator.userAgent.indexOf("Opera") > -1 || select.multiple || select.currentStyle.width == "auto") { return; }

	var body = document.getElementsByTagName("body").item(0);

	var si = select.selectedIndex;

	var clone = select.cloneNode(true);
	clone.style.position = "absolute";
	clone.style.visibility = "hidden";
	clone.style.width = "auto";
	body.appendChild(clone);

	clone._initialOffsetWidth = select.offsetWidth;
	clone._initialOffsetHeight = select.offsetHeight;
	clone._autoWidth = clone.offsetWidth;

	clone = body.removeChild(clone);
	clone.style.visibility = "visible";
	clone.style.width = clone._initialOffsetWidth + "px";

	var span = document.createElement("span");
	span._isIeDropDownContainer = true;
	span.style.position = "relative";
	span.style.width = clone._initialOffsetWidth + "px";
	//span.style.height = clone._initialOffsetHeight + "px";
	//span.style.fontSize = "2em";
	span.style.height = "1em";
	span.style.marginBottom = span.style.height; //hmm...quirky...
	span.innerHTML = '&nbsp;';
	span.appendChild(clone);

	if (select.parentNode._isIeDropDownContainer){
		select.parentNode.parentNode.replaceChild(span, select.parentNode);
	}else{
		select.parentNode.replaceChild(span, select);
	}

	if (clone._autoWidth > clone._initialOffsetWidth){
		var expand = function(){
			event.srcElement.parentNode.style.zIndex = 1;
			event.srcElement.style.width = "auto";
			if (event.srcElement.offsetWidth > event.srcElement._initialOffsetWidth){
				event.srcElement.style.width = "auto";
			}else{
				event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
			}
		};
		var contract = function(){
			event.srcElement.parentNode.style.zIndex = 0;
			event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
		};
		clone.attachEvent("onactivate", expand);
		clone.attachEvent("ondeactivate", contract);
	}
	clone.selectedIndex = si;
}
