$(document).ready(function() {

	if($('ul.sf_postListing').length){
		$('ul.sf_postListing li:nth-child(1)').addClass('first');
	}
	
	if($('.sf_singleNews').length){ 
		//hides certain commands if on a single news item page
	}else{
		$(document).pngFix();
		$('#contactform').validate();
		$('.accordion').accordion({ active: false });	
	}

	$('#calloutboxleft img').attr('width', '648').attr('height', '261');

	if($('body').attr('id') == 'home'){
		$('#calloutboxleft').cycle({
			timeout: '7000' //7 second delay between logo switches
		});
	}
		
	$('.accordion > a').prepend('&bull; ');
	
	$('#related li:first').addClass('first');
	
	var origValue = [];
	$('input').each ( function (currentIndex)
	{
       origValue.push ( $(this).val () );
       $(this).focus ( function ()
       {
               var defaultText = $(this).val();
               if ( $(this).val () == origValue [ currentIndex ] )
               {
                       $(this).val('');
               }

               $(this).blur(function()
               {
                       var userInput = $(this).val();
                       if (userInput == '')
                       {
                               $(this).val(defaultText);
                       }
               });
       	 });
	});
	
	
	// email accordion
	$('input#ctl00_RightColTemplate1_ctl00_emailAddress').click(
		function(){	$('#email-extra').show() 
		});
	// email dropdown
	$("#email").hover(function(){
    
        $(this).addClass("hover");
        $('#email-drop').css("display", "block");
    
    }, function(){
    
        $(this).removeClass("hover");
        $('#email-drop').css("display", "none");
    
    });
    
    $('#email-drop').hover(function() {
		$(this).css("display", "block");
        $('#email').addClass('hover'); 
        return false;
     }, function(){
		 $(this).css("display", "none");
         $('#email').removeClass('hover'); 
     });



  	$('#nav li > ul').hover(function(){
  		$(this).parent().addClass('on');
  	}, function(){
  		$(this).parent().removeClass('on');
  	});
  	
  	$('#nav li ul li:last-child').addClass('last');

	$('#tabcontact, #tabsearch').click(function(){
		//a few variables and setup
		theclass = $('#toptabs').attr("class");
		curwidth = ($(this).width() + 2);
		contactstatus = $('#topcontact').attr('class');
		searchstatus = $('#topsearch').attr('class');
		
		if($(this).attr('id') == 'tabcontact'){
			openheight = 0;
			dropclass='down';
		}else if($(this).attr('id') == 'tabsearch'){
			openheight = -150;
			dropclass='halfdown';
		}
		
		if(theclass == "up"){
			$('#topbuttons').addClass('down');
			$(this).css("width", curwidth).removeClass('off').addClass('on');
			$('#toptabs').removeClass("up").addClass("down");
			$('#toptabs').animate({
    			marginTop: openheight
  			}, 1000, function(){
  				$('body').addClass(dropclass);
 			});
  			$(this).html('Close');
  			$('#topcontact').css('display', 'none').removeClass('on').addClass('off'); //hides contact block & changes class
			$('#topsearch').css('display', 'none').removeClass('on').addClass('off'); //hides search block & changes class
			if($('#tabcontact').attr('class') == 'on'){ // contact was clicked, show it!
				$('#topcontact').css('display', 'block').removeClass('off').addClass('on'); //shows contact block	
			}else if($('#tabsearch').attr('class') == 'on'){ // search was clicked, show it!
				$('#topsearch').css('display', 'block').removeClass('off').addClass('on'); //shows search block			
			}
  			return false;
  		}else if(theclass == "down" && $(this).attr('class') == 'on'){
  			currentTab = $(this);
  			$('#toptabs').removeClass("down").addClass("up");
			$('#toptabs').animate({
    			marginTop: "-300px"
  			}, 1000, function(){
				$('#topbuttons').removeClass('down');
				$(currentTab).removeClass('on').addClass('off');
  				$('#tabcontact').removeClass('on').addClass('off').html($('#tabcontact').attr('title'));
  				$('#tabsearch').removeClass('on').addClass('off').html($('#tabsearch').attr('title'));
  				$('body').removeClass();
  			});
  			return false;
  		}else if(theclass == "down" && $(this).attr('class') == 'off'){
			//switches the tabs
			if(searchstatus == 'off'){ //if search isn't showing, show it!
				$('#topcontact').fadeOut('fast', function(){ //hides contact block & changes class
					$('#topsearch').fadeIn('fast').removeClass('off').addClass('on'); //shows search block	
				}).removeClass('on').addClass('off');
				
				$('#tabsearch').removeClass('off').addClass('on'); //sets tab search to 'on'
				$(this).css("width", curwidth).html('Close');			 
  				$('#tabcontact').removeClass('on').addClass('off').html($('#tabcontact').attr('title'));
  				$('#toptabs').animate({marginTop: "-150px"}, 1000, function(){
  					$('body').removeClass("down").addClass("halfdown");
  				}); //moves the search tab to half the height
  				return false;
  			}else if(contactstatus == 'off'){ //if contact isn't showing, show it!
				$('#topsearch').fadeOut('fast', function(){ //hides search block & changes class
					$('#topcontact').fadeIn('fast').removeClass('off').addClass('on'); //shows contact block	
				}).removeClass('on').addClass('off');

				$('#tabcontact').removeClass('off').addClass('on'); //sets tab contact to 'on'
				$(this).css("width", curwidth).html('Close');			 
  				$('#tabsearch').removeClass('on').addClass('off').html($('#tabsearch').attr('title'));
  				$('#toptabs').animate({marginTop: "0"}, 1000, function(){
   					$('body').removeClass("halfdown").addClass("down");
  				}); //moves the contact tab to the full height
  				return false;
  			}	
  		}
  	});

	//dropdowns
   $("#nav > li > ul").fadeOut("fast");
   $("#nav li").hover(
      function(){ $(this).find("ul:first").fadeIn("fast"); }, 
      function(){ $(this).find("ul:first").fadeOut("fast"); } 
   );
   // if (document.all) {
   //    $("#nav li").hoverClass ("sfHover");
   // };


	$.fn.hoverClass = function(c) {
   	return this.each(function(){
      	$(this).hover( 
         	function() { $(this).addClass(c);  },
         	function() { $(this).removeClass(c); }
      		);	
   		});
	};

		
});




