Event.observe(window, 'load', function() {
	
	var base_url = 'http://64.27.21.106/~starfurn/wp-content/themes/star/';
	
	/* Homepage Hero */
	$$('#circle_links a').each(function(el) {
		
		Event.observe(el, 'click', function(e) {
			
			// slide effect for sale hero
			var offset = el.previousSiblings().size() * 583;
					
			new Effect.Move($('slide'), {
				x: -offset,
				duration: .5,
				mode: 'absolute'
			});
			
			resetLinks();

			el.down().src = base_url+'images/circle_link_on.png';
			
			// fade effect for sale hero
			/*new Effect.Opacity($$('#callouts_left img').first(), { 
				from: 1,
				to: 0,
				duration: 0.5,
				afterFinish: function() {
					$$('#callouts_left img').first().src = el.href;
					
					resetLinks();

					el.down().src = 'images/circle_link_on.png';
					
					new Effect.Opacity($$('#callouts_left img').first(), { 
						from: 0,
						to: 1,
						duration: 0.5
					});
				}
			});*/
			
			Event.stop(e);
		});
		
	});
	
	function resetLinks() {
		$$('#circle_links img').each(function(el) {
			el.src = base_url+'images/circle_link.png';
		});
	}
	
	/* Bottom slider */
	var animating = false;
	
	var num_clicks = 0; // using number of clicks since the logos are not controlled in the CMS
	
	var logos_width = 0;
	
	$$('#logos_images img').each(function(el) {
		logos_width += (parseInt(el.getStyle('width')) + 15); // TODO not sure why this has to be 5 more than the margin of 10
	});
	
	$('logos_images').setStyle({
		width: logos_width+'px'
	});
	
	$('right_arrow').observe('click', function(e) {
		if (animating) {
			Event.stop(e);
		} else {
			if (num_clicks < 8) {
				new Effect.Move($('logos_images'), {
					x: -300,
					duration: .5,
					mode: 'relative',
					beforeStart: function() {
						animating = true;
					},
					afterFinish: function() {
						animating = false;
					}
				});
				
				num_clicks++;
			}
			
			Event.stop(e);
		}
	});
	
	$('left_arrow').observe('click', function(e) {
		if (animating) {
			Event.stop(e);
		} else {
			if (parseInt($('logos_images').getStyle('left')) < 0) {
				new Effect.Move($('logos_images'), {
					x: 300,
					duration: .5,
					mode: 'relative',
					beforeStart: function() {
						animating = true;
					},
					afterFinish: function() {
						animating = false;
					}
				});
				
				num_clicks--;
			}

			Event.stop(e);
		}
	});
	
	// subscribe form
	$('subscribe').observe('focus', function(e) {
		this.value = '';
	});
	
  	$('subscribe').observe('blur', function(e) {
		if (this.value == '') {
			this.value = 'Email Address';
		}
	});
});
