var objs=new Array();var MAX_OBJECTS=80;var BROWSER_WIDTH=getWindowSize().width-50;var BROWSER_HEIGHT=210;var MAX_SPEED=1700;var MIN_SPEED=1200;var START_X_LINE=0;var TIMEOUT_INTERVAL=10;var TIMEOUT_INTERVAL_FAST=10;var TIMEOUT_INTERVAL_SLOW=40;var DISTRIBUTED_WIND=false;var WIND_SPEED=1;var windInc=0;var container=document.getElementById('headMeteo');var stTime=0;function fallingThings(num)
{if(num==0)
{stTime=new Date().getTime();}
if(num<10)
{var idT=setTimeout("fallingThings("+(num+1)+")",5);}
else
{var result=(new Date().getTime())-stTime;if(result>200)
{TIMEOUT_INTERVAL=TIMEOUT_INTERVAL_SLOW;}
else
{TIMEOUT_INTERVAL=TIMEOUT_INTERVAL_FAST;}
createObjects();drawObjects();moveObjects();}}
function Myimage(_url,_width,_height,_bgcolor,_text,_fontsize,_color)
{this.imgurl=_url;this.width=_width;this.height=_height;this.bgcolor=_bgcolor;this.text=_text;this.fontsize=_fontsize;this.color=_color;}
var imgs=new Array();function calculateSpeed()
{var animationTime=(Math.random()*(MAX_SPEED-MIN_SPEED))+MIN_SPEED;var speed=BROWSER_HEIGHT/(animationTime/TIMEOUT_INTERVAL);return speed;}
function createObjects()
{for(i=0;i<MAX_OBJECTS;i++)
{var numFiocco=parseInt(Math.random()*imgs.length);var xPos=parseInt(Math.random()*(BROWSER_WIDTH));var yPos=parseInt(Math.random()*(BROWSER_HEIGHT));if(DISTRIBUTED_WIND)
{var wSpeed=WIND_SPEED*Math.random();}
else
{var wSpeed=WIND_SPEED;}
if(TIMEOUT_INTERVAL==TIMEOUT_INTERVAL_SLOW)
{var wSpeed=wSpeed*(TIMEOUT_INTERVAL_SLOW/TIMEOUT_INTERVAL_FAST);}
var myObj=new FallingObj(imgs[numFiocco],xPos,yPos,calculateSpeed(),wSpeed,BROWSER_HEIGHT,BROWSER_WIDTH);objs.push(myObj);}}
function drawObjects()
{for(i=0;i<objs.length;i++)
{drawObj(i,objs[i]);}}
function SunObj(_refDom,_initLeft,_initTop,_sunrise,_sunset,_width_layout,_height_layout){this.x=0;this.y=0;this.refDom=_refDom;this.sunrise=_sunrise;this.sunset=_sunset;this.width_layout=_width_layout;this.height_layout=_height_layout;this.initLeft=_initLeft;this.initTop=_initTop;this.moveit=function(currtime)
{var middleday=(12*60*60);var availableSeconds=this.sunset-this.sunrise;var currentSecond=currtime-this.sunrise;var currentLeft=this.initLeft+(currentSecond*this.width_layout/availableSeconds);if(currtime<middleday)
{var availableSeconds=middleday-this.sunrise;var currentSecond=currtime-this.sunrise;var currentTop=this.initTop+this.height_layout-(Math.log(currentSecond)*Math.abs(this.height_layout)/Math.log(availableSeconds));}
else
{var availableSeconds=this.sunset-middleday;var currentSecond=currtime-middleday;var currentTop=this.initTop+this.height_layout-(Math.log(availableSeconds-currentSecond)*Math.abs(this.height_layout)/Math.log(availableSeconds));}
this.y=currentTop;this.x=currentLeft;}}
var meteoCategory=4;function initMetoAnimation(data)
{var sunrise=data.sunrise/1000;var sunset=data.sunset/1000;if(meteoCategory==1)
{var d=new Date();var curr_hour=d.getHours();var curr_min=d.getMinutes();var curr_sec=d.getSeconds();var currtime=(curr_hour*60*60)+(curr_min*60)+curr_sec;var sunriseEnd=sunrise+(60*60);var sunsetStart=sunset-(60*60);var middleday=(12*60*60);var endDay=(23*60*60)+(59*60)+59;var puntoRiferimento=document.getElementById('headMeteoForecastToolbar');var headDiv=document.getElementById('headMeteo');var duomoDiv=document.getElementById('duomo');var theSunDiv=document.getElementById('theSun');var initLeft=puntoRiferimento.offsetLeft;var WIDTH_LAYOUT=duomoDiv.offsetWidth;if(currtime>sunrise&&currtime<sunset)
{$('#theSun').css('display','inline');var SUN_H=50;var SUN_TOP_ADJUST=-64;var H_LAYOUT_REDUCE=50;var HEIGHT_LAYOUT=headDiv.offsetHeight-SUN_H-H_LAYOUT_REDUCE;var sunObj=new SunObj(theSunDiv,initLeft,SUN_TOP_ADJUST,sunrise,sunset,WIDTH_LAYOUT,HEIGHT_LAYOUT);sunObj.moveit(currtime);$('#theSun').animate({left:sunObj.x,top:sunObj.y,opacity:'1'},1000,'swing',function(){calcHB(null,sunrise,sunset);});}
else
{calcHB(null,sunrise,sunset);}}
else if(meteoCategory==4)
{var headMeteo=document.getElementById('headMeteo');var divNuv=createDiv('nuvola1');divNuv.style.left=200+'px';divNuv.style.top=-50+'px';}
else if(meteoCategory==13)
{calcHB(null,sunrise,sunset);imgs.push(new Myimage('',5,5,'','*',14,'#ffffff'));imgs.push(new Myimage('',5,5,'','*',16,'#ffffff'));imgs.push(new Myimage('',5,5,'','+',7,'#ffffff'));MAX_SPEED=2400;MIN_SPEED=2100;MAX_OBJECTS=70;DISTRIBUTED_WIND=true;WIND_SPEED=1;fallingThings(0);}
else if(meteoCategory==10)
{calcHB(null,sunrise,sunset);imgs.push(new Myimage('','','','','\\',10,'#DEF7FF'));MAX_SPEED=550;MIN_SPEED=450;MAX_OBJECTS=110;DISTRIBUTED_WIND=false;WIND_SPEED=1.5;fallingThings(0);}}
function FallingObj(_img,_x,_y,_speed,_wind,_limitY,_limitX){this.img=_img;this.x=_x;this.y=_y;this.speed=_speed;this.refDom;this.wind=_wind;this.limitX=_limitX;this.limitY=_limitY;this.moveit=function()
{if((this.y+this.speed)>this.limitY||(this.x+this.wind)>this.limitX)
{this.y=START_X_LINE;this.x=parseInt(Math.random()*(BROWSER_WIDTH));}
else
{this.y+=this.speed;this.x+=this.wind;}}}
function drawObj(id,myObj)
{var newObj=createDiv('objStyle','obj'+id);if(myObj.img.imgurl!='')
{newObj.innerHTML='<img src="'+myObj.img.imgurl+'">';}
if(myObj.img.text!='')
{newObj.innerHTML=myObj.img.text;}
if(myObj.img.bgcolor!='')
{newObj.style.backgroundColor=myObj.img.bgcolor;}
if(myObj.img.color!='')
{newObj.style.color=myObj.img.color;}newObj.style.left=myObj.x+"px";newObj.style.top=myObj.y+"px";newObj.style.width=(myObj.img.width+"px");newObj.style.height=(myObj.img.height+"px");newObj.style.fontSize=(myObj.img.fontsize+"px");myObj.refDom=newObj;container.appendChild(newObj);}
function createDiv(classname,id)
{var obj=document.createElement("div");obj.setAttribute('className',classname);obj.setAttribute('class',classname);if(id!=null)
{obj.setAttribute('id',id);}
else
{obj.setAttribute('id',classname);}
return obj;}
function moveObjects()
{for(i=0;i<objs.length;i++)
{var obj=objs[i];obj.moveit();obj.refDom.style.top=obj.y+"px";obj.refDom.style.left=obj.x+"px";}
idT=setTimeout(moveObjects,TIMEOUT_INTERVAL);}
