$(document).ready(function() {

var contactFloatHeight = 625;
if(navigator.appName.indexOf("Microsoft") != -1){contactFloatHeight = 665}

$('.launchFloatBio').hover(function(){$('img', this).fadeTo(0,.6);},function(){$('img', this).fadeTo(0,1);}).colorbox({iframe:true,width:655,height:460,scrollbars:false});

$('.launchFloat').hover(function(){$('img', this).fadeTo(0,.6);},function(){$('img', this).fadeTo(0,1);}).colorbox({iframe:true,width:405,height:contactFloatHeight,scrollbars:false});

$('.launchFloatWide').hover(function(){$('img', this).fadeTo(0,.6);},function(){$('img', this).fadeTo(0,1);}).colorbox({iframe:true,width:405,height:contactFloatHeight,scrollbars:false});

$('#launchFloat').colorbox({iframe:true,width:645,height:contactFloatHeight,scrollbars:false});

$('a.launchFloatJob').live('mouseenter',function(){
    //$('a.launchFloatJob').click(function(){return false});
    $(this).colorbox({iframe:true,width:645,height:contactFloatHeight});
}); 

/* Set up the accordion, if there's a div on the page with the id "accordion" */

    if(document.getElementById('accordion')) {
        $("#accordion").tabs("#accordion div.accContent", {tabs: 'div.accHeader', effect: 'slide'});
        $('#accordion').find('.accHeader:eq(4)').trigger('click');
    }

/* Swap button image on ouseover */

	$('.customButton' ).each(function(index) {
	
		var orig = $('img', $(this)).attr("src");
		
		$($('.customButton').get(index)).bind('mouseover',
		    function(event) {
			    var over = orig.replace(/.gif$/ig, "-over.gif");
			    $('img', this).attr({'src': over});
	        });
	    
	    $($('.customButton').get(index)).bind('mouseout',
		    function(event) {
		        $('img', this).attr({'src': orig});
	        });
	});	
	
/* Initialize pull-down menus */
	
	jQuery(function(){
        jQuery('ul.sf-menu').superfish({autoArrows: false}); 
    });

/* Initialize folding FAQ answers */

    if(document.getElementById('faqs')){

        /* Assign the numbers in the FAQ links as ids to the FAQ content divs */
        $('#faqs .accHeader a').each(function(){
            var faqID = ($(this).attr('href')).substr(1,2);
            $(this).parent().next().attr('id',faqID);
        });
        
        /* Hide the FAQ answers, but if there's a value of 'id' in the query string, keep that FAQ item open */
        var keepOpen = getQueryVariable('id');
        $('#faqs .accContent').each(function(){
            if($(this).attr('id') != keepOpen){
                $(this).hide().data('open',false);
            } else {
                $(this).data('open',true);
            }
        });

        /* When a FAQ header is clicked, show that FAQ and hide the others, unless it's already open, in which case close it */
        $('#faqs .accHeader a').click(function(){
            var clickedFAQ = ($(this).attr('href')).substr(1,2);
            if($('#'+clickedFAQ).data('open')){
                $('#'+clickedFAQ).slideUp('fast').data('open',false);
            } else {
                $('#faqs .accContent').slideUp('fast').data('open',false);
                $('#'+clickedFAQ).slideDown('slow').data('open',true);
            }
            return false;
        });
    }

});

/* This function returns a value from the query string */
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}
