/* Author: 

*/

// nav bar
(function($) {
	/**
	 * Converts a table into a dl list, along with optional functionality
	 *
	 * @option int toggleDurationMs specify the hide/show animate time (0 for no animation)
	 */
	$.fn.listConverter = function(options)
	{
		options = options || {};
		options = $.extend({
			toggleDurationMs: 0,
			closeByDefault: false,
			closeLabel: 'close'
		}, options);
		var $this = this;
		
		// iterate through each object and 
		return $this.each(function() {
			var id = 'list-converter-'+Math.round(Math.random()*100000);
			
			var html = generateHtmlForList($(this), id, options);
			
			$this.replaceWith(html);

			var $id = $('#'+id);
			
			$('a.list-close-button', $id).click(function(e) {
				e.preventDefault();
				$(this).toggleClass('data-open').toggleClass('data-close');
				$(this).parent().next('dd').toggle(options.toggleDurationMs);
				return false;
			});
			if (options.closeByDefault === true) {
				$('dd', $id).hide();
				$('.list-close-button', $id).removeClass('data-open').addClass('data-close');
			} else if (typeof options.closeByDefault === 'object') {
				$('dd', $id).filter(arrayFilter).hide();
				$('.list-close-button', $id).filter(arrayFilter).removeClass('data-open').addClass('data-close');
			} else if (typeof options.closeByDefault === 'string') {
				$('dd', $id).filter(options.closeByDefault).hide();
				$('.list-close-button', $id).filter(options.closeByDefault).removeClass('data-open').addClass('data-close');
			}
		});
	}
	function arrayFilter(i)
	{
		return options.closeByDefault.indexOf(i) > -1;
	}
	
	/**
	 * Generate a data list for the provided table
	 *
	 * @param jQuery $table table selector
	 * @param string id id attribute for list 
	 * @return string
	 */
	function generateHtmlForList($table, id, options)
	{
		var html = '<dl id="'+id+'" class="'+$table.attr('class')+'">';
		$('tr', $table).each(function() {
			html += '<dt>'+$('td:first',this).html()+'<a class="list-close-button data-open" href="">'+options.closeLabel+'</a></dt><dd>'+$('td:last',this).html()+'</dd>';
		});
		html += '</dl>';
		return html;
	}
})(jQuery);


$(function() {
    var $oe_menu        = $('#oe_menu');
    var $oe_menu_items    = $oe_menu.children('li');
    var $oe_overlay        = $('#oe_overlay');
    var menuTimeout;

    $oe_menu_items.bind('mouseenter',function(){
        var $this = $(this);
        $this.addClass('slided selected');
        $this.children('div').css('z-index','9999').stop(true,true).slideDown(200,function(){
            $oe_menu_items.not('.slided').children('div').hide();
            $this.removeClass('slided');
        });
        clearTimeout(menuTimeout);
    }).bind('mouseleave',function(){
        var $this = $(this);
        $this.removeClass('selected').children('div').css('z-index','1');
    });

    $oe_menu.bind('mouseenter',function(){
        var $this = $(this);
        $oe_overlay.stop(true,true).fadeTo(200, 0.6);
        $this.addClass('hovered');
    }).bind('mouseleave',function(){
        var $this = $(this);
        menuTimeout = setTimeout(function() {
            $this.removeClass('hovered');
            $oe_overlay.stop(true,true).fadeTo(200, 0).css('display', 'none');
            $oe_menu_items.children('div').hide();
        }, 200);
    })

});

if($('#og-page, #mdw-page, #ew-page, #dmu-page, #ddu-page').length > 0) {
            $('a:contains(Biography)')
                        .attr('href', '')
                        // activate the click toggle functionality.
                        .click(function() {
                                    $(this).parent().next().toggle(); 
                                    return false;
                        })
                        // hide the bio by default.
                        .parent().next().hide();
}




	<!-- add class to links -->
	(function() {
		$("a:has(img)").addClass("noBorder");	
		if(!$("a[href$='pdf']").hasClass("button"))
		{
			$("a[href$='pdf']").addClass("pdf")
			$("a[href$='pdf']").attr({ target: "_blank" });	
		} else {
			$("a[href$='pdf']").attr({ target: "_blank" });	
		}			
		$("a[href$='doc']").attr({ target: "_blank" });			
		$("a[href^='http']").attr('target','_blank');		
	})();
	
	

$(function() {
	$('table.general-info-table').listConverter({
		closeByDefault: ':gt(0)',
		closeLabel: 'close'
	});
	
	$('table.speakers-info-table').listConverter({
		closeByDefault: true,
		closeLabel: '<br />Biography'
	});
});
