var cloud_r_direction = 'left';
var cloud_l_direction = 'right';
var speed = 100;


var sky = function(){	
	handleTheSky();	
	var timer = setInterval('moveClouds()', speed);
}

var handleTheSky = function handleTheSky(){
	var sun = document.getElementById('sun');
	var x = findPosition(sun)[0];
	if(window.size().width < 1000){
		sun.style.left = '500px';
		sun.style.right = 'auto';
	}
	else{	
		sun.style.left = 'auto';
		sun.style.right = '0';
	}
}

function moveClouds(){
	moveLeftCloud();
	moveRightCloud();
}

function moveLeftCloud(){
	var c = document.getElementById('cloud_l');
	var cx = findPosition(c)[0];
	if(document.getElementById('index_rightbox')) var right_bumper = findPosition(document.getElementById('index_rightbox'))[0]-200;
	else var right_bumper = window.size().width - 300;
	if(cx > right_bumper) cloud_l_direction = 'left';
	if(cx < 2) cloud_l_direction = 'right';
	if(cloud_l_direction == 'left')	c.style.left = cx-1 +'px';
	else c.style.left = cx+1 +'px';
}

function moveRightCloud(){
	var c = document.getElementById('cloud_r');
	var cx = findPosition(c)[0];
	if(document.getElementById('index_rightbox')) var left_bumper = findPosition(document.getElementById('index_rightbox'))[0]+40;
	else var left_bumper = 0;	
	c.style.right = 'auto';
	if(cx < left_bumper) cloud_r_direction = 'right';
	if(cx > (window.size().width - 230)) cloud_r_direction = 'left';
	
	if(cloud_r_direction == 'left'){
		c.style.left = cx-1 +'px';
	}
	else{
		c.style.left = cx+1 +'px';
	}	
}

