﻿
// utility function - precaches images for quick loading time of initially hidden elements
function preCacheImage(imageUrl) {

	var img = new Image();
	img.src = imageUrl;            
	
	return img;
}

preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_greenDark.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_greenLite.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_greenMedium.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_greenMediumDark.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_greenMediumLite.gif');

preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_boxDownArrow.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_boxDownUp.gif');

preCacheImage('/wp-content/themes/mercedeshuff/images/buttons/btn_homeSearch_on.gif');


preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_areaMapSubNav.gif');
preCacheImage('/wp-content/themes/mercedeshuff/images/backgrounds/bg_areaMapViewLink_hover.gif');





function showPopop(page, width, height) {

	if (width > 0) {
		// nothing
	} else {
		width = 345;
	}
	if (height > 0) {
		// nothing
	} else {
		height = 445;
	}
	
	var left;
	var top;
	left = Math.round((screen.width - width) / 2);
	top = Math.round((screen.height - height) / 2);
	
	var winPopup = window.open(page, 'winPopup', 'width='+ width +',height='+ height +',top='+ top +',left='+ left +',status=0,resizable=0,location=0,scrollbars=0,titlebar=0,toolbar=0');
	winPopup.focus();

}

function showPrintPopop(page, width, height) {
	
	if (width > 0) {
		// nothing
	} else {
		width = 787;
	}
	if (height > 0) {
		// nothing
	} else {
		height = 787;
	}
	
	var left;
	var top;
	left = Math.round((screen.width - width) / 2);
	top = Math.round((screen.height - height) / 2);
	
	var winPrintPopup = window.open(page, 'winPrintPopup', 'width='+ width +',height='+ height +',top='+ top +',left='+ left +',status=0,resizable=0,location=0,scrollbars=1,titlebar=0,toolbar=0');
	winPrintPopup.focus();

}




function showPhotoGalleryItem(num) {
	
	var photoItemId = 'photoGalleryItem_'+ num;
	var photoThumbId = 'photoGalleryThumb_'+ num;
	
	if ($('photoGallery') && $(photoItemId) && $(photoThumbId)) {
	
		$('photoGallery').select('.photoGalleryItem').each(function (item) { item.hide(); });
		$('photoGallery').select('.photoGalleryThumb').each(function (item) { item.removeClassName('on'); });
		
		$(photoItemId).show();
		$(photoThumbId).addClassName('on');
		
	}
	
}



function jumpToArea(sel) {
	
	location.href = sel.options[sel.selectedIndex].value;

}



var curAreaMediaTab = 'mapPhotoGallery';


function changeAreaMediaTab(str) {
	
	if ($(str)) {
		
		if ($(curAreaMediaTab)) {
			$(curAreaMediaTab).hide();
		}
		
		$(str).show();
		
		curAreaMediaTab = str;
		
	}
}

function showAreaMap(id, type) {

	if ($('areaMapDetailImg')) {
		
		$('areaMapDetailImg').src = areaMapImages[id +'_'+ type].src;
		
	}

}


function highlightSubNavItem(id) {

	if ($('subNavItemLink_'+ id)) {
		
		$('subNavItemLink_'+ id).addClassName('highlight');
		
	}

}

function unhighlightSubNavItem(id) {

	if ($('subNavItemLink_'+ id)) {
		
		$('subNavItemLink_'+ id).removeClassName('highlight');
		
	}

}


// usage : writing out link
// <script>linkMail('hostdomain','username');</script>
// usage : link only
// <a href="javascript:popMail('hostdomain','username')">email us</a>
// usage : showing an email address
// <script>showMail('hostdomain','username');</script>

function popMail(host,user) {
	var acct = user +'@'+ host;
	self.location.href = 'mailto:'+ acct;
}

function linkMail(host,user,cls) {
	document.write('<a href="javascript:popMail(\''+ host +'\',\''+ user +'\');"');
	if (cls) {
		document.write(' class="'+ cls +'"');
	}
	document.write('>');
	showMail(host,user);
	document.write('</a>');
}

function showMail(host,user) {
	var acct = user +'@'+ host;
	document.write(acct);
}




// on window load functions
Event.observe(window, 'load', function() {
	
		$$('input[type="text"],textarea').each(function(item) { 
										
										var val = item.getValue();
										if (item.hasClassName(val.replace(/ /g,'-'))) {
											item.addClassName('default');
											item.writeAttribute({ 'defaultval' : val });
										}

										item.observe('focus', function(event) {
																
																var item = event.findElement();
																
																if (item.readAttribute('defaultval') && item.getValue() == item.readAttribute('defaultval')) {
																	item.clear();
																	item.removeClassName('default');
																}
																
															});
															
										item.observe('blur', function(event) {
																
																var item = event.findElement();
																
																if (item.readAttribute('defaultval') && item.getValue() == '') {
																	item.value = item.readAttribute('defaultval');
																	item.addClassName('default');
																}
																
															});

									});
	
	});


