function formSbm(id){
	$("form#"+id).submit();
}

$(document).ready(function(){
	var bgi = new BGImg();
	
	//adjust the height of the content if it's more than window height - logo height - 35 - 5% from window height
	// also add style to display scrollbar
	if(!$("body.book>div").attr('class')){
		updateCntH();
		$(window).resize(function(){
			updateCntH();
		});
	}
});

function updateCntH(){
	var cntH = $(".content>div").height();
	var windowH = $(window).height();
	var delta = windowH-35-125-36-10-$(".submenu").height()-parseInt(windowH*0.05)-80;
	
	if(delta<cntH){
		$(".content").css("overflowY","scroll");
		$(".content").height(delta);
	}else{
		$(".content").height(cntH);
		$(".content").css("overflowY","hidden");
	}
}

function BGImg(){

	var self = this;
	this.imgs = [];
	this.to = null;
	this.current = -1;
	this.delayBetweenImages = 7000;
	this.delayOfFade = 800;
	this.wheretoload = 1;
	this.zIndex = 0;
	this.url = "http://www.artentree.com/";

	this.play = function(){

		var self = this;
		//destroy previous timeout
		clearTimeout(this.to);

		//place the image and notes to the appropriate divs
		this.current++;
		if(this.current>this.imgs.length-1){this.current = 0;}

		this.loader = new ImageLoader(this.url+this.imgs[this.current][0]);
		//set event handler
		this.loader.loadEvent = function(url, image){

			var html  = "<img src='"+self.imgs[self.current][0]+"' border='0'/>";
			if(self.imgs[self.current][1]){
				html += "<div class='note'>"+self.imgs[self.current][1];
				if(self.imgs[self.current][2]){
					html += "<div class='subnote'>"+self.imgs[self.current][2]+"</div>";
				}
				html += "</div>";
			}
			self.wheretoload*=-1;
			$("#bgi"+self.wheretoload).css('zIndex',self.zIndex--);
			$("#bgi"+self.wheretoload).html(html);
			$("#bgi"+self.wheretoload).show();
			//now animate the disappearing of the current wheretoload
			$("#bgi"+self.wheretoload*(-1)).fadeOut(self.delayOfFade);
			//run timeout to play again if more than one image is to display
			if(self.imgs.length>1){
				self.to = setTimeout(function(){self.play();},self.delayBetweenImages);
			}

		}
		this.loader.load();

	};

	//construcor
	$("div.bg>ul>li").each(function(){
		var src  = $(this).contents().filter(function() { return this.nodeType == 3; });
		src = $(src).text();
		var note = $(this).find("ul>li:first-child").text();
		var subnote = $(this).find("ul>li:last-child").text();
		self.imgs.push([src, note, subnote]);
	});
		//create HTML structure for the image and remove the unneded .bg div from HTML
		$("div.bg").remove();
		$("body").append("<div id='bgi1'></div>");
		$("body").append("<div id='bgi-1'></div>");
	this.play();

}

function focusInput(el, value, classname){
	if($(el).val()==value){
		$(el).val('');
		$(el).attr('class',classname);
	}
}

function blurInput(el, value, classname){
	if($(el).val()==''){
		$(el).val(value);
		$(el).attr('class',classname);
	}
}

