// Mootools

var stars = 0;
var timeoutstate;
window.addEvent('domready', function() {
	$('menu_home').addEvent('click',          function(){ window.location = '/';        });
	$('menu_news').addEvent('click',          function(){ window.location = '?news';        });
	$('menu_ref').addEvent('click',           function(){ window.location = '?references';  });
	$('menu_asbestos').addEvent('click',      function(){ window.location = '?asbestos';    });
	$('menu_services').addEvent('click',      function(){ window.location = '?services'     });
	$('menu_regulations').addEvent('click',   function(){ window.location = '?regulations'  });
	$('menu_contact').addEvent('click',       function(){ window.location = '?contact'      });
	$('also_see').addEvent('click',           function(){ window.location = 'http://www.southwestrolloff.com/'        });
	//$('cloud1').addEvent('click',             function(){ destroy_cloud();        });

	
	
	//animate_clouds();
	
	
	$('sky_night').setStyle('opacity', 0);
	$('sky_day').setStyle('opacity', 1);
	$('sun').setStyle('margin-top', 25);
	$('moon').setStyle('margin-top', 130);
	
	$('sun').addEvent('click', function(){
		var day_night_cookie = Cookie.write('night', '1');
		animate_stars();
		if($('sky_night').getStyle('opacity').toInt() == 0) {
			$('sun').setStyle('z-index', 3);
			$('sun').set('tween', {duration: 'long', onComplete: function(){
				$('sky_night').set('tween', {duration: 'long'});
				$('sky_night').tween('opacity', [0, 0.9]);
				$('moon').set('tween', {duration: 'long', onComplete: function(){
					$('moon').setStyle('z-index', 6);
				}});
				$('moon').tween('margin-top', [130, 14]);
			}});
			$('sun').tween('margin-top', [25, 130]);
		}
	});
	
	
	$('moon').addEvent('click', function(){
		var day_night_cookie = Cookie.write('night', '0');
		if($('sky_night').getStyle('opacity').toFloat() == 0.9) {			
			$('moon').setStyle('z-index', 3);
			$('moon').set('tween', {duration: 'long', onComplete: function(){
				$('sky_night').set('tween', {duration: 'long'});
				$('sky_night').tween('opacity', [0.9, 0]);
				$('sun').set('tween', {duration: 'long', onComplete: function(){
					$('sun').setStyle('z-index', 6);
				}});
				$('sun').tween('margin-top', [130, 25]);

			}});
			$('moon').tween('margin-top', [14, 130]);
		}
	});
	
	

})

function animate_stars() {
		if(stars == 199) { stars = 0;	} else { stars++; }
		$('sky_night').setStyle('background-position', stars + "px " + 0 + "px");
		setTimeout("animate_stars()", 256);
}
var position = 695;
var direction = 1;
function animate_clouds() {
	var cloud_position = $('cloud1').getStyle('margin-left').toInt();
	//var window_size = $('real_body').getSize();
	if(direction == 1) {
		if(cloud_position < 980) {
			position = position + 2;	
			$('cloud1').setStyle('margin-left', position + "px");
			direction = 1;
		} else {
			direction = 0;	
		}
	} else { 
		if(cloud_position > - 106) {
			position = position - 2;	
			$('cloud1').setStyle('margin-left', position + "px");
			direction = 0;
		} else {
			direction = 1;	
		}
	}
	setTimeout("animate_clouds()", 256);
}

function destroy_cloud() {
	$('cloud1').fade(0);
}

