var SmokeEffect = {
	
	imgLocation: "/sites/all/themes/sky/images/smoke/smoke.png", //url to image here
	smokeWidth: 10, //standard width
	smokeHeight: 18, //standard height
	
	//don't touch this:
	smokePos: new Array(),
		
	makeEffect: function(id, posX, posY) {
		//set position from the "parent"
		SmokeEffect.smokePos[id] = new Array();
		SmokeEffect.smokePos[id]['x'] = posX;
		SmokeEffect.smokePos[id]['y'] = posY;
		
		//set a random time to start puffing
		var time = (Math.floor(Math.random()*3001));
		setTimeout("SmokeEffect.animate('" + id + "')", time);
	},
	
	animate: function(id) {

		//create the smoke cloud
		var puff = document.createElement("IMG");
		$(puff).attr("src", SmokeEffect.imgLocation);
		$(puff).attr("alt", "");
		$(puff).attr("class", "puff");
		
		//create a temp id for the cloud so we can delete it later on
		var tempId = "puff" + Math.floor(Math.random()*1001);
		$(puff).attr("id", tempId);
		
		//append the cloud to the body
		$(document.body).append($(puff));
		
		var objPos = $('#' + id).offset();
		
		//do smoke animation
		$(puff).css({
			top: (objPos['top'] + SmokeEffect.smokePos[id]['y']) + "px",
			left: (objPos['left'] + SmokeEffect.smokePos[id]['x']) + "px",
			zIndex: 1000,
			opacity: 0.4
		});
		$(puff).animate({
			width: SmokeEffect.smokeWidth + "px",
			height: SmokeEffect.smokeHeight + "px",
			marginLeft: "-" + (SmokeEffect.smokeWidth / 2) + "px",
			marginTop: "-" + (SmokeEffect.smokeHeight * 1) + "px",
			opacity: .6
		},{
			duration: 1500
		}).animate({
			marginTop: "-" + (SmokeEffect.smokeHeight * 1.5) + "px",
			opacity: 0.0
		},{
			duration: 2500
		});
		
		//create timeout and run the animation again
		var time = 800 + (Math.floor(Math.random()*1001));
		
		setTimeout("SmokeEffect.animate('" + id + "')", time);
		
		//remove the old one
		setTimeout("$('#" + tempId + "').remove()", 4200);
		
	}
}

var SmokeEffect1 = {
	
	imgLocation: "/sites/all/themes/sky/images/smoke/smoke2.png", //url to image here
	smokeWidth: 11, //standard width
	smokeHeight: 16, //standard height
	
	//don't touch this:
	smokePos: new Array(),
		
	makeEffect: function(id, posX, posY) {
		//set position from the "parent"
		SmokeEffect1.smokePos[id] = new Array();
		SmokeEffect1.smokePos[id]['x'] = posX;
		SmokeEffect1.smokePos[id]['y'] = posY;
		
		//set a random time to start puffing
		var time = (Math.floor(Math.random()*3001));
		setTimeout("SmokeEffect1.animate('" + id + "')", time);
	},
	
	animate: function(id) {

		//create the smoke cloud
		var puff1 = document.createElement("IMG");
		$(puff1).attr("src", SmokeEffect1.imgLocation);
		$(puff1).attr("alt", "");
		$(puff1).attr("class", "puff1");
		
		//create a temp id for the cloud so we can delete it later on
		var tempId = "puff" + Math.floor(Math.random()*1001);
		$(puff1).attr("id", tempId);
		
		//append the cloud to the body
		$(document.body).append($(puff1));
		
		var objPos = $('#' + id).offset();
		
		//do smoke animation
		$(puff1).css({
			top: (objPos['top'] + SmokeEffect1.smokePos[id]['y']) + "px",
			left: (objPos['left'] + SmokeEffect1.smokePos[id]['x']) + "px",
			zIndex: 1000,
			opacity: 0.4
		});
		$(puff1).animate({
			width: SmokeEffect1.smokeWidth + "px",
			height: SmokeEffect1.smokeHeight + "px",
			marginLeft: "-" + (SmokeEffect1.smokeWidth * -1) + "px",
			marginTop: "-" + (SmokeEffect1.smokeHeight * 1.5) + "px",
			opacity: .6
		},{
			duration: 1500
		}).animate({
			marginLeft: "+" + (SmokeEffect1.smokeWidth * .5) + "px",
			marginTop: "-" + (SmokeEffect1.smokeHeight * 2) + "px",
			opacity: 0.0
		},{
			duration: 2500
		});
		
		//create timeout and run the animation again
		var time = 1500 + (Math.floor(Math.random()*3501));
		
		setTimeout("SmokeEffect1.animate('" + id + "')", time);
		
		//remove the old one
		setTimeout("$('#" + tempId + "').remove()", 4200);
		
	}
}

var SmokeEffect2 = {
	
	imgLocation: "/sites/all/themes/sky/images/smoke/smoke1.png", //url to image here
	smokeWidth: 11, //standard width
	smokeHeight: 16, //standard height
	
	//don't touch this:
	smokePos: new Array(),
		
	makeEffect: function(id, posX, posY) {
		//set position from the "parent"
		SmokeEffect2.smokePos[id] = new Array();
		SmokeEffect2.smokePos[id]['x'] = posX;
		SmokeEffect2.smokePos[id]['y'] = posY;
		
		//set a random time to start puffing
		var time = (Math.floor(Math.random()*3001));
		setTimeout("SmokeEffect2.animate('" + id + "')", time);
	},
	
	animate: function(id) {

		//create the smoke cloud
		var puff2 = document.createElement("IMG");
		$(puff2).attr("src", SmokeEffect2.imgLocation);
		$(puff2).attr("alt", "");
		$(puff2).attr("class", "puff2");
		
		//create a temp id for the cloud so we can delete it later on
		var tempId = "puff2" + Math.floor(Math.random()*1001);
		$(puff2).attr("id", tempId);
		
		//append the cloud to the body
		$(document.body).append($(puff2));
		
		var objPos = $('#' + id).offset();
		
		//do smoke animation
		$(puff2).css({
			top: (objPos['top'] + SmokeEffect2.smokePos[id]['y']) + "px",
			left: (objPos['left'] + SmokeEffect2.smokePos[id]['x']) + "px",
			zIndex: 1000,
			opacity: 0.4
		});
		$(puff2).animate({
			width: SmokeEffect2.smokeWidth + "px",
			height: SmokeEffect2.smokeHeight + "px",
			marginLeft: "-" + (SmokeEffect1.smokeWidth * 1) + "px",
			marginTop: "-" + (SmokeEffect2.smokeHeight * 1.5) + "px",
			opacity: .6
		},{
			duration: 1500
		}).animate({
			marginLeft: "-" + (SmokeEffect1.smokeWidth * 1.5) + "px",
			marginTop: "-" + (SmokeEffect2.smokeHeight * 2) + "px",
			opacity: 0.0
		},{
			duration: 2500
		});
		
		//create timeout and run the animation again
		var time = 1500 + (Math.floor(Math.random()*2501));
		
		setTimeout("SmokeEffect2.animate('" + id + "')", time);
		
		//remove the old one
		setTimeout("$('#" + tempId + "').remove()", 4200);
		
	}
}

SmokeEffect.makeEffect("smokeSpawn", 10, 18);
SmokeEffect2.makeEffect("smokeSpawn1", 11, 16);
SmokeEffect1.makeEffect("smokeSpawn2", 11, 16);
