var fallObjects=new Array();
if (fallActive == undefined)
{
    var fallActive = true;
}

function setControlImage() {
    var path = "images/ng/";
    $("#fallControlImage").get(0).src = path + (fallActive ? "snowflake1.gif" : "snowflake1BW.gif");
}
$(window).load(setControlImage);

function fallStartStop()
{
    fallActive = !fallActive;
    $.get("ajaxFallOnOff.php", { fallScipt: "1" }, function(data){
        if (data != "success") alert(data);
    });
    setControlImage();
}
function newObject(url,height,width)
{
  fallObjects[fallObjects.length]=new Array(url,height,width);
}

var numObjs=3, waft=70, fallSpeed=0.2, wind=2;
//newObject("/images/ng/snowflake1.gif",66,62);
newObject("/images/ng/snowflake2.png",30,28);
//newObject("/images/osen/list3.png",25,40);
newObject("images/ng/snowflake3.png",45,42);
newObject("images/ng/snowflake4.png",45,42);
//newObject("/images/osen/list6.png",25,40);
//newObject("/images/vesna/but1.png",39,70);
//newObject("/images/vesna/but2.gif",39,70);
//newObject("/images/vesna/but3.png",39,70);
//newObject("/images/vesna/but4.png",39,70);
//newObject("/images/vesna/but5.png",39,70);

function winSize(){winWidth=(moz)?window.innerWidth:document.body.clientWidth;winHeight=(moz)?window.innerHeight:document.body.clientHeight;}
function winOfy(){winOffset=(moz)?window.pageYOffset:document.body.scrollTop;}
function fallObject(num,vari,nu){
	objects[num]=new Array(parseInt(Math.random()*(winWidth-waft)),-30,(parseInt(Math.random()*waft))*((Math.random()>0.5)?1:-1),0.02+Math.random()/20,0,1+parseInt(Math.random()*fallSpeed),vari,fallObjects[vari][1],fallObjects[vari][2]);
	if(nu==1){document.write('<img id="fO'+i+'" style="position:absolute;" src="'+fallObjects[vari][0]+'">'); }
}

function fall(){
	for(i=0;i<numObjs && fallActive;i++){
		var fallingObject=document.getElementById('fO'+i);
		if((objects[i][1]>(winHeight-(objects[i][5]+objects[i][7])))||(objects[i][0]>(winWidth-(objects[i][2]+objects[i][8])))){fallObject(i,objects[i][6],0);}
		objects[i][0]+=wind;objects[i][1]+=objects[i][5];objects[i][4]+=objects[i][3];
		with(fallingObject.style){ top=objects[i][1]+winOffset;left=objects[i][0]+(objects[i][2]*Math.cos(objects[i][4]));}
	}
	setTimeout("fall()",31);
}

var objects=new Array(),winOffset=0,winHeight,winWidth,togvis,moz=(document.getElementById&&!document.all)?1:0;winSize();
for (i=0;i<numObjs;i++){fallObject(i,parseInt(Math.random()*fallObjects.length),1);}
window.onscroll=winOfy;window.onresize=winSize;fall();
