$( function () {
      	$("div.header_rotator div:not(:first)").hide();
      	$("div.footer_rotator div:not(:first)").hide();
      	$("div.header_rotator div:first").addClass("current");
      	$("div.footer_rotator div:first").addClass("current");
      	

      	setInterval( function () {
      		var $hactive = $("div.header_rotator div.current");    		
          var $factive = $("div.footer_rotator div.current");    		

      		if($hactive.length == 0)
      			$hactive = $("div.header_rotator div:first");
          if($factive.length == 0)
      			$factive = $("div.footer_rotator div:first");

      			

      		$hnext = $hactive.next().length ? $hactive.next() : $("div.header_rotator div:first");     		
      		$hactive.removeClass("current").fadeOut(1000, function () {
            $hnext.addClass("current").fadeIn(2000);
          });

      		$fnext = $factive.next().length ? $factive.next() : $("div.footer_rotator div:first");     		
      		$factive.removeClass("current").fadeOut(1000, function () {
            $fnext.addClass("current").fadeIn(2000);
          });          
          
      	}, 15000);

      });

function bindReady(handler){
	var called = false
	function ready() {
		if (called) return
		called = true
		handler()
	}
	if (document.addEventListener) {
		document.addEventListener( "DOMContentLoaded", ready, false )
	} else if (document.attachEvent) {
		if (document.documentElement.doScroll && window == window.top) {
			function tryScroll(){
				if (called) return
				if (!document.body) return
				try {
					document.documentElement.doScroll("left")
					ready()
				} catch(e) {
					setTimeout(tryScroll, 0)
				}
			}
			tryScroll()
		}
		document.attachEvent("onreadystatechange", function(){
			if ( document.readyState === "complete" ) {
				ready()
			}
		})
	}
	if (window.addEventListener) window.addEventListener('load', ready, false)
	else if (window.attachEvent) window.attachEvent('onload', ready)
}
bindReady(function(){
  
  
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
	/*initAutoScalingNav({
		menuId: "nav",
		sideClasses: true,
		equalLinks: false,
		minPaddings: 0
	});*/
})

// Clear inputs
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";
	}
}

// AutoScalingNav
function initAutoScalingNav(o) {
	if (!o.menuId) o.menuId = "nav";
	if (!o.tag) o.tag = "a";
	if (!o.spacing) o.spacing = 0;
	if (!o.constant) o.constant = 0;
	if (!o.minPaddings) o.minPaddings = 0;
	if (!o.liHovering) o.liHovering = false;
	if (!o.sideClasses) o.sideClasses = false;
	if (!o.equalLinks) o.equalLinks = false;
	if (!o.flexible) o.flexible = false;
	var nav = document.getElementById(o.menuId);
	if(nav) {
		nav.className += " scaling-active";
		var lis = nav.getElementsByTagName("li");
		var asFl = [];
		var lisFl = [];
		var width = 0;
		for (var i=0, j=0; i<lis.length; i++) {
			if(lis[i].parentNode == nav) {
				var t = lis[i].getElementsByTagName(o.tag).item(0);
				asFl.push(t);
				asFl[j++].width = t.offsetWidth;
				lisFl.push(lis[i]);
				if(width < t.offsetWidth) width = t.offsetWidth;
			}
			if(o.liHovering) {
				lis[i].onmouseover = function() {
					this.className += " hover";
				}
				lis[i].onmouseout = function() {
					this.className = this.className.replace("hover", "");
				}
			}
		}
		var menuWidth = nav.clientWidth - asFl.length*o.spacing - o.constant;
		if(o.equalLinks && width * asFl.length < menuWidth) {
			for (var i=0; i<asFl.length; i++) {
				asFl[i].width = width;
			}
		}
		width = getItemsWidth(asFl);
		if(width < menuWidth) {
			var version = navigator.userAgent.toLowerCase();
			for (var i=0; getItemsWidth(asFl) < menuWidth; i++) {
				asFl[i].width++;
				if(!o.flexible) {
					asFl[i].style.width = asFl[i].width + "px";
				}
				if(i >= asFl.length-1) i=-1;
			}
			if(o.flexible) {
				for (var i=0; i<asFl.length; i++) {
					width = (asFl[i].width - o.spacing - o.constant/asFl.length)/menuWidth*100;
					if(i != asFl.length-1) {
						lisFl[i].style.width = width + "%";
					}
					else {
						if(navigator.appName.indexOf("Microsoft Internet Explorer") == -1 || version.indexOf("msie 8") != -1 || version.indexOf("msie 9") != -1)
							lisFl[i].style.width = width + "%";
					}
				}
			}
		}
		else if(o.minPaddings > 0) {
			for (var i=0; i<asFl.length; i++) {
				asFl[i].style.paddingLeft = o.minPaddings + "px";
				asFl[i].style.paddingRight = o.minPaddings + "px";
			}
		}
		if(o.sideClasses) {
			lisFl[0].className += " first-child";
			lisFl[0].getElementsByTagName(o.tag).item(0).className += " first-child-a";
			lisFl[lisFl.length-1].className += " last-child";
			lisFl[lisFl.length-1].getElementsByTagName(o.tag).item(0).className += " last-child-a";
		}
		nav.className += " scaling-ready";
	}
	function getItemsWidth(a) {
		var w = 0;
		for(var q=0; q<a.length; q++) {
			w += a[q].width;
		}
		return w;
	}
}

//<![CDATA[
	var mobi = ['opera', 'iemobile', 'webos', 'android', 'blackberry', 'ipad', 'iphone', 'safari'];
	var midp = ['blackberry', 'symbian'];
	var ua = navigator.userAgent.toLowerCase();
		if ((ua.indexOf('midp') != -1) || (ua.indexOf('mobi') != -1) || ((ua.indexOf('ppc') != -1) && (ua.indexOf('mac') == -1)) || (ua.indexOf('webos') != -1)) {
			document.write('<link rel="stylesheet" href="css/allmobile.css" type="text/css" media="all"/>');
				if (ua.indexOf('midp') != -1) {
					for (var i = 0; i < midp.length; i++) {
						if (ua.indexOf(midp[i]) != -1) {
							document.write('<link rel="stylesheet" href="css/' + midp[i] + '.css" type="text/css"/>');
						}
					}
				}
			else {
				if ((ua.indexOf('mobi') != -1) || (ua.indexOf('ppc') != -1) || (ua.indexOf('webos') != -1)) {
					for (var i = 0; i < mobi.length; i++) {
						if (ua.indexOf(mobi[i]) != -1) {
						if ((mobi[i].indexOf('blackberry') != -1) && (ua.indexOf('6.0') != -1)) {
							document.write('<link rel="stylesheet" href="css/' + mobi[i] + '.css" type="text/css"/>');
								}
							else {
								document.write('<link rel="stylesheet" href="css/' + mobi[i] + '.css" type="text/css"/>');
							}
						break;
					}
				}
			}
		}
	}
//]]>


var view;
function initResize() {
	viewa = document.getElementById("bga");
	viewb = document.getElementById("bgb");
	viewc = document.getElementById("bgc");
	viewd = document.getElementById("bgd");
	if(viewa) {
		viewa.width = viewa.clientWidth;
		viewb.width = viewb.clientWidth;
		viewc.width = viewc.clientWidth;
		viewd.width = viewd.clientWidth;
		//view.height = view.clientHeight;
		initBg();
		setTimeout("initBg()", 10);
	}
}
function initBg() {
	var w = document.documentElement.offsetWidth;
	var h = document.documentElement.offsetHeight;
	var pr = viewa.width/viewa.height;
	var spr = w/h;
	
	if(spr > pr) {
		viewa.style.width = w + "px";
		viewa.style.left = 0 + "px";
		viewa.style.top = h/2-viewa.height/2 + "px";
		viewa.width = w;
		
		viewb.style.width = w + "px";
		viewb.style.left = 0 + "px";
		viewb.style.top = h/2-viewb.height/2 + "px";
		viewb.width = w;
		
		viewc.style.width = w + "px";
		viewc.style.left = 0 + "px";
		viewc.style.top = h/2-viewc.height/2 + "px";
		viewc.width = w;
		
		viewd.style.width = w + "px";
		viewd.style.left = 0 + "px";
		viewd.style.top = h/2-viewd.height/2 + "px";
		viewd.width = w;
	}
	else {
		viewa.style.width = h*pr + "px";
		viewa.style.top = 0 + "px";
		viewa.style.left = w/2-viewa.width/2 + "px";
		viewa.width = h*pr;

		viewb.style.width = h*pr + "px";
		viewb.style.top = 0 + "px";
		viewb.style.left = w/2-viewb.width/2 + "px";
		viewb.width = h*pr;

		viewc.style.width = h*pr + "px";
		viewc.style.top = 0 + "px";
		viewc.style.left = w/2-viewc.width/2 + "px";
		viewc.width = h*pr;

		viewd.style.width = h*pr + "px";
		viewd.style.top = 0 + "px";
		viewd.style.left = w/2-viewd.width/2 + "px";
		viewd.width = h*pr;

	}
}
if (window.addEventListener) {
	window.addEventListener("load", initResize, false);
	window.addEventListener("resize", initResize, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initResize);
	window.attachEvent("onresize", initResize);
}
