window.onDOM = function() {
	
	window.featured_content_display = document.getElementById("featured_content_display");
	window.feed_next = document.getElementById("featured_show_next");
	window.feed_loading_indicator = document.getElementById("featured_loading_indicator");
	feed_next.onmousedown = function(e){if(!e)e=window.event;e.returnValue=false;return false;};
	feed_next.onselectstart = feed_next.onmousedown;
	feed_next.onmousemove = feed_next.onmousedown;
	feed_next.className += " featured_show_next";
	feed_next.onmouseover = function(){ this.className=this.className.replace(/\shover/mgi,"")+" hover"; };
	feed_next.onmouseout = function(){ this.className=this.className.replace(/\shover/mgi,""); };
	feed_next.onclick = function() {
		if(window.nextFeedRequest) {
			window.nextFeedRequest.cancelled = true;
			try{ window.nextFeedRequest.cancel(); }catch(e){}
		}
		function FeedReadHandler() {
			if(this.cancelled==true)
				return true;
			if(this.error==true) {
				window.feed_loading_indicator.style.visibility = "hidden";
				return true;
			}
			window.featured_content_display.innerHTML = this.data;
			window.feed_loading_indicator.style.visibility = "hidden";
		}
		window.nextFeedRequest = Request.create("/include/feed_read.php",null,FeedReadHandler,FeedReadHandler).Send();
		window.nextFeedRequest.cancelled = false;
		window.feed_loading_indicator.style.visibility = "visible";
	};
	
	// Mouseover Site Previews
	window.previewpanel = document.getElementById("cloud1_blog_previews");
	previewpanel._opac = 0;
	if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
		previewpanel.setOpac = function(opac) { this._opac=opac; this.style.filter = "alpha(opacity="+opac+")"; this.style.visibility = opac==0?"hidden":"visible"; };
	else
		previewpanel.setOpac = function(opac) { this._opac=opac; this.style.opacity = (opac/100)+""; this.style.visibility = opac==0?"hidden":"visible"; };
	previewpanel.setOpac(0);
	previewpanel.ClearTimers = function() {
		for(var x=0; x<this.opacity_timers.length; x++)
			if(this.opacity_timers[x])
				try{ window.clearTimeout(this.opacity_timers[x]); }catch(e){}
	};
	previewpanel.gracefulOpac = function(opac) {
		this.ClearTimers();
		if(opac==this._opac)
			return 0;
		var dir = opac>this._opac ? 1 : -1;
		var x;
		for(x=0; x<Math.abs(opac-this._opac); x+=10)
			this.opacity_timers.push( window.setTimeout("window.previewpanel.setOpac("+(this._opac+(dir*x))+");", x*2) );
		this.opacity_timers.push( window.setTimeout("window.previewpanel.setOpac("+opac+");", x*2+10) );
		return x*2+10;
	};
	previewpanel.resetImages = function(zeroHeight) {
		if(this._killTimer)
			try{window.clearTimeout(this._killTimer);}catch(e){}
		if(zeroHeight==false)
			return true;
		var imgs = this.getElementsByTagName("img");
		for(var x=0; x<imgs.length; x++) {
			imgs[x].style.height = "0";
			imgs[x].style.visibility = "hidden";
		}
	};
	
	var a = document.getElementById("cloud1_blog_links").getElementsByTagName("a");
	previewpanel.opacity_timers = [];
	var img = previewpanel.getElementsByTagName("img");
	for(var x=0; x<a.length; x++) {
		a[x].onmouseover = function(){
			window.previewpanel.resetImages();
			this._img.style.height = "auto";
			this._img.style.visibility = "visible";
			window.previewpanel.gracefulOpac(100);
		};
		a[x].onmouseout = function(){
			this.blur();
			window.previewpanel.resetImages(false);
			var delay = window.previewpanel.gracefulOpac(0);
			window.previewpanel._killTimer = window.setTimeout("window.previewpanel.currentimage.style.height='0';", delay);
		};
		a[x].onclick = a[x].onmouseout;
		a[x]._img = img[x];
	}
	
	// Email Form Open Link:
	var link = document.getElementById("blog_request_open");
	
	window.blogRequestFormOverlay = document.getElementById("blog_request_form_overlay");
	
	window.blogRequestForm = document.getElementById("blog_request_form");
	window.blogRequestForm.style.top = -window.blogRequestForm.offsetHeight+"px";
	window.blogRequestForm._open = false;
	window.blogRequestForm._timer = null;
	window.blogRequestForm.animationStep = 32;
	window.blogRequestForm._animate = function() {
		var dir = this.offsetTop>this.animationTarget ? -1 : 1;
		if(dir==1) {
			if(Math.abs(this.offsetTop) > Math.abs(this.animationStart+this.animationTarget)/2)
				var step = this.animationStep - (Math.abs(this.animationTarget-this.offsetTop)/Math.abs(this.animationTarget-this.animationStart)*29);
			else
				var step = this.animationStep - (29-Math.abs(this.animationTarget-this.offsetTop)/Math.abs(this.animationTarget-this.animationStart)*29);
		}
		else {
			if(Math.abs(this.offsetTop) > Math.abs(this.animationStart+this.animationTarget)/2)
				var step = this.animationStep - (29-Math.abs(this.animationTarget-this.offsetTop)/Math.abs(this.animationTarget-this.animationStart)*29);
			else
				var step = this.animationStep - (Math.abs(this.animationTarget-this.offsetTop)/Math.abs(this.animationTarget-this.animationStart)*29);
		}
		
		
		if(Math.abs(this.offsetTop-this.animationTarget)<step) {
			this.style.top = this.animationTarget+'px';
			window.clearTimeout(this._timer);
			this._timer = null;
		}
		else
			this.style.top = (this.offsetTop + dir*step)+'px';
	};
	window.blogRequestForm.Slide = function(direction) {
		this._open = (direction==1 || direction==-1) ? direction : !this._open;
		
		this.animationStart = this.offsetTop;
		this.animationTarget = this._open==true ? 0 : -this.offsetHeight;
		if(this._timer==null || this._timer=="undefined") {
			try{ window.clearInterval(this._timer); }catch(e){}
			this._timer = window.setInterval("window.blogRequestForm._animate();", 20);
		}
	};
	
	if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
		window.blogRequestFormOverlay.style.filter = "alpha(opacity=0)";
	else
		window.blogRequestFormOverlay.style.opacity = 0;
	
	window.blogRequestFormOverlay._opacity = 0;
	window.blogRequestFormOverlay.animationStep = 10;
	window.blogRequestFormOverlay._animate = function() {
		var dir = this.animationTarget>this._opacity ? 1 : -1;
		this._opacity += dir * this.animationStep;
		
		if(dir==-1)
			window.blogRequestFormOverlay.style.display = "block";
		
		if(Math.abs(this._opacity-this.animationTarget)<this.animationStep) {
			this._opacity = this.animationTarget;
			window.clearInterval(this._timer);
			this._timer = null;
			if(dir==-1)
				window.blogRequestFormOverlay.style.display = "none";
		}
		if(document.all	&& document.body.filters && !window.opera && parseFloat(navigator.appVersion)<8)
			this.style.filter = "alpha(opacity="+this._opacity+")";
		else
			this.style.opacity = this._opacity/100;
	};
	window.ShowBlogRequestForm = function() {
		window.blogRequestFormOverlay.style.display = "block";
		window.blogRequestFormOverlay.animationTarget = 70;
		if(window.blogRequestFormOverlay._timer==null || window.blogRequestFormOverlay._timer=="undefined")
			window.blogRequestFormOverlay._timer = window.setInterval("window.blogRequestFormOverlay._animate();", 30);
		window.blogRequestForm.Slide(1);
	};
	window.HideBlogRequestForm = function() {
		window.blogRequestFormOverlay.animationTarget = 0;
		if(window.blogRequestFormOverlay._timer==null || window.blogRequestFormOverlay._timer=="undefined")
			window.blogRequestFormOverlay._timer = window.setInterval("window.blogRequestFormOverlay._animate();", 30);
		window.blogRequestForm.Slide(-1);
	};
	
	
	link.onclick = function(e) {
		if(window.blogRequestForm.animationTarget==null || Math.abs(window.blogRequestForm.animationTarget)>window.blogRequestForm.offsetHeight/2)
			window.ShowBlogRequestForm();
		else
			window.HideBlogRequestForm();
		
		this.blur();
		e.returnValue = false;
		if(e.preventDefault)
			e.preventDefault();
		return false;
	};
	document.getElementById("blog_request_form_cancel").onclick = function(e) {
		window.HideBlogRequestForm();
		
		this.blur();
		e.returnValue = false;
		if(e.preventDefault)
			e.preventDefault();
		return false;
	};
};
window._waitForDOM = window.setInterval("if(document && document.body && document.getElementById && document.body.childNodes && document.getElementById('blog_request_open')){ window.clearInterval(window._waitForDOM); window.setTimeout('window.onDOM();',200); }", 100);


window.SubmitBlogRequest = function() {
	var inputs = window.blogRequestForm.getElementsByTagName("input");
	var textareas = window.blogRequestForm.getElementsByTagName("textarea");
	var postdata = {};
	for(var x=0; x<inputs.length; x++)
		if(inputs[x].type && inputs[x].id)
			postdata[inputs[x].id] = inputs[x].value;
	for(var x=0; x<textareas.length; x++)
		if(textareas[x].id)
			postdata[textareas[x].id] = textareas[x].value;
	function oncomplete() {
		if(this.error==true)
			alert("There was an error. Please send an email to admin@cloud1.me");
		else {
			try{ var JSON = window.eval('('+this.data+')'); }catch(e){ var JSON = {result:false,message:'Unknow error.'} }
			if(JSON.result==true) {
				window.blogRequestForm._open = true;
				window.HideBlogRequestForm();
				document.getElementById("blog_request_open").innerHTML = "Your request has been sent.";
				document.getElementById("blog_request_open").onclick=function(){ return false; };
			}
			else {
				// email or other error:
				alert(JSON.message);
			}
		}
	}
	var req = Request.create("submit_blog.php",postdata,oncomplete,oncomplete,true).send();
};