// JavaScript Document


/*
* runs once the page is loaded
*/
$(document).ready(
     function(){

          //initialize hidden sitemap
          initImgSwap();
          
          initIntGalleryHover();

		initContactForm();
     }
 );
 
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */


/**
 *   initialize hidden sitemap
 */ 
function initImgSwap() {

	$(".imgswap").hover( onImgHover, offImgHover );


}

function onImgHover(){
   
   var imgsrc = $(this).attr('src');
   $(this).attr('src', imgsrc.replace('inactive','active') ) ;
   
}

function offImgHover(){
   //alert('off');
   
   var imgsrc = $(this).attr('src');
   $(this).attr('src', imgsrc.replace('active','inactive') ) ;
   
}

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

/**
 * initializes the gallery hover action.
 * @return none 
 */
function initIntGalleryHover(){

	$(".int-gallery .fmgimg").hover( onGalleryImgHover, offGalleryImgHover );

} 

function onGalleryImgHover(){
   
   var ximg = $(this).find('img');
   var imgsrc = ximg.attr('src');
   ximg.attr('src', '/images/int-gallery-overlay.png' ) ;
   
}

function offGalleryImgHover(){

   var ximg = $(this).find('img');
   var imgsrc = ximg.attr('src');
   ximg.attr('src', '/images/blank.png' ) ;
   
}


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

function initContactForm() {

	$('select#building_homesite').change( toggleContactField ); 
	
}

function toggleContactField(){
   var val = $('select#building_homesite').val();
   
   if( val == 'Yes' ){
   
   		$('#building_homesite_location-label').show();
   		$('#building_homesite_location-element').show();
   
   		$('#building_counties-label').hide();
   		$('#building_counties-element').hide();
   	
   } else {
   
   		$('#building_homesite_location-label').hide();
   		$('#building_homesite_location-element').hide();
   
   		$('#building_counties-label').show();
   		$('#building_counties-element').show();
   }
}

function toggleContactFields( xselect ){

     //alert(' xxx ');
     
     var sindex = xselect.selectedIndex;
     var value = xselect[sindex].value;

     //building_homesite_location - yes
     //building_counties - no
     
     if( value == 'Yes' ){
          
          $('.stdfieldloc').show();
          $('.stdfieldbcnt').hide();
          //$("label").hide();
     }else{
     
          $('.stdfieldloc').hide();
          $('.stdfieldbcnt').show();
     }
     

}




