$(document).ready(function(){

	// =====================================================================================
	// App wide
	// =====================================================================================
	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  // Rollovers
  $("a.rollover").hover(
    function() {
      curr = $(this).find("img").attr("src");
      overlen = curr.length;
      over = curr.substr(0, overlen-4);
      over = over+'_over.png';
      $(this).find("img").attr({ src: over});
    },
    function() {
      $(this).find("img").attr({ src: curr});
    }
  )
	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  // Rollovers - Preload images
  $("a.rollover").find("img").each(function(i){
    temp = this.src;
    prelen = temp.length;
    pre = temp.substr(0, prelen-4);
    pre = pre+'_over.png';
    preload_image_object = new Image();
    preload_image_object.src = pre;
  });

	$("ul.sf-menu").superfish().find('ul').bgIframe({opacity:false});

	// $('.datePicker input').datepicker({ yearRange: "-100:+0", });


	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Header login boxes
	// $('a#alumniLoginLink').click(function(){
	// 	$("div.headerDialogueWrapper").fadeOut('fast');
	// 	$("div#alumniLogin").fadeIn('fast');
	// 	return false;
	// });
	// $('a#joinMailingListLink').click(function(){
	// 	$("div.headerDialogueWrapper").fadeOut('fast');
	// 	$("div#joinMailingList").fadeIn('fast');
	// 	return false;
	// });
	// $('a.headerDialogueBoxCloseLink').click(function(){
	// 	$("div.headerDialogueWrapper").fadeOut('fast');
	// 	return false;
	// });



	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Tabs
  $(".tabs").tabs();

	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Multicolumn plugin
	$('.multicolumn2').columnize({
		'columns':2,
		'lastNeverTallest': true
	});


	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Homemade accordian behavior for Program views
	$("div.additionalProgramInfoText").hide();
	// $("div.additionalProgramInfoText:first").show();
	$("div#additionalProgramInfoContainer h2").click(function(){
		$("div.additionalProgramInfoText").slideUp('slow');
		if ($(this).hasClass('open')) {
			$(this).removeClass('open');
		} else {
			$("div#additionalProgramInfoContainer h2").removeClass('open');
			$(this).addClass('open');
		}
		$(this).siblings("div.additionalProgramInfoText").slideToggle('slow');
		return false;
	});






	// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
	// Search Field
	$('#searchIcon').click(function() {
		$('#search').submit();
	});

	$('#searchText').focus(function(){
		if($(this).attr('value') == ''|| $(this).attr('value') == 'Search'){	//test to see if the search field value is empty or 'search' on focus, then remove our holding text
			$(this).attr('value', '');
		}
		$(this).css('color', '#000');

	});
	$('#searchText').blur(function(){	//test to see if the value of our search field is empty, then fill with our holding text
		if($(this).attr('value') == ''){
			$(this).attr('value', 'Search');
			$(this).css('color', '#777');
		}
	});

});

/* ========================================================
 Programs section functions
======================================================== */
function ProgramCalendarInsertSessions(){
	var str = "";
	var cell;

	$.each(ProgramCalendarSessions,function(i,el){


		cell = $('<div id="'+ el.calid+'_'+ el.id +'">'+ el.title +'</div>').appendTo('#'+ el.calid);

		if(el.person != undefined)
		{
			str = '<div class="programCalTooltip"><a href="javascript:closeProgramCalendarTooltip('+"'"+ el.calid+'_'+ el.id +"'"+');" title="Close" class="closeLink">X</a>';

				str += '<div class="session_author_when">'+ el.when +'</div>';

				str += '<div class="session_author_basic">';

					if(el.person.bio_photo != '')
						str += '<img src="/uploads/people_images/'+ el.person.bio_photo +'" alt="" />';


					str += '<strong>'+ el.person.first_name +' '+ el.person.last_name + '</strong><br />';

					if(el.person.title != '')
						str += el.person.title +'<br />';

					if(el.person.email != '')
						str += el.person.email +'<br />';

					if(el.person.phone != '')
						str += el.person.phone +'<br />';

					str += '<a href="/people/view/'+ el.person.id +'" title="View Profile" class="biolink">View Profile</a>';

				str += '</div><div class="clear"></div>';

				if(el.person.intro != '')
					str += '<div class="session_author_intro">'+ el.person.intro +'</div>';

			str += '<div class="clear"></div></div>';
			cell.qtip({
				content: str,
				style: {
					border: { width: 6, color: '#bbbbbb' },
					width: 300
				},
				position: {
					corner: { target: 'bottomLeft' }
				},
				show: { solo: true },
				hide: { fixed: true }
			});
		}
	});

}

function closeProgramCalendarTooltip(ttid){
	var api = $('#'+ ttid).qtip("api");
	api.hide();
}






