$(document).ready(function() {
	$("#info").click(function() {
		$("#sendEmail").load("sendemail.php", {action: "showForm"}, function() {
			$("#sendEmail").fadeIn();
		});
 	});
});


function updPortImg(imgName, parentImgDiv, url, fade){
	var launchDiv = "", nextDiv = '<div id="nextDiv" class="finger" style="display:none; position:absolute; top:200px; left:510px;"><img src="img/btnNext.png" onmouseover="$(this).attr(\'src\', \'img/btnNext_rollover.png\');" onmouseout="$(this).attr(\'src\', \'img/btnNext.png\');" ></div>', prevDiv = '<div id="prevDiv" class="finger" style="display:none; position:absolute; top:200px; left:-55px;"><img src="img/btnPrevious.png" onmouseover="$(this).attr(\'src\', \'img/btnPrevious_rollover.png\');" onmouseout="$(this).attr(\'src\', \'img/btnPrevious.png\');" ></div>', next, prev, nextPrev;
	fade = (typeof fade == "undefined") ? true : fade;
	
	imgSize = $.get("imgSize.php", {img: imgName}, function(data){
		tmpImg = data.split("x");
		$("#photoCont").height(tmpImg[0]);
		$("#photoCont").width(tmpImg[1]);
		if (url != ""){
			launchDiv = '<div class="finger" style="position:absolute; top:13px; left:15px; width:70; height:23;"><a href="' + url + '" target="_blank"><img src="img/btnLaunchSite.png" /></a></div>';
		}
		
		nextPrev = $.get("next.php", {imgName: imgName}, function(data){
			nextPrev = data.split(":");
			prev = nextPrev[0];
			next = nextPrev[1];
			
			if (prev != "none"){
				prevDiv = '<div id="prevDiv" class="finger" style="position:absolute; top:200px; left:-55px;" onClick="updPortImg(\'' + prev + '\', $(this), \'\', 0);"><img src="img/btnPrevious.png" onmouseover="$(this).attr(\'src\', \'img/btnPrevious_rollover.png\');" onmouseout="$(this).attr(\'src\', \'img/btnPrevious.png\');" ></div>'
			}
			if (next != "none"){
				nextDiv = '<div id="nextDiv" class="finger" style="position:absolute; top:200px; left:510px;" onClick="updPortImg(\'' + next + '\', $(this), \'\', 0);"><img src="img/btnNext.png" onmouseover="$(this).attr(\'src\', \'img/btnNext_rollover.png\');" onmouseout="$(this).attr(\'src\', \'img/btnNext.png\');" ></div>'
			}
			
			if (fade) {
				parentImgDiv.html("<img style='display:none' src='img/arrow.gif' />");
				jQuery("img", parentImgDiv).css("filter","alpha(opacity=60)");
				jQuery("img", parentImgDiv).css("-moz-opacity","0.6");
				jQuery("img", parentImgDiv).css("-khtml-opacity","0.6");
				jQuery("img", parentImgDiv).fadeIn("slow", function() {
					$("#photoCont").fadeOut("slow", function(){
						$("#photoCont").html(launchDiv + prevDiv + nextDiv + '<div id="closeButt" class="finger" style="position:absolute; top:10px; right:15px; width:73; height:23; display:none;" onClick="$(\'#photoCont\').fadeOut();"><img src="img/btnClose.png" /></div><img id="curImg" src="' + imgName + '" />');
						$("#photoCont").fadeIn("slow", function() {
							$("#closeButt").toggle();
							jQuery("img", parentImgDiv).fadeOut("slow");
						});
					});
				});

			}
			else {
				$("#curImg").attr("src", imgName);
				if (prev == "none"){
					$("#prevDiv").fadeOut("slow");
				}
				else{
					$("#prevDiv").fadeIn("slow");
				}
				if (next == "none"){
					$("#nextDiv").fadeOut("slow");
				}
				else{
					$("#nextDiv").fadeIn("slow");
				}
				var pDiv = document.getElementById("prevDiv");
				var nDiv = document.getElementById("nextDiv");
				if (pDiv != null){
					pDiv.onclick = new Function("updPortImg('" + prev + "', $(this), '', 0)");
				}
				if (nDiv != null){
					nDiv.onclick = new Function("updPortImg('" + next + "', $(this), '', 0)");				
				}
			}
		});
	});
	
}	
	
function sendMsg(){
	name = $("#nameEmail").val();
	msg = $("#messageEmail").val();
	address = $("#addressEmail").val();
	code = $("#codeEmail").val();
	custNumEntry = $("#custNumEntry").val();
	$("#sendEmail").fadeOut();
	$("#sendEmail").load("sendemail.php", {action: "submitForm", nameEmail: name, addressEmail: address, msgEmail: msg, custNumEntry: custNumEntry, codeEmail: code}, function() {$("#sendEmail").fadeIn();});
}

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}
