window.addEvent('domready', function(){
	// Setup the homepage rotator
	if ($('home_banner')) {
		var frames = $('home_banner').getElements('.slide_nav a.frame-link');
		new TIControlledRotator(frames, $('home_banner'), {
			duration: 3.75,
			transition: Fx.Transitions.Quad.easeOut,
			fade_duration: 2.5,
			frame_class: 'slide',
			controls: {
				play_on_jump: true,
				buttons: {
					'play': $('home_banner').getElement('.play_pause_button'),
					'next': null,
					'prev': null
				}
			}
		});
	}
	if ($('landing_slideshow')) {
		var frames = $('landing_slideshow').getElements('.slide_nav a.frame-link');
		new TIControlledRotator(frames, $('landing_slideshow'), {
			duration: 3.75,
			transition: Fx.Transitions.Quad.easeOut,
			fade_duration: 2.5,
			frame_class: 'slide',
			controls: {
				play_on_jump: true,
				buttons: {
					'play': $('landing_slideshow').getElement('.play_pause_button'),
					'next': null,
					'prev': null
				}
			}
		});
	}
	
	//Some logic to get values on the fields for Billing into Shipping when 'Shipping same as Billing' is selected, Remove if unselected
	
	function matchField (field_ID){
		billing_field = field_ID;
		shipping_field = billing_field.replace("billing", "shipping");
		return $(shipping_field);
	}
	
	//Here is where all begins when you click "Same as Billing":
	if ($('same_as_billing')){
		$('same_as_billing').addEvent('click', function(){
			if ($('same_as_billing').getProperty('checked')){
				//Get the inputs and select fields from Billing:
				$('billing').getChildren().each(function(ele){
				
					//Check if it is input or if it select:
					if (ele.match('input')){
						shipping_f = matchField(ele.getProperty('id'));
						shipping_f.setProperty('value', ele.getProperty('value'));
					} else if (ele.match('select')){
						// Else should be select field so we need to get the option fields that are selected in Billing and pass it to Shipping
						selected = ele.getSelected();
						shipping_f = matchField(ele.getProperty('id'));
						shipping_f.getChildren().each(function(el){
							if (el.getProperty('value')==selected.getProperty('value')){
								el.setProperty('selected','selected');
							}
						});
					}
				})
			}
		});
	}
	
	//Add inactive arrows
	if (!$('home_banner')){
		if ($$('.main_slider').length != 0){
			$$('.main_slider').each(function(el){
				prev = el.getChildren('div.prev');
				next = el.getChildren('div.next');
				if (prev.length == 0){
				//	inactivePrev = new Element('div',{class: "prev-inactive"});
				//	inactivePrev.inject(el);
				}
				if (next.length == 0){
				//	inactiveNext = new Element('div',{class: "next-inactive"});
				//	inactiveNext.inject(el);
				}
			});
		}
	}
});


