//var xPos = new Array();
var yPos = new Array(0,0,0);
var arrows = new Array();
var arrow_count = 2;
var speed =  new Array(20,6,6);
var sky = '';
w = window.innerWidth;
h = window.innerHeight;

small_arrow = '/assets/images/elements/smallarrow.png';
big_arrow = '/assets/images/elements/bigarrow.png';

adjust = new Array();
adjust[0] = 900; // top astronot
adjust[1] = 300; // 2nd ast
adjust[2] = 100; // bunny
adjust[3] = 20; // zooman
adjust[4] = 350; // small zooman 2
adjust[5] = 330; // small zooman
adjust[6] = 300; // santa
adjust[7] = 10;  // fountain
adjust[8] = 240; // hi billy


function place(){
    bin = document.getElementById('landing-bin')
    images = bin.getElementsByTagName('img')
    h = window.innerHeight;
    for(i=0; i<images.length; i++){
        if((h-(adjust[i]+images[i].height)) > 0){
            images[i].style.top = (h - (adjust[i] + images[i].height)) + 'px';
        }
    }

    w = window.innerWidth;
    for(i=1; i<arrows.length+1;i++){
        arrows[i].style.left = (Math.random()*200+(w-w/3))+'px';
    }
}

function init(){
    place();
    $("#landing-bin").fadeIn(3000);   
    $("#arrow-bin").fadeIn(3000);   

    landing_bin = document.getElementById('landing-bin');
    arrow_bin   = document.getElementById('arrow-bin');


    img = document.createElement('img');
    img.setAttribute('class','arrow');
    img.src = big_arrow;
    img.style.left = -100+'px';
    landing_bin.appendChild(img)
    arrows[0] = img;
    
    for(i=1; i< arrow_count+1; i++){
        img = document.createElement('img');
        img.setAttribute('class','arrow');
        img.src = small_arrow;
        img.style.left = (Math.random()*100+(w-w/2.5))+'px';
        yPos[i] = (Math.random()*h);
        img.style.top = yPos[i]+'px';
        arrow_bin.appendChild(img)
        arrows[i] = img;
    }
    
    setInterval('rain()',5);
    
}

function rain(){
    for(i=0; i<arrows.length; i++){
        arrows[i].style.top = yPos[i]+"px";
        yPos[i]+=speed[i];
        if(yPos[i] > h+arrows[i].height){
            yPos[i]=-arrows[i].height;
        }
    }
}


function _on_resize(){
    place()
    
}

clouds = new Array('/assets/images/clouds/cloud.png','/assets/images/clouds/cloud2.png','/assets/images/clouds/cloud7.png','/assets/images/clouds/cloud4.png','/assets/images/clouds/cloud5.png','/assets/images/clouds/cloud6.png','/assets/images/clouds/cloud3.png','/assets/images/clouds/hibilly.png');

function rand(x_range,y_range){ 
    return new Array(Math.round((Math.random()*(x_range[1]-x_range[0]))+x_range[0]),Math.round((Math.random()*(y_range[1]-y_range[0]))+y_range[0]))
}

function cloudy(){
    for(i=0;i<clouds.length; i++){
        cloud = document.createElement('img');
        cloud.src = clouds[i];
        cloud.setAttribute('class','cloud');
        cloud.setAttribute('onclick','window.location=/shop/')
        randxy = rand([0,window.innerWidth],[-50,window.innerHeight-200]);
        cloud.style.left = randxy[0] + 'px';
        cloud.style.top = randxy[1] + 'px';
        sky.appendChild(cloud);
    }
}


function init2(){
    // create clouds
    sky = document.getElementById('cloud-bin');
    cloudy();
    
    setInterval(function(){
        for(i=1;i<sky.childNodes.length; i++){
            cloud = sky.childNodes[i ];
            if(parseInt(cloud.style.left) > window.innerWidth){
                cloud.style.left = -cloud.width + 'px';
            }else{
                cloud.style.left = parseInt(cloud.style.left) + 1 +'px';
            }
        }
    },1);
}

//document.onload = setTimeout('init()',400);
document.onload = setTimeout('init2()',400);
