Body= {};
Util= {};
//Effect= {};

$(document).ready(function () {	
	//Effect.set();
	Body.set();
	//window.setTimeout(Body.set, 100);
	
	/* init lightbox */
	if($(".lightbox")) {
		$(".lightbox").lightbox();
	}
	/* start */
	if($("#start")) {
		var lang= $("#language").html();
		$('#flash').flash({
		    src: '/_flash/humer.swf',
		    width: 960,
		    height: 540,
			id: 'humer',
			name: 'humer',
			flashvars: { language: lang, xml: '_flash/config.xml' }
		}).show();
	}
});
$(window).bind('resize', function() {	
	//Body.set();
});

Body= {
	set: function() {
		var dimension= Util.getWindowSize();
		var pageHeight= dimension[1];
		var windowHeight= dimension[3];
		
		var height= pageHeight;
		
		if(windowHeight>pageHeight) {
			height= windowHeight;
		}
		
		var leftHeight= height-143-32-263; /*  header-margin-footer */
		var rightHeight= height-143-20-83; /* header-margin-footer */

		if(BrowserDetect.browser=="Explorer") {
			leftHeight+= 5;
		} else {
			rightHeight-=5;
		}
		$("#page .left .content").css("height", leftHeight);
		$("#page .right .content").css("height", rightHeight);
		
		Menu.init();
	} 
};

Util= {
	getWindowSize: function(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight) {
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else if(document.body) { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		if(yScroll < windowHeight) {
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		if(xScroll < windowWidth) {
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}

		var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	},
	submitForm: function(id) {
		if(Util.validateForm(id)) {
			 $("#form_shop").get(0).submit();
		}
	},
	validateForm: function(id) {
		var result= true;
		$("#"+id + " input, #"+id + " textarea").each(function() {
			if($(this).attr("class") && $(this).attr("class").match("required")) {
				var itemresult= Util.validate($(this).attr("id"));
				result= result && itemresult;
			}
		});
		if(result) {
			$("#form_error").removeClass("error");
		} else {
			$("#form_error").addClass("error");
		}
		return result;
	},
	validate: function(id) {
		var result= true;
		var obj= $("#"+id);
		var commands= $("#"+id).attr("class").split(" ");
		for(var i=0; i<commands.length; i++) {
			var command= commands[i].replace(/[0-9]/g, "");
			switch(command) {
				case("minlength"):
					var length= parseInt(commands[i].replace(/minlength/g, ""));
					result= result && (obj.val().length>=length);
					break;
				case("maxlength"):
					var length= parseInt(commands[i]);
					result= result && (obj.val().length<=length);
					break;
				case("email"):
					result = result && ( obj.get(0).value.match(/\S@\S.\S{2,}/)!=null )
					break;
				default:
					result= result && (obj.val().length!=0);
					break;
			}
		}
		if(!result) {
			obj.addClass("error");
		} else {
			obj.removeClass("error");
		}
		return result;
	}
}

Effect= {
	shopHover: function(type, image, height, position) {
		var top= 24; //for list
		if(type=="search") {
			top= -26;
		}
		$("#shophover .hovercontent").html('<img src="'+image+'" />');
		if(height<198) {
			$("#shophover .hovercontent img").css("padding-top", (198-height)/2);
		}
		$("#shophover").css("top", top+(38*position));
		$("#shophover").show();
	},
	shopHoverOff: function() {
		$("#shophover").hide();
	}
}

Menu= {
	init: function() {
		$(".startmenu a").hover(function() {
			var startmenu= $(this);
			$(".navigation li a").each(function() {
				var navigation= $(this);
				if(startmenu.attr("href")==navigation.attr("href")) {
					navigation.addClass("hover");
				}
			});
		}, function() {
			$(".navigation li a").removeClass("hover");
		});
		
		$(".navigation li a").hover(function() {
			var navigation= $(this);
			$(".startmenu a").each(function() {
				var startmenu= $(this);
				if(startmenu.attr("href")==navigation.attr("href")) {
					startmenu.addClass("hover");
				}
			});
		}, function() {
			$(".startmenu a").removeClass("hover");
		});
	}
}