// JavaScript Document

$(document).ready(function(){
	
    
	/* var homeImgNum = $('#imgRefresh div').length;
	var randHomeNum = Math.floor(Math.random()*homeImgNum);
	$('#imgRefresh div:eq('+ randHomeNum + ')').css({'display': 'block'}); */
	
	$('input#search-text').focus(function() {
		if(this.value == "Search" || this.value == "search") {
			this.value = "";
		}
	});
	
	$('input#search-text').blur(function() {
		if(this.value == "") {
			this.value = "Search";
		}
	});
	
	// GLOBAL NAV //
	
	$('#globalNav li').children('a.active').css({'color': '#BE5817'});
	$('#globalNav').find('li').each(function() {
	navWidth = $(this).width();
			childWidth = $(this).children('ul').width();
			if(navWidth > childWidth) {
				$(this).find('ul li a').css({'width': (navWidth-12)});
				}
	});
	$('#globalNav li').hover(function() {
		$(this).children('ul').show();
		// need the below bc jquery.hover() hijacks CSS :hover
		$(this).children('a.level_one').css({'color': '#BE5817'});
	}, function () {
		$(this).children('ul').hide();
		// need the below bc jquery.hover() hijacks CSS :hover
		$(this).children('a.level_one').css({'color': '#000000'});
		$(this).children('a.active').css({'color': '#BE5817'});

	});
	
	// Click anywhere in a feature block and go to the url of the link inside it //
	
	if ($.fn.colorbox) { } else {
		$('#featureBlocks .feature').bind('click.hrefExpand', function() {
		thisLink = $(this).find('a').attr('href');
		if (thisLink != undefined) {
			if($(this).find('a').attr('target') == "_blank") {
					window.open(thisLink);
					return false;
			}
			else {
				window.location = thisLink;
			}
		}
	});
	}
	
	
		$('.contentRight .feature').click(function() {
		thisLink = $(this).find('a').attr('href');
		if (thisLink != undefined) {
		window.location = thisLink;
		}
	});
	
	// VIDEOS PAGE //
	
	$('.videoListing #featureBlocks .feature').mouseover(function() {
		$(this).find(".featureCapt a").addClass("over");
	}).mouseout(function() {$(this).find(".featureCapt a").removeClass("over");
	}); 
	
	$('.contentRight .video .feature').mouseover(function() {
	alert('test');
		$(this).find(".featureCapt a").addClass("over");
	}).mouseout(function() {$(this).find(".featureCapt a").removeClass("over");
	}); 
	
	
   	if ($.fn.colorbox) {
   $(".videolink").colorbox({iframe:true, innerWidth:480, innerHeight:272});
    } else { } 
	
	// HISTORY PAGE //
	
	$('.historyListing #featureBlocks .feature').mouseover(function() {
		$('#featureBlocks .feature').unbind('click.hrefExpand');
		$(this).find(".featureCapt h3.dark").css({'color':'#FFFFFF'});
		$(this).find(".featureCapt p").show();
	}).mouseout(function() {
	if(  $(this).find(".featureCont img").is(":visible")){
  			$(this).find(".featureCapt p").hide();
  			$(this).find(".featureCapt h3.dark").css({'color':'#000000'});
		}
		else{
  			// do nothing
		}
	}); 

	$('.historyListing #featureBlocks .feature').click(function() {
		$(this).find(".featureCont img").toggle();	
		return false;
	}); 
	

  
  	// SUB NAV //
	
	if ($.fn.hoverIntent) {
	
	
	function showDropdown() { $(this).children('.columns').show(); }
	function hideDropdown() { $(this).children('.columns').hide(); }
	
	
	$("#subNav li").hoverIntent({
				over: showDropdown, 
				timeout: 250, 
				out: hideDropdown
			});
			
		
			
	// event categories dropdown //
	
	function showeDropdown() { $(this).children('ul').show(); }
	function hideeDropdown() { $(this).children('ul').hide(); }
	
	
	$("#eventCategories li").hoverIntent({
				over: showeDropdown, 
				timeout: 250, 
				out: hideeDropdown
			});
			
	// event table //
	}
			
	$(".event_calendar td").live("click", function () {
	// Test to see if there's an anchor before allowing toggle //
	if ($(this).children('a').length > 0){
    $(this).toggleClass("eventSelected");
	}
	});
	
  	// event table AJAX //
  	
  	$(".calendarNav #prevArrow").live("click", function(){
  	var prevCal = $(this).attr('href');
     $('#eventCal').load(prevCal);
     return false;
	});
	
	$(".calendarNav #nextArrow").live("click", function(){
	var nextCal = $(this).attr('href');
    $('#eventCal').load(nextCal);
     return false;
	});

	if ($.fn.cycle) {
	
	$.fn.cycle.defaults.timeout = 7000;
	$('#imgRefresh').cycle({
		fx: 'fade'
	});
	
	
	$.fn.cycle.defaults.timeout = 7000;
	$('.teaserSlideShow').cycle({
		fx: 'fade'
	}); 
	
	} else {}
	


	$('.eventsList h4 a.eventDetailLink').click(function() {
		var eventguid = $(this).attr('name');
		var eventExpander = $(this).find('#eventExpander').text();
		if(eventExpander == '+') {
			$(this).find('#eventExpander').text('-');
		}
		else {
			$(this).find('#eventExpander').text('+');
		}
		$('.eventsList .EventDescription').each(function() {
			if($(this).attr('id') == eventguid) {
				$(this).slideToggle('fast');
			}
		});
											   
	});
	
  
});
