//Site-specific JavaScript code goes in the SLE (Summit Live Events) namespace
//Summit Live Events namespace
var SLE = window.SLE || {
	Speakers : {},
	UI : {}
};

SLE.UI.config = function(){
	$('#menu-main-nav').superfish();
	$('#accordion').accordion({
    	autoHeight: false,
		navigation: true
    });
    $('.tabs').tabs();
    	// light box script
    	
    if(!$.browser.msie) {
		$('.nyroModal').nyroModal();
	} else if(parseInt($.browser.version, 10) != 6) {
		$('.nyroModal').nyroModal();
	} 
	
	// new window for external links with MYS
	$("body").delegate("a[href^='http']", "click", function(){
            var path = $(this).attr('href'),
            
            // IMPORTANT!!!
            // change this regex to specify which domains DO NOT open in a new window
            sameWindow = /americasclaimsevent\.com|ace12\.mapyourshow\.com/gi; 
            
            if(path.match(sameWindow)){
                  return;     
            }
            else{
                  $(this).attr("target", "_blank");
            }
    });
}

SLE.UI.agenda = function(linkColor){
	var rows = $('tbody tr'),
    	tips = $('.tip');
	
	// hides the session description and speaker name
	tips.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' : linkColor,
			'cursor' : 'pointer',
			'text-decoration' : 'underline'
		}).click(function(){
		        $(this).next('.tip').toggle("350");
		    });
	    }
	});
	// 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 : 'Clear Filter'
		}).css({
			'color' : linkColor,
			'cursor' : 'pointer',
			'text-decoration' : 'underline'
		}).appendTo(legend).click(function(){
			$(rows).show();
	});
	legend.find('span')
		.css({
			'color' : linkColor,
			'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();
	});	
}

SLE.Speakers.filter = function(){
	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');
	});
}

$(function(){
	var SpeakerBios = new ExpandCollapse($('.speaker h4'), '.speaker-bio');
	SLE.UI.config();
	SLE.UI.agenda('#1849AA');
	SLE.Speakers.filter();
});
