// JavaScript Document
//Fade Plugin

(function(c){var b=[];var a=[];c.fn.xfade=function(d){return this.each(function(e){a.push(c(this));b[e]={container:null,settings:{effect:"fade",speed:"normal",order:"sequence",timeout:2000,height:"auto",containerClass:false,children:false,onBefore:false},timeout:200,current:1,last:0,init:function(f,g){var j=this;j.container=f;if(g){c.extend(j.settings,g)}var k=j.items();if(k.length>1){c(j.container).css({position:"relative",height:j.settings.height});if(j.settings.containerClass){c(j.container).addClass(j.settings.containerClass)}for(var h=0;h<k.length;h++){c(k[h]).css("z-index",String(k.length-h)).css("position","absolute").hide()}if(j.settings.order=="sequence"){j.onBefore(0,null,c(k[0]),null,k);j.timeout=setTimeout(function(){j.next()},j.settings.timeout);c(k[j.last]).show()}else{if(j.settings.order=="random"){j.last=Math.floor(Math.random()*k.length);do{j.current=Math.floor(Math.random()*k.length)}while(j.last==j.current);j.onBefore(j.current,j.last,c(k[j.current]),c(k[j.last]),k);j.timeout=setTimeout(function(){j.next()},j.settings.timeout);c(k[j.current]).show()}else{if(j.settings.order=="random-start"){j.settings.order="sequence";j.current=Math.floor(Math.random()*k.length);j.onBefore(j.current,j.last,c(k[j.current]),c(k[j.last]),k);j.timeout=setTimeout(function(){j.next()},j.settings.timeout);c(k[j.current]).show()}else{alert("xfade:order must either be 'sequence', 'random' or 'random-start'")}}}}},items:function(){var f=this;if(f.settings.children){return c(f.container).children()}else{return c(f.container).children(f.settings.children)}},next:function(){var f=this;var g=f.items();f.onBefore(f.current,f.last,c(g[f.current]),c(g[f.last]),g);if(f.settings.effect=="slide"){c(g[f.last]).slideUp(f.settings.speed);c(g[f.current]).slideDown(f.settings.speed)}else{if(f.settings.effect=="fade"){c(g[f.last]).fadeOut(f.settings.speed);c(g[f.current]).fadeIn(f.settings.speed,function(){removeFilter(c(this)[0])})}else{alert("xfade:effect must either be 'slide' or 'fade'")}}if(f.settings.order=="sequence"){if((f.current+1)<g.length){f.current+=1;f.last=f.current-1}else{f.current=0;f.last=g.length-1}}else{if(f.settings.order=="random"){f.last=f.current;while(f.current==f.last){f.current=Math.floor(Math.random()*g.length)}}else{alert("xfade:order must either be 'sequence', 'random' or 'random-start'")}}f.timeout=setTimeout((function(){f.next(g)}),f.settings.timeout)},to:function(f){var g=this;if(typeof(f)=="object"&&f.jquery){if(f.length==0){return false}c.each(g.items(),function(h){if(c(this)[0]==f[0]){f=h}})}c.each(g.items(),function(){if(c(this).css("display")!="none"){c(this).fadeOut()}});clearTimeout(g.timeout);g.current=f;g.next()},refresh:function(){var f=this;var g=f.items();c.each(g,function(h){c(this).css({"z-index":String(g.length-h),position:"absolute"});if(h!=f.last){c(this).css({display:"none"})}})},onBefore:function(k,i,f,g,j){var h=this;if(typeof(h.settings.onBefore)=="function"){h.settings.onBefore(k,i,f,g,j)}}};b[e].init(this,d)})};c.xfadeInstance=function(d){var e=0;do{if(c(a[e]).get(0)==c(d).get(0)){return b[e]}e++}while(e<a.length-1);return false};c.fn.xfadeNext=function(){var d=c.xfadeInstance(this);if(d){d.next()}};c.fn.xfadeTo=function(e){var d=c.xfadeInstance(this);if(d){d.to(e)}};c.fn.xfadeRefresh=function(e){var d=c.xfadeInstance(this);if(d){d.refresh(e)}}})(jQuery);function removeFilter(a){if(a.style.removeAttribute){a.style.removeAttribute("filter")}};


function initPage()
{
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filterClass) o.filterClass = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass) == -1) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);
	
	

// jQuery scripting
$(document).ready(function() {

	$('#news-posts').xfade({height: 20, timeout: 7000});
	
	$('form > span').click(function() { $(this).children('input').focus(); });

});

