//Summit Live Events namespace
var SLE = window.SLE || {}; 
SLE.Speakers = {};

$(document).ready(function() {
	var SpeakerBios = new ExpandCollapse($('.speaker h4'), '.speaker-bio');
	var speakerContainer = $('#speaker-last-name'),
	speakerList = $('#speakers-alpha'),
	speakers = $('.speaker')
	removeFilter = $('#clear-filter');
	
	removeFilter.button({
		icons : {
			primary : 'ui-icon-close'
		}
	}).hide();
	
	speakerContainer.autocomplete({
		minLength: 2,
		source: SLE.Speakers.nameList,
		select: function(event, ui){
			speakers.hide();
			$("." + ui.item.value).show();
			speakerList.addClass('filtered');
			removeFilter.show();
		}
	});
	
	removeFilter.click(function(e){
		removeFilter.hide();
		speakers.show();
		speakerContainer.val('');
		speakerList.removeClass('filtered');
	});
	
	// new window for external links
	$("body").delegate("a[href^='http']:not([href*='" + window.location.host + "'])", "click", function(){
            $(this).attr("target", "_blank");
      });
	
	$('.tabs').tabs();
	
	 
	$('#menu-main-nav').superfish();
    var rows = $('tbody tr'),
    tips = $('.tip');
    
    // adds zebra striping for tables
	$('.tablesorter tbody tr:odd').addClass('odd');
	
	// hides the session description and speaker name
	$('.tip').hide();
	
	// makes the session name clickable and sets style
	// toggles the description on click
	rows.each(function(i){
	    if($(this).has(tips).length > 0) {
		    $(this).find('.sessionName').css({
		            'color' : '#00313f',
		            'cursor' : 'pointer',
		            'text-decoration' : 'underline'
		        }).click(function(){
		        $(this).next('.tip').toggle("350");
		    });
	    }
	});
	
	// light box script
	$('.nyroModal').nyroModal();
	
	// controls the filtering for the event categories
	// appends instructions and a reset link to show all
	var legend = $('#key');
	var instructions = $('<strong/>', {
		text : 'Filter by: '
	}).prependTo(legend);
	var reset = $('<a/>', {
		text : 'Show All'
		}).css({
			'color' : '#3A82B6',
			'cursor' : 'pointer',
			'text-decoration' : 'underline'
		}).appendTo(legend).click(function(){
			$(rows).show();
	});
	legend.find('span').css({
		'color' : '#3A82B6',
		'cursor' : 'pointer',
		'text-decoration' : 'underline'
		}).click(function(e){
			$(rows).show();
			var clicked = $(this).attr('class');
			$(rows).not('.' + clicked).hide();
	});
	$('#collapse-all').click(function(){
		tips.hide();
	});
	$('#show-all').click(function(){
		tips.show();
	});
}); 
