$(document).ready(function()
{
	var timer;
	
	// Resize Background
	resizeBG();
	$(window).resize(resizeBG).scroll(resizeBG);
	
	var searches = ['SEARCH','SEARCH'];
	$('.search_for').addClass('hint').attr('value', '' + searches[Math.floor(Math.random()*1)]).one('focus', function(){$(this).attr('value', '').removeClass('hint')});
	
	$('.search_again').one("focus", function(){$(this).attr('value','');});
	$('.search_for_programs').one("focus", function(){$(this).attr('value','');});
	$('.search_for_travel').one("focus", function(){$(this).attr('value','');});
	$('.search_for_members').one("focus", function(){$(this).attr('value','');});
	
	// DYAD CREDIT
	$('#dyad_credit').css({ opacity: "0.4" });

	$('#dyad_credit').hover(function(){
		$(this).animate({ backgroundPosition: "0px 0px", width: "155px", opacity: "1" }, 300);
	},function(){ 
		$(this).animate({	backgroundPosition: "-155px 0px", width: "11px", opacity: "0.4" }, 300);}
	);
	
	// BookShop search.
	var amazon = 'SEARCH AMAZON';
	$('#keyword').addClass('hint').attr('value', '' + amazon).one('focus', function(){$(this).attr('value', '').removeClass('hint')});
	
	$('.column-inline:last').css('margin-right', '0px');
	
	//BookShop Navigation
	// $('li.recommended-reading-list').hover(function()
	// { 				
	// 	var thisChild = $(this).children('ul');
	// 	if(timer) { clearTimeout(timer); timer = null }
	// 	timer = setTimeout(function() 
	// 	{	
	// 		thisChild.addClass('curSlide');
	// 		thisChild.slideDown(); 
	// 	}, 300);
	// },function()
	// {
	// 	if(timer) { clearTimeout(timer); timer = null }
	// 	timer = setTimeout(function() 
	// 	{	
	// 		$('ul.curSlide').slideUp(); 
	// 	}, 0);
	// });
	
		
	if ($('.slideshow').length!=0) {				
		$('.slideshow') 
		.after('<div id="image_nav">') 
		.cycle({
		    speed:  'slow', 
		    timeout: 0, 
		    pager:  '#image_nav' 
		});
	};	
	
	$('li.hudson-river-list').hover(function(){ 	
			
		var thisChild = $(this).children('ul');
		if(timer) { clearTimeout(timer); timer = null }
		timer = setTimeout(function() 
		{	
			thisChild.addClass('curSlide');
			thisChild.slideDown(); 
		}, 300);
	},function()
	{
		if(timer) { clearTimeout(timer); timer = null }
		timer = setTimeout(function() 
		{	
			$('ul.curSlide').slideUp(); 
		}, 0);
	});
	
	// Benefits and Levels expanding lists
	$('a.expand').each(function()
	{
		$(this).click(function()
		{					
			if($(this).parent().next().attr('class') == 'collapse expanded')
			{
				$(this).parent().next().slideUp().removeClass('expanded');
			}
			else
			{
				$('.expanded').slideUp().removeClass('expanded');			
				$(this).parent().next('.collapse').slideDown().toggleClass('expanded');		
			}
			return false;			
		});
	});
	
	if($('body#pg_home #slideshow').length != 0)
	{
		/* Whats New at the Institute */
		$('ul#whats-new-ticker').liScroll({travelocity: .03});
		
		/* Add Slideshow */
		$('#slideshow').flash({ src: webroot+"/workspace/swf/homepage-slideshow.swf", width: 633, height: 145, wmode: 'transparent' });
	}	
	
	// Travel Gallery
	if($('body#pg_travel-programs #travel-gallery').length != 0)
	{
		$('#travel-gallery ').flash({ src: webroot+"/workspace/swf/travel-programs.swf", width: 633, height: 437, wmode: 'transparent'});
	}
	
	// ARA09 Gallery
	if($('body#pg_awards-and-prizes #ara09').length != 0)
	{
		$('#ara09 ').flash({ src: webroot+"/workspace/swf/ara09.swf", width: 633, height: 437, wmode: 'transparent'});
	}
	
	//  Holiday Auction
	if($('body#pg_holiday-cocktail-party-and-benefit-auction #holiday_auction_gallery').length != 0)
	{
		$('#holiday_auction_gallery ').flash({ src: webroot+"/workspace/swf/holiday_auction.swf", width: 633, height: 475, wmode: 'transparent'});
	}
	
	
	// Navigation Lines
	if($('#tertiary_nav li').length != 0)
	{		
		$('#tertiary_nav').parent().css({'background': 'url('+webroot+'/workspace/img/dashed-line-for-links.gif) repeat-x 0 top','padding-top': '4px'});		
		$('#tertiary_nav').css({'background': 'url('+webroot+'/workspace/img/dashed-line-for-links.gif) repeat-x 0 bottom'});
	}	
	
	// Enhanced Listing
	$('.listing a').click(function()
	{
		$(this).next().slideToggle("slow");
		$(this).toggleClass('cur');
	});
	
	// Content resize fix.
	if(($('#content').height()-$(document).height()) <= 300){ $('.container').css('height', $(document).height()+300); }
	
	$('#usa area').mouseover(function(){
		var id = $(this).attr('id');
		var ida = ['default','ne','mw','se','sw','w', 'international'];
			
		if (ida.indexOf) {
			var index = ida.indexOf(id);
		}
		else {
			for(var i=0; i<ida.length; i++){
	            if(ida[i]==id){
	                var index = i;
	            }
	        }
		};
				
		$('#map').css('background-position', ' 0px -' + (index * 152) + 'px');
	});
	
	$('#usa area').mouseout(function(){ $('#map').css('background-position', '0px 0px'); });
	
	// Press Kit ~ Embed Flash Player
	$('#press-gallery').flash({ src: webroot+"/workspace/swf/press-gallery.swf", width: 633, height: 475, wmode: 'transparent' });
	
});


function resizeBG(){
	var wh = $(window).height();
	var dh = $(document).height();
	var ph = (wh > dh) ? wh : dh;
	$('.container').css('height', ph);
}