function placeButtons(){
	for (a=1; a<=5; a++){
		var offset = $("#wel" + a).offset(); 
		var btn = document.getElementById('btn'+a);
		btn.style.left = offset.left + 2 +"px";
		btn.style.top = offset.top + 2 + 10 + "px";
		for (i=1; i<=5; i++){
			var img = document.getElementById("welimg" + a + i);
			img.style.position = "absolute";
			img.style.left = offset.left + 2 +"px";
			img.style.top = offset.top + 2 + "px";
			if (i==1){
				img.style.display = "block";
			}
		}
	}
}
function btnOver(img){
	var progress = document.getElementById("progress").value;
	if (progress == 0){
		progress = 1;
		for (q=1; q<=5; q++){
			var obj = document.getElementById("welimg" + img + q);
			if (obj.style.display == "block" && obj.style.zIndex == 0){
				var btnold = q;
			}
		}
		if (img!=btnold){
			$("#welimg5" + img).delay(0).show("slide", { direction: "right" }, 300, function(){
					document.getElementById("welimg5" + img).style.display = "block";
					document.getElementById("welimg5" + img).style.zIndex = 0;
					document.getElementById("welimg5" + btnold).style.display = "none";
					document.getElementById("welimg5" + btnold).style.zIndex = 1;
					progress = 0;
			});
			$("#welimg4" + img).delay(100).show("slide", { direction: "right" }, 300, function(){
					document.getElementById("welimg4" + img).style.display = "block";
					document.getElementById("welimg4" + img).style.zIndex = 0;
					document.getElementById("welimg4" + btnold).style.display = "none";
					document.getElementById("welimg4" + btnold).style.zIndex = 1;
					progress = 0;
			});
			$("#welimg3" + img).delay(200).show("slide", { direction: "right" }, 300, function(){
					document.getElementById("welimg3"+ img).style.display = "block";
					document.getElementById("welimg3" + img).style.zIndex = 0;
					document.getElementById("welimg3" + btnold).style.display = "none";
					document.getElementById("welimg3" + btnold).style.zIndex = 1;
					progress = 0;
			});
			$("#welimg2" + img).delay(300).show("slide", { direction: "right" }, 300, function(){
					document.getElementById("welimg2"+ img).style.display = "block";
					document.getElementById("welimg2" + img).style.zIndex = 0;
					document.getElementById("welimg2" + btnold).style.display = "none";
					document.getElementById("welimg2" + btnold).style.zIndex = 1;
					progress = 0;
			});
			$("#welimg1" + img).delay(400).show("slide", { direction: "right" }, 300, function(){
					document.getElementById("welimg1"+ img).style.display = "block";
					document.getElementById("welimg1" + img).style.zIndex = 0;
					document.getElementById("welimg1" + btnold).style.display = "none";
					document.getElementById("welimg1" + btnold).style.zIndex = 1;
					progress = 0;
			});
		}
	}
}
function PreloadMenu(){
	var img = new Array();
	function PreloadImg(){
		for (i=0; i<=4; i++){
			img[i] = new Image();
			img[i].src = PreloadImg.arguments[i];
		}
	}
	PreloadImg (
		"../img/btn1over.jpg",
		"../img/btn2over.jpg",
		"../img/btn3over.jpg",
		"../img/btn4over.jpg",
		"../img/btn5over.jpg"
	);
}
function tbEnter (tb, val){
	if (tb.value == val){
		tb.value = "";
		tb.style.color = "#FFF";
	}
}
function tbExit (tb, val){
	if (tb.value == "" || tb.value == " " || tb.value == val){
		tb.value = val;
		tb.style.color = "#666";
	}
}
function picOver (pic){
	var img = new Image();
	img.src = pic.src;
	//Get Scroll X and Y
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	
	//Show image
	var windowSize = getWindowSize();
	var div = document.getElementById("preview");
	
	var offset = $(pic).offset();
	if ((offset.left + pic.width*0.5) > (windowSize.width*0.5)){
		maxWidth = offset.left - 100;
		left = 0;
	}else{
		maxWidth = windowSize.width - offset.left - pic.width - 100;
		left = 1;
	}
	var maxHeight = windowSize.height - 100;
	img = rescaleImage (img, maxWidth, maxHeight);
	div.style.top = (windowSize.height - img.height) / 2 + scrOfY + "px";
	div.innerHTML = '<img src="'+pic.src+'" width="'+img.width+'" height="'+img.height+'" alt="'+pic.alt+'" />';
	div.style.display = "block";
	if (left == 0){
		div.style.left = offset.left - img.width - 50 + "px";
	}else if (left == 1){
		div.style.left = offset.left + pic.width + 50 + "px";
	}
}

function picOut (){
	var div = document.getElementById("preview");
	div.innerHTML = '&nbsp;';
	div.style.display = "none";
}

function rescaleImage (img, maxWidth, maxHeight){
	var windowSize = getWindowSize();
	var width = img.width;
	var height = img.height;
	var ratioW = 0;
	var ratioH = 0;
	var ratio = 0;
	/*Check if the current width is larger than the max*/
	if (width > maxWidth) {
		/*get ratio for scaling image*/
		ratioW = (maxWidth / width);
	}
	/*Check if current height is larger than max*/
	if (height > maxHeight) {
		/*get ratio for scaling image*/
		ratioH = (maxHeight / height);
	}
	/* Set New hieght and width of Image*/
	if (ratioW >= ratioH && ratioH!=0){
		ratio = ratioH;
	}else{
		ratio = ratioW
	}
	if(ratioH >= ratioW && ratioW!=0){
		ratio = ratioW;
	}else{
		ratio = ratioH;
	}
	if (ratio != 0){
		img.width = width * ratio;
		img.height = height * ratio;
	}
	return img;
}

function getWindowSize(){
	var windowSize = {width:0, height:0};
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		windowSize.width = window.innerWidth;
		windowSize.height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowSize.width = document.documentElement.clientWidth;
		windowSize.height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowSize.width = document.body.clientWidth;
		windowSize.height = document.body.clientHeight;
	}
	return windowSize;
}
