var maxsize = 24;
var minsize = 12;
var weight = 50;
var maxflakes = 20;
var constrain = '';
var pagewidth = window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
var pageheight = window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
pagewidth = pagewidth - 100;
pageheight = pageheight - 36;
var isdancingFlag;

var createSnowFlag=0;
var snow = new Array();
var cntad;
var xp = new Array();
var yp = new Array();
var directpos = new Array();
var timer1,timer2,timer3,timer4,timer5,timer6,timer7,timer8,timer9,timer10,timer11,timer12,timer13,timer14,timer15,timer16,timer50;
var startpoint = '';

/*orbit start*/
var orbith='';
var orbitk=''
var orbita='';
var orbitb='';
var orbitval= new Array();
var orbitangle= new Array();
var orbits='';
var orbitarr2str='';
var orbitt='';
/*orbit end*/

/*zerog*/
var side=new Array();
var posx=new Array();
var posy=new Array();
/*zerog end*/

/*fountian 2 start*/
var fleft=new Array();
/*fountian 2 end*/

// sprial start
var si = new Array();
var tf='';
var scale='';
//sprial end

// faery start
var time = new Array();

//faery end


var mode ='';
var isdancing = 1;
var isdancingads=1;
var imgTag="";
if(constrain != ''){
	pagewidth = document.getElementById(constrain).offsetWidth;
	pageheight = document.getElementById(constrain).offsetHeight;
}
var fireworkpostop;
var fireworkposleft;
var originalimgsize;
function dancingGraphic(startpt,endpt,smode,dancingspeed,dancingimgArr,otheropt,imgsize,imgwidth)
{
	this.imgwidth=imgwidth;
	this.mode=smode;
	this.startflake =startpt;
	this.maxflakes = endpt;
	this.snow = new Array();
	this.snowh = new Array();
	var imgH,imgW;
	this.snowflake="";
	this.otheroption=otheropt;
	this.gspeed=dancingspeed;
	this.nddimgsize=imgsize;
	fireworkpostop = randomise(pagewidth, 20);
	fireworkposleft = randomise(pageheight/4, 20);
	this.originalimgsize = imgsize;
	this.currStep=0;
	if(this.mode == 7 || this.mode == 8)
	{
		this.step=0.5; 
		this.yBase=pageheight/6;
		this.xBase=pagewidth/12;
		this.currStep=0;
	}
	if(this.mode==5)
	{
		this.xval = new Array(); 
		this.yval = new Array();
		this.xp = new Array();
		this.yp=new Array();
		this.directpos=new Array();
		var keywords = new Array('top','left');
	}
	if(this.mode==9)
	{
		this.xp = new Array();
		this.yp=new Array();
	}
	if(this.mode==10)
	{
		this.xp = new Array();
		this.yp = new Array();
		this.orbith=pagewidth/2;
		this.orbitk=pageheight/2;
		this.orbita=pagewidth/2;
		this.orbitb=pageheight/2;
		
	}
	if(this.mode==11)
	{
		this.xp = new Array();
		this.yp = new Array();
		
		this.side=new Array();
		this.posx=new Array();
		this.posy=new Array();
				
	}
	if(this.mode==12)
	{
		this.cntad=this.startflake;
		this.xp = new Array();
		this.yp = new Array();
				
	}
	if(this.mode==13)
	{
		this.cntad=this.startflake;
		this.xp = new Array();
		this.yp = new Array();
		this.fleft=new Array();
				
	}
	if(this.mode==14)
	{
		this.si = new Array();
						
	}
	if(this.mode==15)
	{
		this.xp = new Array();
		this.yp = new Array();		
		this.time=new Array();
	}
	if(this.mode==16)
	{
		
		this.xp = new Array();
		this.yp = new Array();
		this.side=new Array();
		this.posx=new Array();
		this.posy=new Array();
		this.notcheck=new Array();
		this.element=new Array();
	
	}
	if(this.mode==17)
	{
		this.side=new Array();
		this.xp = new Array();
		this.yp = new Array();
		
	
	}
	if(this.mode == 3 || this.mode == 6) 
		this.startpoint = pageheight+"px";
	else if(this.mode == 1 || this.mode == 2)
	{
		this.startpoint= '-36px';
	}
	
	else
		this.startpoint= '0px';
		
	if(this.mode==50)
	{
		this.ad = new Array();
		this.cntad=this.startflake;
	}
	var imgArr = dancingimgArr;
	imgArr=imgArr.split("##");
	
	var strimg="";
	if(createSnowFlag==0)
	{
	for (var i = this.startflake; i < this.maxflakes; i++) {
		this.snowflake = document.createElement("span");
		this.imgH = Math.random()*60;
		
		this.snowflake.id = 's' + i; 
		this.snowflake.style.display = 'none'; 
		this.snowflake.style.position = 'fixed';
		this.snowflake.style.zIndex  = 1011;
		if(this.mode==6) 
		{
			tmpid='si'+i;
			strimg= imgArr[Math.floor(Math.random()*imgArr.length)];
			strimg = strimg.replace("/>","id="+tmpid+" height="+this.imgH+"/>");
			this.snowflake.innerHTML = strimg;
		}
		if(this.mode==20) 
		{
			tmpid='si'+i;
			strimg= imgArr[Math.floor(Math.random()*imgArr.length)];
			strimg = strimg.replace("/>","id="+tmpid+" height="+this.nddimgsize+"/>");
			this.snowflake.innerHTML = strimg;
		}
		else if(this.mode==14 || this.mode==10 || this.mode==9)
		{
			tmpid='si'+i;
			strimg= imgArr[Math.floor(Math.random()*imgArr.length)];
			strimg = strimg.replace("/>","id="+tmpid+" height=0>");
			this.snowflake.innerHTML = strimg;
		}
		else
			this.snowflake.innerHTML =imgArr[Math.floor(Math.random()*imgArr.length)];
		if(constrain != ''){
			document.getElementById(constrain).appendChild(snowflake);
		} else {
			document.body.appendChild(this.snowflake);
		}
	}
	}
	for (i = this.startflake; i < this.maxflakes; i++) {
		this.snow[i] = document.getElementById("s" + i);
		
		if( this.mode>19 && this.mode<50)
			this.snowh[i] = this.nddimgsize;
		
		
		
		this.snow[i].style.fontSize = randomise(maxsize, minsize) + 'px';
		if(this.mode==50)
			this.ad[i] =true;

		this.snow[i].style.display = 'none';
		
		if(this.mode==7)
		{
			this.snow[i].style.left = randomise(pagewidth) + 'px';
			this.snow[i].style.top = Math.random()*(pageheight/4)+"px";
		}
		else if(this.mode==5)
		{
			this.xp[i] = pagewidth * Math.random();
			this.yp[i] = pageheight  * Math.random();
			this.snow[i].style.left =this.xp[i] + 'px';
			this.snow[i].style.top =this.yp[i] + 'px';
			this.directpos[i] = keywords[Math.floor(Math.random()*2)];
		}
		else if(this.mode==8)
		{
			this.snow[i].style.left = fireworkpostop + 'px';
			this.snow[i].style.top = fireworkposleft+"px";
		}
		else if(this.mode==9)
		{
			this.snow[i].style.left = pagewidth/2+"px";
			this.snow[i].style.top =(pageheight/2) +((pageheight/2)/2)+"px";
			this.snowh[i] = Math.round(Math.random()*8);
			this.xp[i] = Math.floor(Math.random()*100) - 30;
			this.yp[i] =  Math.floor(Math.random()*100) - 50;
		}
		else if(this.mode==10)
		{
			this.snowh[i] = Math.round(Math.random()*8);
			var tmp= new Array();
			
			tmp=getorbitpoint(this.orbita,this.orbitb,this.orbith,this.orbitk);
			
			this.xp[i] = tmp[0];
			this.yp[i] = tmp[1];
			this.snow[i].style.left = tmp[0]+"px";
			this.snow[i].style.top = tmp[1]+"px";
			
			orbitval.push(tmp[2]);
			orbitangle.push(tmp[3]);
	
			
		}
		else if(this.mode==11)
		{
			
			var tmp=new Array();
			tmp=getzerogpoint(i);
			this.xp[i] = tmp[0];
			this.yp[i] = tmp[1];
			this.side[i]=tmp[2];
			this.posx[i]=tmp[0];
			this.posy[i]=tmp[1];
			this.snow[i].style.left =tmp[0]+'px';
			this.snow[i].style.top =tmp[1]+'px';
		}
		else if(this.mode==12)
		{
			
			this.xp[i]=Math.floor(Math.random()*20-10);
    		this.yp[i]= -Math.random()*10-14;
			this.snow[i].style.left = (pagewidth/2)+'px';
			this.snow[i].style.top = pageheight+'px';
			
		}
		else if(this.mode==13)
		{
			//pagewidth=pagewidth+100;
			
			this.xp[i]=Math.floor(Math.random()*20-10);
    		this.yp[i]= -Math.random()*10-14;
			
			var tmp=Math.floor(Math.random()*3);
			switch(tmp)
			{
				case 0:
						this.snow[i].style.left = (pagewidth/2)-((pagewidth/2)/2)+'px';
						this.fleft[i]=(pagewidth/2)-((pagewidth/2)/2)+'px';
						break;
				case 1:
						this.snow[i].style.left = (pagewidth/2)+((pagewidth/2)/2)+'px';
						this.fleft[i]=(pagewidth/2)+((pagewidth/2)/2)+'px';
						break;
				case 2:
						this.snow[i].style.left = (pagewidth/2)+'px';
						this.fleft[i]=(pagewidth/2)+'px';
						break;
			}
				this.snow[i].style.top = pageheight+'px';
							
		}
		else if(this.mode==14)
		{
			if(i!=this.startflake)this.si[i]=this.si[i-1]+2;
			else this.si[i]=1;
			
			tf=((50-0)/200);
			scale=(pagewidth/2)/50;
			this.snow[i].style.top=(pagewidth/2)+'px';
			this.snow[i].style.left=(pageheight/2)+'px';
			this.snowh[i] = Math.round(Math.random()*8);
			
		}
		else if(this.mode==15)
		{
			this.xp[i]=Math.floor(Math.random()*pagewidth);
			this.yp[i]=Math.floor(Math.random()*pageheight);
			this.snow[i].style.left=this.xp[i]+'px';
			this.snow[i].style.top=this.yp[i]+'px';
			this.time[i]=1200-(i*10);
		}
		else if(this.mode==16)
		{
			var tmp=new Array();
			tmp=getzerogpoint(i)
			this.xp[i] = tmp[0];
			this.yp[i] = tmp[1];
			this.side[i]=tmp[2];
			this.posx[i]=tmp[0];
			this.posy[i]=tmp[1];
			this.snow[i].style.left =tmp[0]+'px';
			this.snow[i].style.top =tmp[1]+'px';
			this.element[i]=new Array();
			this.notcheck=new Array();
		
		}
		else if(this.mode==17)
		{
			var tmp=Math.floor(Math.random()*4);
			
			switch(tmp)
			{
				case 0:
						this.xp[i]=0;
						this.yp[i]=0;
						this.side[i]=0;
						break;
				case 1:
						this.xp[i]=0;
						this.yp[i]=pageheight;
						this.side[i]=1;
						break;
				case 2:
						this.xp[i]=pagewidth;
						this.yp[i]=0;
						this.side[i]=2;
						break;
				case 3:
						this.xp[i]=pagewidth;
						this.yp[i]=pageheight;
						this.side[i]=3;
						break;
			}
			this.snow[i].style.left=this.xp[i]+'px';
			this.snow[i].style.top=this.yp[i]+'px';
			
			
			
		}
		else if(this.mode==20)
		{
			this.snow[i].style.left = randomise(pagewidth) + 'px';
			this.snow[i].style.top = randomise(pageheight) + 'px';
			
		}
		else 
		{
		this.snow[i].style.left = randomise(pagewidth) + 'px';
		this.snow[i].style.top =this.startpoint;
		}
	}
}

/*diagonal*/

var length = Math.sqrt( (pagewidth*pagewidth) + (pageheight*pageheight) );
var addx = pagewidth / length;
var addy = pageheight / length;

dancingGraphic.prototype.diagonal=function()
{
	
	
	if(isdancingFlag==0)
		clearTimeout(timer17);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				var tmp=Math.floor(Math.random()*4);
			
				switch(tmp)
				{
					case 0:
							this.xp[i]=0;
							this.yp[i]=0;
							this.side[i]=0;
							break;
					case 1:
							this.xp[i]=0;
							this.yp[i]=pageheight;
							this.side[i]=1;
							break;
					case 2:
							this.xp[i]=pagewidth;
							this.yp[i]=0;
							this.side[i]=2;
							break;
					case 3:
							this.xp[i]=pagewidth;
							this.yp[i]=pageheight;
							this.side[i]=3;
							break;
				}
				this.snow[i].style.left=this.xp[i]+'px';
				this.snow[i].style.top=this.yp[i]+'px';
				
			
			
			}
			else
			{
			if ((parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.top))<=pageheight)
			{
	
				
				this.snow[i].style.display = 'block';
				
				switch(this.side[i])
				{
					case 0:
							this.snow[i].style.left=this.xp[i]+'px';
							this.snow[i].style.top=this.yp[i]+'px';
							
							this.xp[i]=this.xp[i]+addx;
							this.yp[i]=this.yp[i]+addy;
									 
							break;
					case 1:
					
							this.snow[i].style.left=this.xp[i]+'px';
							this.snow[i].style.top=this.yp[i]+'px';
							
							this.xp[i]=this.xp[i]+addx;
							this.yp[i]=this.yp[i]-addy;
							break;
					case 2:
					
							this.snow[i].style.left=this.xp[i]+'px';
							this.snow[i].style.top=this.yp[i]+'px';
							
							this.xp[i]=this.xp[i]-addx;
							this.yp[i]=this.yp[i]+addy;
							break;
					case 3:
					
							this.snow[i].style.left=this.xp[i]+'px';
							this.snow[i].style.top=this.yp[i]+'px';
							
							this.xp[i]=this.xp[i]-addx;
							this.yp[i]=this.yp[i]-addy;
							break;
				}
			
				
		}
		else
		{
				switch(this.side[i])
				{
					case 0:
							this.xp[i]=pagewidth;
							this.yp[i]=pageheight;
							this.side[i]=3;
							break;
					case 1:
							this.xp[i]=pagewidth;
							this.yp[i]=0;
							this.side[i]=2;
							break;
					case 2:
							this.xp[i]=0;
							this.yp[i]=pageheight;
							this.side[i]=1;
							break;
					case 3:
							this.xp[i]=0;
							this.yp[i]=0;
							this.side[i]=0;
							break;
				}
				this.snow[i].style.left=this.xp[i]+'px';
				this.snow[i].style.top=this.yp[i]+'px';
				
		}
	}
	}
	if(isdancingFlag==1)
	timer17 = setTimeout(function(){self.diagonal();},this.gspeed);

}
/*diagonal end*/

/*buzg coster*/
var sideflag=0;
var tmpsidecheck=0;
dancingGraphic.prototype.bugz=function()
{
	
	
	if(isdancingFlag==0)
		clearTimeout(timer16);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				var tmp=new Array();
				tmp=getzerogpoint(i)
				this.xp[i] = tmp[0];
				this.yp[i] = tmp[1];
				this.side[i]=tmp[2];
				this.posx[i]=tmp[0];
				this.posy[i]=tmp[1];
				this.snow[i].style.left =tmp[0]+'px';
				this.snow[i].style.top =tmp[1]+'px';
				this.element[i]=new Array();
				this.notcheck=new Array();
				
				
				 
			}
			else
			{
			if ((parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.top))<=pageheight)
			{
	
				
				this.snow[i].style.display = 'block';
			
			switch(this.side[i])
			{
				case 3:
						this.snow[i].style.top =(parseInt(this.snow[i].style.top))+1+'px';
						break;
				case 2:
						this.snow[i].style.left =(parseInt(this.snow[i].style.left))+1+'px';
						break;
				case 1:
						this.snow[i].style.left =(parseInt(this.snow[i].style.left))-1+'px';
						break;
				case 0:
						this.snow[i].style.top =(parseInt(this.snow[i].style.top))-1+'px';
						break;
			}
			
			
			/*serch for collide */
			var st=this.notcheck.toString();
							
			if(st.search(i)==-1)
			{
				this.posx[i]=(parseInt(this.snow[i].style.left));
				this.posy[i]=(parseInt(this.snow[i].style.top));
				
				var tmp= collide(this.posx,this.posy,i,this.imgwidth,this.nddimgsize,this.startflake);
				
				if(tmp!=-1 && st.search(tmp)==-1)
				{						
						this.notcheck.push(tmp);
						//this.notcheck.push(i);
						this.element[i].push(tmp);
							
							
						var s1i=this.side[i];
						
						if(this.element[tmp].length>0)
						{
							
							for(z=this.element[tmp].length;z>0;z--)
							{
								var ztmp=this.element[tmp].pop();
								this.side[ztmp]=s1i;
								
								var tmppos=addbug(this.posx[i],this.posy[i],s1i,this.element[i].length,this.imgwidth,this.nddimgsize,this.snow[i]);
								
								this.snow[ztmp].style.left=tmppos[0]+'px';
								this.snow[ztmp].style.top=tmppos[1]+'px';
								this.element[i].push(ztmp);
							}
	
							var tmppos=addbug(this.posx[i],this.posy[i],s1i,this.element[i].length,this.imgwidth,this.nddimgsize,this.snow[i]);
								this.side[tmp]=s1i;
								this.snow[tmp].style.left=tmppos[0]+'px';
								this.snow[tmp].style.top=tmppos[1]+'px';
								
								
							
						}
						else
						{
							var tmppos=addbug(this.posx[i],this.posy[i],s1i,this.element[i].length,this.imgwidth,this.nddimgsize,this.snow[i]);
								this.side[tmp]=s1i;
								this.snow[tmp].style.left=tmppos[0]+'px';
								this.snow[tmp].style.top=tmppos[1]+'px';
								
							
						}
						this.posx[tmp]=(-1);
						this.posy[tmp]=(-1);
						
						
				}
				
			}
			
					
				
				
				
		}
		else
		{
			
			sidefalg=0;
			if(this.posx[i]>-1 && this.posy[i]>-1)
			{
				if(!(this.element[i].length>0))
				{
					switch(this.side[i])
					{
				
						case 3:
								tmpsidecheck=3;
								this.snow[i].style.top =(parseInt(this.snow[i].style.top))-1+'px';
								while(tmpsidecheck==this.side[i])
								tmpsidecheck=Math.floor(Math.random()*4);
								this.side[i]=tmpsidecheck;
								break;
						case 2:
								tmpsidecheck=2;
								this.snow[i].style.left =(parseInt(this.snow[i].style.left))-1+'px';
								while(tmpsidecheck==this.side[i])
								tmpsidecheck=Math.floor(Math.random()*4);
								this.side[i]=tmpsidecheck;							
								break;
						case 1:
								tmpsidecheck=1;
								this.snow[i].style.left =(parseInt(this.snow[i].style.left))+1+'px';
								while(tmpsidecheck==this.side[i])
								tmpsidecheck=Math.floor(Math.random()*4);
								this.side[i]=tmpsidecheck;							
								break;
						case 0:
								tmpsidecheck=0;
								this.snow[i].style.top =(parseInt(this.snow[i].style.top))+1+'px';
								while(tmpsidecheck==this.side[i])
								tmpsidecheck=Math.floor(Math.random()*4);
								this.side[i]=tmpsidecheck;
								break;
					}
								
				}
			}
			/*
			for(zside=this.startflake;zside<this.maxflakes;zside++)
			{
				if(this.element[zside].length>0)
				{
					var tmpsideelement=this.element[zside].toString();
					if(tmpsideelement.search(i)!=-1)
					{
						switch(this.side[zside])
						{
							case 0:
									this.side[i]=3;
									break;
							case 1:
									this.side[i]=2;
									break;
							case 2:
									this.side[i]=1;
									break;
							case 3:
									this.side[i]=0;
									break;
						}
						sidefalg=1;
						
					}
				}
				if(sideflag)
				break;
			}*/
				if(sideflag==0)
				{
					switch(this.side[i])
					{
						case 3:
								this.snow[i].style.top =(parseInt(this.snow[i].style.top))-1+'px';
								this.side[i]=0;
								break;
								
						case 2:
								this.snow[i].style.left =(parseInt(this.snow[i].style.left))-1+'px';
								this.side[i]=1;
								break;
								
						case 1:
								this.snow[i].style.left =(parseInt(this.snow[i].style.left))+1+'px';
								this.side[i]=2;
								break;
								
						case 0:
								this.snow[i].style.top =(parseInt(this.snow[i].style.top))+1+'px';
								this.side[i]=3;
								break;
						
					}
					if(this.posx[i]>-1 && this.posy[i]>-1)
					{
						this.posx[i]=(parseInt(this.snow[i].style.left));
						this.posy[i]=(parseInt(this.snow[i].style.top));
					}
				}
		}
	}
	}
	if(isdancingFlag==1)
	timer16 = setTimeout(function(){self.bugz();},this.gspeed);

}
/*bugz coster rnd*/


/* faery start*/
dancingGraphic.prototype.faery=function()
{
	
	this.gspeed=10;
	if(isdancingFlag==0)
		clearTimeout(timer15);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				this.xp[i]=Math.floor(Math.random()*pagewidth);
				this.yp[i]=Math.floor(Math.random()*pageheight);
				this.snow[i].style.left=this.xp[i]+'px';
				this.snow[i].style.top=this.yp[i]+'px';
				this.time[i]=1200-(i*10);
				
			}
			else
			{
			if ((parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.top))<=pageheight && this.time[i]>0)
			{
	
				
				this.snow[i].style.display = 'block';
				this.time[i]=this.time[i]-this.gspeed;
				
				
		}
		else
		{
			this.xp[i]=Math.floor(Math.random()*pagewidth);
			this.yp[i]=Math.floor(Math.random()*pageheight);
			this.snow[i].style.left=this.xp[i]+'px';
			this.snow[i].style.top=this.yp[i]+'px';
			this.time[i]=1200-(i*10);
		}
	}
	}
	if(isdancingFlag==1)
	timer15 = setTimeout(function(){self.faery();},this.gspeed);

}

/* faery end*/

/*sprial function made by nirav*/
var starheight=0;
var resizeimageby=1;
dancingGraphic.prototype.sprial=function()
{
	
	
	if(isdancingFlag==0)
		clearTimeout(timer14);
	var self = this;
	this.currStep+=this.step;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				this.si[i]=1;
				this.snow[i].style.top=(pagewidth/2)+'px';
				this.snow[i].style.left=(pageheight/2)+'px';
				this.snowh[i]=0;
			    
			}
			else
			{
			if ((parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.top))<=pageheight)
			{
	
				
				this.snow[i].style.display = 'block';
				
				var t=this.si[i]*tf+0;
				var r =eval(t);
				var x=r*Math.cos(t);
			  	var y=r*Math.sin(t);
				
				var x1=(pagewidth/2)+(scale*x);
				var y1=(pageheight/2)-(scale*y);
				
				
				this.snow[i].style.top=y1+'px';
				this.snow[i].style.left=x1+'px';
				
				cheight = this.snowh[i];
				if(cheight<this.nddimgsize)
				{
					this.snowh[i]=parseInt(this.snowh[i])+(resizeimageby);
					document.getElementById("si"+i).height=this.snowh[i];
					
				}
				
			  	this.si[i]=this.si[i]+1;
		}
		
		else
		{
			this.si[i]=1;
			this.snow[i].style.top=(pagewidth/2)+'px';
			this.snow[i].style.left=(pageheight/2)+'px';
			this.snowh[i]=0;
				
		}
	}
	}
	if(isdancingFlag==1)
	timer14 = setTimeout(function(){self.sprial();},this.gspeed);

}
/*sprial end*/

/*fountain_2 function made by nirav*/

dancingGraphic.prototype.fountain2=function()
{
	//this.gspeed=5;
	if(isdancingFlag==0)
		clearTimeout(timer13);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				this.xp[i]=Math.floor(Math.random()*20-10);
    			this.yp[i]= -Math.random()*10-14;
				this.snow[i].style.left = this.fleft[i];
				this.snow[i].style.top = pageheight+'px';
				
			    
			}
			else
			{
			if ((parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))<=pageheight)
			{
	
				this.snow[i].style.display = 'block';
				this.xp[i]*=.99;
				this.yp[i]+=0.5;
		
				this.snow[i].style.left =parseInt(this.snow[i].style.left)-this.xp[i] +'px';
				this.snow[i].style.top = parseInt(this.snow[i].style.top)+ this.yp[i]+'px';
					
				if(parseInt(this.snow[i].style.top)>pageheight)
				{
				   	this.xp[i]=Math.floor(Math.random()*20-10);
    			  	this.yp[i]= -Math.random()*10-14;
					this.snow[i].style.left = this.fleft[i];
					this.snow[i].style.top = pageheight+'px';
				}

			
		}
		else
		{
				 
			this.xp[i]=Math.floor(Math.random()*20-10);
    		this.yp[i]= -Math.random()*10-14;
			this.snow[i].style.left = this.fleft[i];
			this.snow[i].style.top = pageheight+'px';
				
		}
	}
	}
	if(isdancingFlag==1)
	timer13 = setTimeout(function(){self.fountain2();},this.gspeed);

}
/* fountain_2 funvtion end */

/*fountain_1 function made by nirav*/

dancingGraphic.prototype.fountain1=function()
{
	if(isdancingFlag==0)
		clearTimeout(timer12);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				this.xp[i]=Math.floor(Math.random()*20-10);
    			this.yp[i]= -Math.random()*10-14;
				this.snow[i].style.left = (pagewidth/2)+'px';
				this.snow[i].style.top = pageheight+'px';
				
			    
			}
			else
			{//(pagewidth-this.imgwidth) (pageheight-this.nddimgsize)
			if ((parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))<=pageheight)
			{
	
				this.snow[i].style.display = 'block';
				this.xp[i]*=.99;
				this.yp[i]+=0.5;
		
				this.snow[i].style.left =parseInt(this.snow[i].style.left)-this.xp[i] +'px';
				this.snow[i].style.top = parseInt(this.snow[i].style.top)+ this.yp[i]+'px';
					
				if(parseInt(this.snow[i].style.top)>pageheight)
				{
				   	this.xp[i]=Math.floor(Math.random()*20-10);
    			  	this.yp[i]= -Math.random()*10-14;
					this.snow[i].style.left = (pagewidth/2)+'px';
					this.snow[i].style.top = pageheight+'px';
				}

			
		}
		else
		{
				 
			this.xp[i]=Math.floor(Math.random()*20-10);
    		this.yp[i]= -Math.random()*10-14;
			this.snow[i].style.left = (pagewidth/2)+'px';
			this.snow[i].style.top = pageheight+'px';
				
		}
	}
	}
	
	if(isdancingFlag==1)
	timer12 = setTimeout(function(){self.fountain1();},this.gspeed);

}
/* fountain_1 funvtion end */


/* Zero G function made by nirav */
dancingGraphic.prototype.zerog=function() 
{
	
	if(isdancingFlag==0)
		clearTimeout(timer11);
	var self = this;
	this.currStep+=this.step;
	if(imgTag=="")
	imgTag = document.getElementById('s'+this.startflake).innerHTML;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				  var tmp=new Array();
				  tmp=getzerogpoint(i);
				  this.xp[i] = tmp[0];
				  this.yp[i] = tmp[1];
				  this.side[i]=tmp[2];
				  this.posx[i]=tmp[0];
				  this.posy[i]=tmp[1];
				  this.snow[i].style.left =tmp[0]+'px';
				  this.snow[i].style.top =tmp[1]+'px';
				 
			}
			else
			{
			if ((parseInt(this.snow[i].style.top))>=0 && (parseInt(this.snow[i].style.left))>=0 && (parseInt(this.snow[i].style.left))<=pagewidth && (parseInt(this.snow[i].style.top))<=pageheight)
			{

			this.snow[i].style.display = 'block';
			
			switch(this.side[i])
			{
				case 3:
						this.snow[i].style.top =(parseInt(this.snow[i].style.top))+1+'px';
						break;
				case 2:
						this.snow[i].style.left =(parseInt(this.snow[i].style.left))+1+'px';
						break;
				case 1:
						this.snow[i].style.left =(parseInt(this.snow[i].style.left))-1+'px';
						break;
				case 0:
						this.snow[i].style.top =(parseInt(this.snow[i].style.top))-1+'px';
						break;
			}
			
			this.posx[i]=(parseInt(this.snow[i].style.left));
			this.posy[i]=(parseInt(this.snow[i].style.top));
			
			/*serch for collide */
			
			var tmp= collide(this.posx,this.posy,i,this.imgwidth,this.nddimgsize,this.startflake);
			if(tmp!=-1)
			{
				
					var s1i=this.side[i];
					var s2i=this.side[tmp];
					
					var new_side=s1i;
					while(s1i==new_side)
					{
						new_side= Math.floor(Math.random()*4);
					}
					this.side[i]=new_side;
					
					var new_side1=s2i;
					while(s2i==new_side1 && new_side==new_side1)
					{
						new_side1= Math.floor(Math.random()*4);
					}
					this.side[tmp]=new_side1;
					
					
			}
			
			
		}
		else
		{
				  switch(this.side[i])
					{
						case 3:
								this.snow[i].style.top =pageheight+'px';
								this.side[i]=0;
								break;
								
						case 2:
								this.snow[i].style.left =pagewidth+'px';
								this.side[i]=1;
								break;
								
						case 1:
								this.snow[i].style.left =0+'px';
								this.side[i]=2;
								break;
								
						case 0:
								this.snow[i].style.top =0+'px';
								this.side[i]=3;
								break;
						
					}
					this.posx[i]=(parseInt(this.snow[i].style.left));
					this.posy[i]=(parseInt(this.snow[i].style.top));
		}
	}
	}
	if(isdancingFlag==1)
	timer11 = setTimeout(function(){self.zerog();},this.gspeed);
		
}
/* Zero G fuction end*/




/* orbit function madde by nirav */
var starheight=0;
var resizeimageby=1;
dancingGraphic.prototype.orbit=function() 
{
	
	if(isdancingFlag==0)
		clearTimeout(timer10);
	var self = this;
	this.currStep+=this.step;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				
				this.snow[i].style.left = this.xp[i]+"px";
				this.snow[i].style.top = this.yp[i]+"px";
				this.snow[i].style.display = 'none';
				this.snowh[i] = Math.random()*8;
			}
			else
			{
			if ( (parseInt(this.snow[i].style.top))<pageheight && (parseInt(this.snow[i].style.left))<pagewidth && (parseInt(this.snow[i].style.top))>0 && (parseInt(this.snow[i].style.left))>0 && this.snowh[i] <this.originalimgsize)
			{

			this.snow[i].style.display = 'block';
			
			orbita=this.orbita;
			orbitb=this.orbitb;
			
			orbitt=orbitangle[i];
			orbitt=orbitt+0.1;
			orbitangle[i]=orbitt;			
			x=Math.floor(orbita*Math.cos(orbitt));
			
			y=Math.floor(orbitb*Math.sin(orbitt));
			
			x=orbita+x;
			y=orbitb+y;
			
			this.snow[i].style.top = y+'px';
			this.snow[i].style.left = x+'px';
			
			cheight = this.snowh[i];
			this.snowh[i]=parseInt(this.snowh[i])+resizeimageby;
			
			document.getElementById("si"+i).height=this.snowh[i];
			
		}
		else
		{
			
			this.snow[i].style.display = 'none';
			this.snow[i].style.left = this.xp[i]+"px";
			this.snow[i].style.top = this.yp[i]+"px";
			this.snowh[i] = Math.random()*8;
			
		}
	}
	}
	if(isdancingFlag==1)
	timer10 = setTimeout(function(){self.orbit();}, this.gspeed);
}
/* orbit function end */

dancingGraphic.prototype.snowfall=function()
{
	if(isdancingFlag==0)
		clearTimeout(timer1);
	var self = this;
	var direction = this.otheroption;

	if(direction == 'left')
	 dx=-4;
		 else
	 dx=4;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
			
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2){
				this.snow[i].style.left =parseInt(this.snow[i].style.left) + dx + 'px'; 
			} else {
				this.snow[i].style.left = parseInt(this.snow[i].style.left) + dx + 'px';
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (parseInt(this.snow[i].style.top) < pageheight){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) + (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer1 = setTimeout(function(){self.snowfall();}, this.gspeed);
}
dancingGraphic.prototype.rainfall=function()
{
	if(isdancingFlag==0)
		clearTimeout(timer2);
		
	var self = this;
	for (var i = this.startflake; i < this.maxflakes; i++) 
	{
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint))
		{
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (parseInt(this.snow[i].style.top) < pageheight && isdancingFlag==1){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) + (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
				
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.display = 'none';
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer2 = setTimeout(function(){self.rainfall();}, this.gspeed);
		
}

dancingGraphic.prototype.balloons=function()
{
	if(isdancingFlag==0)
		clearTimeout(timer3);
		
	var self = this;
		for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(startpoint)){
			
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2){
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left) + 2, parseInt(this.snow[i].style.left) - 2)) + 'px';
			} else {
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left), parseInt(this.snow[i].style.left) - 2)) + 'px';
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (parseInt(this.snow[i].style.top) >= (pageheight*-1)){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) - (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer3 = setTimeout(function(){self.balloons();}, this.gspeed);
		
}
dancingGraphic.prototype.autumnleaves=function() 
{
	if(isdancingFlag==0)
		clearTimeout(timer4);
	var self = this;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
			
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2){
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left) + 24, parseInt(this.snow[i].style.left) - 24)) + 'px';
			} else {
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left), parseInt(this.snow[i].style.left) - 24)) + 'px';
			}
				if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (parseInt(this.snow[i].style.top) < pageheight){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) + (parseInt(this.snow[i].style.fontSize) /4)) + 'px';
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer4 = setTimeout(function(){self.autumnleaves();}, this.gspeed);
}


var chckex,checky;
angle = 3.14 * Math.random(); 
xinc = 3 * Math.sin(angle);
yinc = 3;
function goangle() {
angle = 3.14 * Math.random();
xinc = 3 * Math.sin(angle);
return true;
}

dancingGraphic.prototype.flutterby=function() 
{
	if(isdancingFlag==0)
		clearTimeout(timer5);
	var self = this;
	for (var j = this.startflake; j < this.maxflakes;j++){
		if(isdancingFlag==0)
			{
				this.snow[j].style.left = this.xp[j]+"px";
				this.snow[j].style.top = this.yp[j]+"px";
				this.snow[j].style.display = 'none';
			}
			else
			{
this.snow[j].style.left = this.xp[j]+"px";
this.snow[j].style.top = this.yp[j]+"px";
this.snow[j].style.display = 'block';
			}
if(this.directpos[j] == "top")
{
this.xp[j] += xinc;
this.yp[j] +=yinc;
}
else
{
this.xp[j] -= xinc;
this.yp[j] -=yinc;
}

if(this.xp[j]<0)
	this.xp[j]= this.xp[j]*-1;
if(this.yp[j]<0)
	this.yp[j]= this.yp[j]*-1;

if ((this.xp[j] >= (pagewidth - 50)) || (this.xp[j] <= 10) || this.snow[j].style.left>(pagewidth - 50))  { goangle();  xinc = (-1) * xinc; }
if ((this.yp[j] >= (pageheight - 50)) || (this.yp[j] <= 10) || this.snow[j].style.top>=(pageheight - 50)) {  goangle(); yinc = (-1) * yinc; }
	}		
if(isdancingFlag==1)	
timer5 = setTimeout(function(){self.flutterby();}, this.gspeed);
}
dancingGraphic.prototype.bubbles=function() 
{
	if(isdancingFlag==0)
		clearTimeout(timer6);
		var self = this;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
			
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2){
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left) + 2, parseInt(this.snow[i].style.left) - 2)) + 'px';
			} else {
				this.snow[i].style.left = (randomise(parseInt(this.snow[i].style.left), parseInt(this.snow[i].style.left) - 2)) + 'px';
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (parseInt(this.snow[i].style.top) >= (pageheight*-1)){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) - (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer6 = setTimeout(function(){self.bubbles();}, this.gspeed);
}
dancingGraphic.prototype.buzzby=function() 
{
	if(isdancingFlag==0)
		clearTimeout(timer7);
		
	var self = this;
	this.currStep+=this.step;
	for (var i = this.startflake; i < this.maxflakes; i++) {
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2 ){
				this.Xpos=parseInt(this.snow[i].style.left)+Math.random()*2;  
				this.Ypos=parseInt(this.snow[i].style.top)+Math.random()*2; 
			} else {
				this.Xpos=parseInt(this.snow[i].style.left)-Math.random()*2;  
				this.Ypos=parseInt(this.snow[i].style.top)-Math.random()*2; 
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			else
			{
			if (this.Ypos < pageheight || this.Xpos < pagewidth-20){
				this.snow[i].style.display = 'block';
				poscos = Math.cos(this.currStep+i*35)/10;
				possin = Math.sin(((this.currStep)+i*3.7)/4);
				this.snow[i].style.top = this.Ypos+this.yBase*Math.sin(((this.currStep)+i*3.7)/4)*Math.cos((this.currStep+i*35)/10)+"px"; 
  				this.snow[i].style.left =this.Xpos+this.xBase*Math.cos(((this.currStep)+i*3.7)/4)*Math.cos((this.currStep+i*35)/62)+"px";
			} else {
				this.snow[i].style.top = this.startpoint;
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
			}
			}
	}
	if(isdancingFlag==1)
	timer7 = setTimeout(function(){self.buzzby();}, this.gspeed);
}
dancingGraphic.prototype.fireworks=function() 
{
	if(isdancingFlag==0)
		clearTimeout(timer8);
	var self = this;
	if(this.currStep>10)
	this.currStep=0.5;
	this.currStep+=this.step;
	var cnt=0;
	for (var i = this.startflake; i < this.maxflakes; i++) {
			cnt++;
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2 ){
				this.Ypos=parseInt(this.snow[i].style.left)+Math.random()*2;  
				this.Xpos=parseInt(this.snow[i].style.top)+Math.random()*2;  
			} else {
				this.Ypos=parseInt(this.snow[i].style.left)-Math.random()*2;  
				this.Xpos=parseInt(this.snow[i].style.top)-Math.random()*2; 
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top =fireworkpostop+ 'px';
				this.snow[i].style.left = fireworkposleft + 'px';
				this.snow[i].style.display = 'none';
				this.currStep=0;
				this.Xpos=0;
				this.Ypos=0;
			}
			else
			{
			if ((this.Ypos < pageheight || this.Xpos < pagewidth-20)&&parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
				this.snow[i].style.display = 'block';
				
				this.snow[i].style.top = this.Xpos + 60*Math.sin((this.currStep+cnt*3)/6)*Math.sin(this.currStep/200)+"px"; 
  				this.snow[i].style.left = this.Ypos + 60*Math.cos((this.currStep+cnt*3)/6)*Math.sin(this.currStep/200)+"px";
			} else {
				this.snow[i].style.top = fireworkpostop+ 'px';
				this.snow[i].style.left = fireworkposleft + 'px';
				this.snow[i].style.display = 'none';
				this.currStep=0;
				this.Xpos=0;
				this.Ypos=0;
			}
			}
	}
	if(isdancingFlag==1)
		timer8 = setTimeout(function(){self.fireworks();}, this.gspeed);
}


dancingGraphic.prototype.showNddAds=function() 
{
	var self = this;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
			
			if (parseInt(this.snow[i].style.top) < pageheight+36 && isdancingads==1 && this.ad[i]==true){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) + (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
				
			} else {
				if (parseInt(this.snow[i].style.top) > pageheight+36)
				{
					this.snow[i].style.top = this.startpoint;
					this.snow[i].style.left = randomise(pagewidth) + 'px';
					this.snow[i].style.display = 'none';
					this.ad[i]=false;
					this.cntad++;
				}
			}
		}
	}
	/*if(this.cntad==this.maxflakes)
	{
		hidedancingads();
		isdancingads=0;
		clearTimeout(timer50);
	}*/
	if(isdancingads==1)
		timer50 = setTimeout(function(){self.showNddAds();}, this.gspeed);
}
var starheight=0;
var randomxdir;
var randomydir;
dancingGraphic.prototype.starfield=function() 
{
	
	if(isdancingFlag==0)
		clearTimeout(timer9);
	var self = this;
	this.currStep+=this.step;
	
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(isdancingFlag==0)
			{
				this.snowh[i] = Math.random()*8;
				this.snow[i].style.top = (pageheight/2) +((pageheight/2)/2) + 'px';
				this.snow[i].style.left = pagewidth/2 + 'px';
				this.snow[i].style.display = 'none';
				
			}
			else
			{
		if((parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)) && this.snowh[i] <this.originalimgsize){
		
			this.snow[i].style.display = 'block';
			this.snow[i].style.top = (parseInt(this.snow[i].style.top) - (this.xp[i] / 4)) + 'px';
			this.snow[i].style.left = (parseInt(this.snow[i].style.left) - (this.yp[i] / 4)) + 'px';
			cheight = this.snowh[i];
			this.snowh[i]=parseInt(this.snowh[i])+resizeimageby;
			document.getElementById("si"+i).height=this.snowh[i];
		}
		else
		{
			this.snowh[i] = Math.random()*8;
			this.snow[i].style.top =(pageheight/2) +((pageheight/2)/2) + 'px';
			this.snow[i].style.left = pagewidth/2 + 'px';
			this.snow[i].style.display = 'none';
			
		}
	}
	}
	if(isdancingFlag==1)
	timer9 = setTimeout(function(){self.starfield();}, this.gspeed);
}

var cheight=100;
var resizeimageby = 1;
dancingGraphic.prototype.snowfall3d=function() 
{
	
	if(isdancingFlag==0)
		clearTimeout(timer20);
	var self = this;
	var direction = this.otheroption;
	if(direction == 'left')
	 dx=-4;
		 else
	 dx=4;
	
	if(this.nddimgsize>150 && pageheight-this.nddimgsize > 100)
		resizeimageby = 2;
	for (var i = this.startflake; i < this.maxflakes; i++) {
		if(parseInt(this.snow[i].style.top) == parseInt(this.startpoint) && randomise(weight) == 1 || parseInt(this.snow[i].style.top) != parseInt(this.startpoint)){
			
			if(parseInt(this.snow[i].style.left) < (pagewidth - maxsize) - 2){
				this.snow[i].style.left =parseInt(this.snow[i].style.left) + dx + 'px'; 
				
				if(this.snowh[i]>0 && cheight>0)
				{
					cheight = this.snowh[i];
					this.snowh[i]=parseInt(this.snowh[i])-resizeimageby;
					document.getElementById("si"+i).height=this.snowh[i];
				}
				
			} else {
				this.snow[i].style.left = parseInt(this.snow[i].style.left) + dx + 'px';
			}
			if(isdancingFlag==0)
			{
				this.snow[i].style.top = randomise(pageheight) + 'px';
				this.snow[i].style.left = randomise(pagewidth) + 'px';
				this.snow[i].style.display = 'none';
				this.snowh[i]=this.nddimgsize;
				
			}
			else
			{
			if (parseInt(this.snow[i].style.top) < pageheight){
				this.snow[i].style.display = 'block';
				this.snow[i].style.top = (parseInt(this.snow[i].style.top) + (parseInt(this.snow[i].style.fontSize) / 4)) + 'px';
				
				if(this.snowh[i]>0 && cheight>0)
				{
					cheight = this.snowh[i];
					this.snowh[i]=parseInt(this.snowh[i])-resizeimageby;
					
					document.getElementById("si"+i).height=this.snowh[i];
				}
				
			} else {
				this.snow[i].style.top = randomise(pageheight) + 'px';
			this.snow[i].style.left = randomise(pagewidth) + 'px';
			this.snow[i].style.display = 'none';
			this.snowh[i]=this.nddimgsize;
			
			}
			}
		}
	}
	if(isdancingFlag==1)
	timer20 = setTimeout(function(){self.snowfall3d();}, this.gspeed);
}

function randomise(high, low) {	
	if(!low){ low = 0; }
	rand = Math.floor(Math.random() * (high - low + 1) + low)
	return rand;
}
function showdancing()
{
	isdancingFlag=1;
	var imgArray = document.getElementById('dancingGraphicImage').value;
	
	imgArray=imgArray.split("|");
	var modeArr = document.getElementById('dancingGraphicMode').value;
	modeArr=modeArr.split("|");
	var amtArr = document.getElementById('dancingGraphicImageAmount').value;
	amtArr=amtArr.split("|");
	var speedArr = document.getElementById('dancingGraphicSpeed').value;
	speedArr= speedArr.split("|");
	var otherOptArr = document.getElementById('dancingGraphicOtherOpt').value;
	otherOptArr=otherOptArr.split("|");
	var sizeArr = document.getElementById('dancingGraphicSize').value;
	sizeArr= sizeArr.split("|");
	var modestartpt=0
	var modeendpt=amtArr[0];
	for(var modlen=0;modlen<modeArr.length;modlen++)
	{
		if(modlen>0)
			modeendpt=parseInt(amtArr[modlen])+parseInt(modestartpt);
		
		adsStart=modestartpt;
		adsEnd=modeendpt;
		adsSpeed=speedArr[modlen];
		adsArr = imgArray[modlen];
		adsOther=otherOptArr[modlen];
		adsSize=sizeArr[modlen];
		secs=document.getElementById('dancingAdsInterval').value;
			
		if(modeArr[modlen]==1)
		{
			mode_no = 1;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==2)
		{
			mode_no = 2;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==3)
		{
			mode_no = 3;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==4)
		{
			mode_no = 4;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==5)
		{
			mode_no = 5;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==6)
		{
			mode_no = 6;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==7)
		{
			mode_no = 7;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==8)
		{
			mode_no = 8;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==9)
		{
			mode_no = 9;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==10)
		{
			mode_no = 10;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==11)
		{
			mode_no = 11;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==12)
		{
			mode_no = 12;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==13)
		{
			mode_no = 13;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==14)
		{
			mode_no = 14;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==15)
		{
			mode_no = 15;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==16)
		{
			mode_no = 16;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==17)
		{
			mode_no = 17;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize,68);
		}
		if(modeArr[modlen]==20)
		{
			mode_no = 20;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		if(modeArr[modlen]==50)
		{
			mode_no = 50;
			InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize);
		}
		modestartpt=parseInt(modeendpt);
	}
	createSnowFlag=1;
	return;
}
function hidedancing()
{
	isdancingFlag=0;
	var amtArr = document.getElementById('dancingGraphicImageAmount').value;
	amtArr=amtArr.split("|");
	var modeArr = document.getElementById('dancingGraphicMode').value;
	modeArr=modeArr.split("|");
	var totalamt=0;
	for(var i=0;i<amtArr.length;i++)
		totalamt += parseInt(amtArr[i]);
	for(var j= 0;j<totalamt;j++)
		document.getElementById("s" + j).style.display = 'none';
	return;
}
function hidedancingads()
{
	for(var j= adsStart;j<adsEnd;j++)
	{
		document.getElementById("s" + j).style.display = 'none';
	}
	return;
}
//var delay = document.getElementById('dancingAdsDelay').value;
setTimeout("toggleSnow()",5000 /*delay*/);
function toggleSnow()
{
	if(isdancing==1)
	{
		showdancing();
		isdancing=0;
	}
	else
	{
		isdancing=1;
		hidedancing();
	}	
}
var adsStart;
var adsEnd;
function setVisibility(id) {
	document.getElementById(id).style.display = 'none';
	if(id=="graphic_border_bottom")
	{
		document.getElementById('graphic_border_bottom_left_corner').style.display = 'none';
		document.getElementById('graphic_border_bottom_right_corner').style.display = 'none';
	}
	if(id=="graphic_border_top")
	{
		document.getElementById(id+'2').style.display = 'none';
		document.getElementById('graphic_border_top_right_corner').style.display = 'none';
		document.getElementById('graphic_border_top_left_corner').style.display = 'none';
	}
}

var secs;
var timerID = null;
var timerRunning = false;
var delay_tm = 1000;

function InitializeNddModes(adsStart,adsEnd,mode_no,adsSpeed,adsArr,adsOther,adsSize)
{
	secs = document.getElementById('dancingAdsInterval').value;
    StopTheClock(mode_no);
    StartTheTimer(mode_no);
}
function StopTheClock()
{
	if(mode_no == 1)
	{
		if(timerRunning);
			clearTimeout(timer1);
		 timerRunning = false;
	}
	if(mode_no == 2)
	{
		if(timerRunning);
			clearTimeout(timer2);
		 timerRunning = false;
	}
	if(mode_no == 3)
	{
		if(timerRunning);
			clearTimeout(timer3);
		 timerRunning = false;
	}
	if(mode_no == 4)
	{
		if(timerRunning);
			clearTimeout(timer4);
		 timerRunning = false;
	}
	if(mode_no == 5)
	{
		if(timerRunning);
			clearTimeout(timer5);
		 timerRunning = false;
	}
	if(mode_no == 6)
	{
		if(timerRunning);
			clearTimeout(timer6);
		 timerRunning = false;
	}
	if(mode_no == 7)
	{
		if(timerRunning);
			clearTimeout(timer7);
		 timerRunning = false;
	}
	if(mode_no == 8)
	{
		if(timerRunning);
			clearTimeout(timer8);
		 timerRunning = false;
	}
	if(mode_no == 9)
	{
		if(timerRunning);
			clearTimeout(timer9);
		 timerRunning = false;
	}
	if(mode_no == 10)
	{
		if(timerRunning);
			clearTimeout(timer10);
		 timerRunning = false;
	}
	if(mode_no == 11)
	{
		if(timerRunning);
			clearTimeout(timer11);
		 timerRunning = false;
	}
	if(mode_no == 12)
	{
		if(timerRunning);
			clearTimeout(timer12);
		 timerRunning = false;
	}
	if(mode_no == 13)
	{
		if(timerRunning);
			clearTimeout(timer13);
		 timerRunning = false;
	}
	if(mode_no == 14)
	{
		if(timerRunning);
			clearTimeout(timer14);
		 timerRunning = false;
	}
	if(mode_no == 15)
	{
		if(timerRunning);
			clearTimeout(timer15);
		 timerRunning = false;
	}
	if(mode_no == 16)
	{
		if(timerRunning);
			clearTimeout(timer16);
		 timerRunning = false;
	}
	if(mode_no == 17)
	{
		if(timerRunning);
			clearTimeout(timer17);
		 timerRunning = false;
	}
	if(mode_no == 20)
	{
		if(timerRunning);
			clearTimeout(timer20);
		 timerRunning = false;
	}
	if(mode_no == 50)
	{
		if(timerRunning);
			clearTimeout(timer50);
		 timerRunning = false;
	}
   
}
function StartTheTimer(mode_no)
{
	mode_no;
    if (secs==0)
    {
		timerRunning = false;
        StopTheClock(mode_no);
		hidedancingads();
		isdancingads=0;
		var badge_interval = document.getElementById('dancingAdsInterval').value;
		self.setTimeout("setadtime(mode_no)", badge_interval*1000)
		
    }
    else
    {
        secs = secs - 1
        timerRunning = true
		if(timerID==null)
		{
			var adsSpeed = document.getElementById('dancingGraphicSpeed').value;
			if(mode_no == 1)
			{
				var m1 = new dancingGraphic(adsStart,adsEnd,1,adsSpeed,adsArr,'');
				m1.snowfall();
			}
			if(mode_no == 2)
			{
				var m2 = new dancingGraphic(adsStart,adsEnd,2,adsSpeed,adsArr,'');
				m2.rainfall();
			}
			if(mode_no == 3)
			{
				var m3 = new dancingGraphic(adsStart,adsEnd,3,adsSpeed,adsArr,'');
				m3.balloons();
			}
			if(mode_no == 4)
			{
				var m4 = new dancingGraphic(adsStart,adsEnd,4,adsSpeed,adsArr,'');
				m4.autumnleaves();
			}
			if(mode_no == 5)
			{
				var m5 = new dancingGraphic(adsStart,adsEnd,5,adsSpeed,adsArr,'');
				m5.flutterby();
			}
			if(mode_no == 6)
			{
				var m6 = new dancingGraphic(adsStart,adsEnd,6,adsSpeed,adsArr,'');
				m6.bubbles();
			}
			if(mode_no == 7)
			{
				var m7 = new dancingGraphic(adsStart,adsEnd,7,adsSpeed,adsArr,'');
				m7.buzzby();
			}
			if(mode_no == 8)
			{
				var m8 = new dancingGraphic(adsStart,adsEnd,8,adsSpeed,adsArr,'');
				m8.fireworks();
			}
			if(mode_no == 9)
			{
				var m9 = new dancingGraphic(adsStart,adsEnd,9,adsSpeed,adsArr,'');
				m9.starfield();
			}
			if(mode_no == 10)
			{
				var m10 = new dancingGraphic(adsStart,adsEnd,10,adsSpeed,adsArr,'');
				m10.orbit();
			}
			if(mode_no == 11)
			{
				var m11 = new dancingGraphic(adsStart,adsEnd,11,adsSpeed,adsArr,68);
				m11.zerog();
			}
			if(mode_no == 12)
			{
				var m12 = new dancingGraphic(adsStart,adsEnd,12,adsSpeed,adsArr,68);
				m12.fountain1();
			}
			if(mode_no == 13)
			{
				var m13 = new dancingGraphic(adsStart,adsEnd,13,adsSpeed,adsArr,68);
				m13.fountain2();
			}
			if(mode_no == 14)
			{
				var m14 = new dancingGraphic(adsStart,adsEnd,14,adsSpeed,adsArr,68);
				m14.sprial();
			}
			if(mode_no == 15)
			{
				var m15 = new dancingGraphic(adsStart,adsEnd,15,adsSpeed,adsArr,68);
				m15.faery();
			}
			if(mode_no == 16)
			{
				var m16 = new dancingGraphic(adsStart,adsEnd,16,adsSpeed,adsArr,68);
				m16.bugz();
			}
			if(mode_no == 17)
			{
				var m17 = new dancingGraphic(adsStart,adsEnd,17,adsSpeed,adsArr,68);
				m17.diagonal();
			}
			if(mode_no == 20)
			{
				var m20 = new dancingGraphic(adsStart,adsEnd,20,adsSpeed,adsArr,'');
				m20.snowfall3d();
			}
			if(mode_no == 50)
			{
				var m50 = new dancingGraphic(adsStart,adsEnd,50,adsSpeed,adsArr,'');
				m50.showNddAds();
			}
		}
        timerID = self.setTimeout("StartTheTimer(mode_no)", delay_tm)
    }
}
function setadtime(mode_no)
{
	isdancingads=1;
	 secs = document.getElementById('dancingAdsInterval').value;
	 timerID = null;
	 StartTheTimer(mode_no);
}

var secs2;
var timerID2 = null;
var timerRunning2 = false;

function getorbitpoint(a,b,h,k)
{
	
	var x=0;
	var y=0;
	var tmp=new Array();
	while(true)
	{
		
		
			orbitt=Math.floor(Math.random()*90);
			
			x=Math.floor(a*Math.cos(orbitt));
			y=Math.floor(b*Math.sin(orbitt));
			x=a+x;
			y=b+y;
		
		orbits=x+':'+y;
		orbitarr2str = orbitval.toString();
		
		
		if(orbitarr2str.search(orbits)!= -1)
		continue;
		else
		break;
	}
	tmp[0]=x;
	tmp[1]=y;
	tmp[2]=orbits;
	tmp[3]=orbitt;
	
	return tmp;
	
}
function getzerogpoint(i)
{
	var tmp=new Array();
	c=Math.floor(Math.random()*4);
	switch(c)
	{
		case 3:
				x=Math.floor(Math.random()*pagewidth);
				y=0;
				break;
		case 2:
				y=Math.floor(Math.random()*pageheight);
				x=0;
				break;
		case 1:
				x=pagewidth;
				y=Math.floor(Math.random()*pageheight);
				break;
		case 0:
				x=Math.floor(Math.random()*pagewidth);
				y=pageheight;
				break;
	}
	
	tmp[0]=x;
	tmp[1]=y;
	tmp[2]=c;
	return tmp;
}
/*Array.prototype.exists = function(o,j) {
for(var i = 0; i < this.length; i++)
   if(i!=j)
   if(this[i] === o)
     return i;
return -1;
}*/

function collide(posx,posy,i,width,height,start)
{
	
	var tmp = -1;
	var flag=1;
	var p_x=posx[i];
	var p_y=posy[i];
	var width=parseInt(width)+parseInt(p_x);
	var height=parseInt(height)+parseInt(p_y);
	
	
	for(j=start;j<(posx.length+start);j++)
	{
		
		if(j!=i)
		{
			var p_find_x=parseInt(posx[j]);
			var p_find_y=parseInt(posy[j]);
			var r=insideSquare(width,height,p_x,p_y,p_find_x,p_find_y)	
			if(r)
			{tmp=j;flag=0;break;}
			
			var p_find_x=parseInt(posx[j]);
			var p_find_y=parseInt(posy[j])+height;
			var r=insideSquare(width,height,p_x,p_y,p_find_x,p_find_y)	
			if(r)
			{tmp=j;flag=0;break;}
			
			var p_find_x=parseInt(posx[j])+width;
			var p_find_y=parseInt(posy[j]);
			var r=insideSquare(width,height,p_x,p_y,p_find_x,p_find_y)	
			if(r)
			{tmp=j;flag=0;break;}
			
			var p_find_x=parseInt(posx[j])+width;
			var p_find_y=parseInt(posy[j])+height;
			var r=insideSquare(width,height,p_x,p_y,p_find_x,p_find_y)	
			if(r)
			{tmp=j;flag=0;break;}
			
		}
		if(flag==0)
		break;
	}
	return tmp;
	
}
function insideSquare(width,length,p_x,p_y,p_find_x,p_find_y)
{
	/*alert(width+','+length+','+p_x+','+p_y+','+p_find_x+','+p_find_y);*/
	if (p_find_x >= p_x && p_find_x <= width)
	{
		if (p_find_y >= p_y && p_find_y <= length)
		{
			return 1;
		}
	}
	
	return 0;
}
function addbug(posx,posy,side,length,imgwidth,imgheight,obj,pageheight,pagewidh)
{
	var tmp = new Array();
	//tmp[0] = left    tmp[1]= top
	switch(side)
	{
		case 0://top-1
				tmp[0]=posx;
				tmp[1]=posy+(length*imgheight);
				if(tmp[1]>pageheight)
				{
					tmp[1]=posy;
					obj.style.top=parseFloat(obj.style.top)-parseFloat(imgheight)+'px'; 
				}
				break;
		
		case 1://left-1
				tmp[0]=posx+(length*imgwidth);
				tmp[1]=posy;
				if(tmp[0]>pagewidth)
				{
					tmp[0]=posx;
					obj.style.left=parseFloat(obj.style.left)-parseFloat(imgwidth)+'px';
				}
				break;
		
		case 2://left+1
				tmp[0]=posx-(length*imgwidth);
				tmp[1]=posy;
				if(tmp[0]<0)
				{
					tmp[0]=posx;
					obj.style.left=parseFloat(obj.style.left)+parseFloat(imgwidth)+'px';
				}
				break;
		
		case 3://top+1
				tmp[0]=posx;
				tmp[1]=posy-(length*imgheight);
				if(tmp[1]<0)
				{
					tmp[1]=posy;
					obj.style.top=parseInt(obj.style.top)+parseFloat(imgheight)+'px';
				}
				
				break;
	}
	return tmp;
}
