// JavaScript Document

function openMaps(strUrl, strParams) {
	window.open(strUrl, 'mywin', strParams);
}

function setMapPosition(strLat, strLong, strMag) {
	$("#googlemap").show();
	map.checkResize()
	map.setCenter(new GLatLng(strLat,strLong), strMag);
}

//************************************************************
  
function adjustHeights(arrDivs) {
	maxHeight = 0;
	var i = 0;
	for (i=0; i<arrDivs.length; i++) { 
		if ($('#' + arrDivs[i]).height() > maxHeight) {
			maxHeight = $('#' + arrDivs[i]).height();
		}
	}
	for (i=0; i<arrDivs.length; i++) { 
		if ($('#' + arrDivs[i]).height() < maxHeight) {
			$('#' + arrDivs[i]).height(maxHeight);
		}
	}
}

//************************************************************

function swapImage(strReplace, strImage) {
	$("#" + strReplace).attr("src", strImage);
}

//************************************************************

function changePortfolioThumb(strReplace, strImage, strDescription) {
	
	$("#" + strReplace).html('');
	$("#" + strReplace).css('display', 'none');
	$("#" + strReplace).html('<img src="/images/site/' + strImage + '" alt="' + strDescription + '" title="' + strDescription + '" /><p style="text-align: left; padding-top: 10px;">' + strDescription + '</p>');
	$("#" + strReplace).fadeIn("slow");
	
}

//************************************************************

function replaceImage(strReplace, strImage, strDescription) {
	$("#" + strReplace).html('');
	$("#" + strReplace).css('display', 'none');
	$("#" + strReplace).html('<img src="/images/site/' + strImage + '" alt="' + strDescription + '" title="' + strDescription + '" /><p style="text-align: right; padding-top: 10px;">' + strDescription + '</p>');
	$("#" + strReplace).fadeIn("slow");
	
	$("#showProjectContent").fadeIn("slow");
	
	var arrDivColumns = new Array('microLeftMenu', 'microLeftContent', 'microLeftRight'); 
	adjustHeights(arrDivColumns);
}

//************************************************************

function doJqueryAjax(strShow, strHide, strQueryData, strMethod, intReplace)  {
	
	var intDebug = 0;
	var strDataType = 'json';
	var strData = '';
	var strQuery = '';
	
	if (strMethod == 'POST') {
		strData = $("#" + strForm).serialize(); 
		strQuery = "?" + strQueryData;
	} 
	else {
		strData = strQueryData;
	}
	
	var strURL = "/php/object-up-ajax.php" + strQuery;
	
	var strDebug =  "<strong>doJqueryAjaxM</strong>" + 
					" <br />strShow = " + strShow + 
					" <br />strHide = " + strHide + 
					"<br /> strQueryData = " + strQueryData + 
					"<br /> strMethod = " + strMethod + 
					"<br />";
	
	
	//$("#debug").html(strDebug);
	
	$.ajax({  
		type: 		strMethod,   
		url: 		strURL,  
		data: 		strData,
		cache: 		false,  
		dataType: 	'json',
		
		beforeSend: function() { 
		
			if (strHide.length > 0) {
				$("#" + strHide).hide(); //hide
			} 
			$("#waiting").show("slow"); //hide
			$("#" + strShow).hide(); //hide
			$("#" + strShow).html("");
			
			if (intDebug > 0) {
				$("#ajaxurl").html("<p>" + strURL + " (" + strQueryData + ")</p>");
			}
			//alert(strURL);
		}, //show loading just when link is clicked
		
		success: function(objReturn, textStatus) {  
			//alert('returned ok');
			switch (strDataType) {
				case 'json': // JSON
					 
					if (objReturn.result == 'success') {
						strDebug += "objReturn.result = success" + " - " + objReturn.op + "<br />";
						
						switch (objReturn.op) {
							
							case 'replace': // replace table
							
								var strLinks = '' + objReturn.links;
								if (strLinks.length > 0) {
									$("#imageLinks").html(objReturn.links);
								}
							
								$("#" + strShow).html(objReturn.html); //show the html inside
								$("#" + strShow).fadeIn('slow');
								
								strDebug += "<strong>Action:</strong> <br />HTML = " + strShow + "<br />";
											
							break;
						}
					}
				break;
			}
			
			$("#waiting").hide("slow"); //hide
			//$("#questionHolder").show("slow"); //animation
			
			var arrDivColumns = new Array('microLeftMenu', 'microLeftContent', 'microLeftRight'); 
			adjustHeights(arrDivColumns);
			
			if (intDebug > 0) {
				$("#ajax").html(html2entity(objReturn.html)); //animation
				$("#debug").html(strDebug);
				$("#debugSuccess").html(objReturn.debug);
			}
		},
		
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus + " " + errorThrown);
		}
		
	}); 
}
