$(document).ready(function() {

$('a').focus(function() {
  this.blur();
});

$('ul.navbar').accordion({
      header: "span.hd",
      fillSpace: false,
      autoHeight: false,
      event: "click",
      active: false,
      selectedClass: 'tmpContentSelected',
      navigation: true,
      navigationFilter: function(){
      	return(
	      decodeURIComponent(this.href).toLowerCase() ==
  	    decodeURIComponent(location.href.toLowerCase())
        );
        }
}); // jquery.ui.accordion()

$('div.controls').show(); // controls are by default not shown in CSS

// highlight any links referring to current page:
var thisPage = document.URL.match(/[^/]*$/);
if(thisPage == ""){
		$('a[href$=index.php]').css('color', 'red');
	} else {
		$('a[href$=' + thisPage + ']').css('color', 'red');
  }

// the infoPopup is positioned "fixed" which works vertically but needs this JQ hack to keep it positioned horizontally. 
// following script must not be used on index page
if( $('body').attr('id') != 'index' ){
	$('#infoPopup').css('left', $('#imageTop').offset().left);
}; // on load
$(window).resize(function(){															 // (on resize)
	$('body[id!=index] #infoPopup').css('left', $('#imageTop').offset().left);
});

animateTime = 250; // global variable which can set all animation speeds
var lastDiv; // persistent value required for showHide() to test for existence
var infoPopupCloser = '<div class="infoPopupCloser">click anywhere on this to close</div>';
$('#infoPopup').append(infoPopupCloser);

var showHide = function(){
	$(this).parents().find('.more').show();
	var thisDiv = $(this).attr('href');
  var forPopup = $(thisDiv).html();

	if($('#background div#infoPopup:visible') != false){
		if(thisDiv == lastDiv){                   // clicked on same link twice; close
      thisDiv = 'closed';
    	$('#infoPopup').fadeOut(animateTime);
    } else {                                  // clicked on new link; close old and open new
			$('#infoPopup').fadeOut(animateTime);
			setTimeout(function(){$('#infoPopupBox').html($(thisDiv).html())}, (animateTime + 50));
			setTimeout(function(){$('#infoPopup').fadeIn(animateTime)}, (animateTime + 100));
			$(this).parent().find('.more').hide();
    } // if/else end; if different 
	 } // 1st if()
	 else {                                  // popup not open, open new popup
			setTimeout(function(){$('#infoPopupBox').html(($($(this).attr('href')).html()))}, 1);
			setTimeout(function(){$('#infoPopup').fadeIn(animateTime)}, (1 + 10));
		$(this).parent().find('.more').hide();
	 }
	lastDiv = thisDiv;
	return false;
}; // showHide

$('#select a').click(showHide);

$('#infoPopup').click(function(){
	$(this).parents().find('.more').show();
  thisDiv = 'closed';
	$('#infoPopup').fadeOut(animateTime);
});

// following is for contactus.php
$('#inputform #message').blur(function(){
	if ($('#email').val() == ''){
  	alert('Just a reminder:\n  It\'s not necessary, but if you don\'t leave an email address, we can\'t reply to your message.');
    }
});

// following is for index. php
var FadeInOutTime = 1000;
var animateTime = 375;

function captionUpFeature(){
      	$(this).find('.target').animate({height : '100%'}, animateTime).end()
        .find('img.more').hide().end()
        .find('.reveal').animate({opacity : '1'}, animateTime)
        .end();
			}

function captionDownFeature(){
      	$(this).find('.target').animate({height : '85px'}, animateTime)
        .end()
        .find('img[src$=stardingbat.png].more').show()
        .end()
        .find('.reveal').animate({opacity : '0'}, animateTime)
        .end();
			}

function captionUpBottom(){
      	$(this).find('.target').animate({height : '22.5%'}, animateTime)
        .end()
        .find('img.more').hide()
        .end()
        .find('.reveal').animate({opacity : '1'}, animateTime)
        .end();
			}

function captionDownBottom(){
      	$(this).find('.target').animate({height : '28px'}, animateTime)
        .end()
        .find('img.more').show()
        .end()
        .find('.reveal').animate({opacity : '0'}, animateTime)
        .end();
			}

var hiHomeFeature = {   // settings for hoverintent    
    sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)    
    interval: 50, // number = milliseconds for onMouseOver polling interval    
    over: captionUpFeature, // function = onMouseOver callback (REQUIRED)    
    timeout: 250, // number = milliseconds delay before onMouseOut    
    out: captionDownFeature // function = onMouseOut callback (REQUIRED)
};

var hiHomeBottom = {   // settings for hoverintent    
    sensitivity: 4, // number = sensitivity threshold (must be 1 or higher)    
    interval: 50, // number = milliseconds for onMouseOver polling interval    
    over: captionUpBottom, // function = onMouseOver callback (REQUIRED)    
    timeout: 250, // number = milliseconds delay before onMouseOut    
    out: captionDownBottom // function = onMouseOut callback (REQUIRED)
};

$('#feature > .featured').hoverIntent( hiHomeFeature );
$('#homeBottom').hoverIntent( hiHomeBottom );


}); // ready
