$(document).ready(function(){
	$('.list_letters .deactive').click(function(){
		return false;
	});
	$('#prev_next a').addClass('pink_link');
	$('#content .collapseomatic_content  p').filter(function() {
        return $.trim($(this).text()) === ''
    }).remove()

	//--------------------------------------------------------------------------------					   
	// Search Submit (Override if people is checked)
	//--------------------------------------------------------------------------------
	$('#sitewidesearch').submit(function(e){
		if($('#filter_ppl').is(':checked')){
			e.preventDefault();
			var the_location = $(this).attr('action');
			the_location += '/people/?ps='+$('input[name="s"]').val()+'#search_results';
			window.location = the_location;
			//alert(the_location);
		}
	});
	/*Addiitonal search page functions */
	$('#people_search').submit(function(e){
		e.preventDefault();
		var the_location = $(this).attr('action');
		var filter = $('input[name="search_by"]:checked').val();
		var ps = '';
		var specialty = '';
		var prevent_search = false;
		var contact_search = false;
		switch (filter){
			case 'alpha':
				/*Since clicking the letter is what actually causes the page to reload, if they accidently click search, do not refresh*/
				prevent_search = true;
				break;
			case 'name':
				if($('#people_search input[name="first_name"]').val() != ''){
					ps = $('#people_search input[name="first_name"]').val();
					if($('#people_search input[name="last_name"]').val() != ''){
						ps+=' ';
					}
				}
				if($('#people_search input[name="last_name"]').val() != ''){
					ps+= $('#people_search input[name="last_name"]').val();
				}
				break;
			case 'practice_area':
				ps = $('#people_search select[name="practices"] option:selected').attr('title');
				
				
				specialty = $('#people_search select[name="specialties"]').val();
				if(specialty.length != 1){
					ps = ps+'+'+specialty;
				}
				break;
			case 'industry_exp':
				ps = $('#people_search select[name="industries"]').val();
				break;
			case 'contact':
				/*Go to contact page, do not serach*/
				ps = 'none';
				filter = 'admins';
				break;
		}
		//alert(ps);
		/*if(ps.length == 1 && filter == 'practice_area'){
			alert('You must select an area of expertise.');
		}else*/ if(ps.length == 1 && filter == 'industry_exp'){
			alert('You must select an industry item.');
		}else if(prevent_search == false){
			the_location += '/people/?ps='+encodeURIComponent(ps)+'&filter='+filter+'#search_results';
			window.location = the_location;
		}
	});
	$('.btn_browse').click(function(){
		var the_location = $('#people_search').attr('action');
		the_location += '/people/?browse=true#search_results';
		window.location = the_location;
	});
	$('.deacive').click(function(){
		return false;
	});
	
	//--------------------------------------------------------------------------------					   
	// Plus Minus Expandable buttons
	//--------------------------------------------------------------------------------
	/*$('.plusminus').click(function(){
		$(this).toggleClass('active');
		if($(this).siblings('div').is(':visible')){
			$(this).siblings('div').hide();
		}else{
			$(this).siblings('div').show();		
		}
	});*/
	//--------------------------------------------------------------------------------					   
	// Search Page Filter Inactive Overlay div functions
	//--------------------------------------------------------------------------------
	$('#search_page input[type="radio"]').click(function(){
		$('.inactive_overlay').removeClass('active');
		$(this).parent().siblings('.inactive_overlay').addClass('active');
	});
	$('#search_page select[name="practices"]').change(function(){
		$('#search_page select[name="specialties"]').removeAttr('disabled');
		$('#search_page select[name="specialties"]').empty();
		$('#search_page select[name="specialties"]').append(eval($(this).val()+'_list'));
	});
	
	//--------------------------------------------------------------------------------					   
	// Custom 'lightbox'/modular windows (for videos/images)
	//--------------------------------------------------------------------------------
	
	/*Client Testimonials*/
	$('.list_video li a,.video_launcher').click(function(){
		createModularWindow();
		var the_href = $(this).attr('href');
		var the_rel = $(this).attr('rel').split('&');
		var htmlzor = '<embed src="'+the_rel[0]+'" flashvars="flvurl='+the_href+'&skinurl='+the_rel[1]+'" type="application/x-shockwave-flash" width="540" height="304"></embed>';
		$('#modularContent').html(htmlzor);
		$.scrollTo(0);
		return false;
	});
	//--------------------------------------------------------------------------------					   
	// Home page video launcher
	//--------------------------------------------------------------------------------
	if($('#video_launcher_1337').size() != 0){
		var urlText = window.location.href.split("?");
		if($('#video_launcher_1337').attr('title') == urlText[1]){
			createModularWindow();
			var the_href = $('#video_launcher_1337').attr('href');
			var the_rel = $('#video_launcher_1337').attr('rel').split('&');
			var htmlzor = '<embed src="'+the_rel[0]+'" flashvars="flvurl='+the_href+'&skinurl='+the_rel[1]+'" type="application/x-shockwave-flash" width="540" height="304"></embed>';
			$('#modularContent').html(htmlzor);
			$.scrollTo(0);
		}
		return false;
	}
});
function createModularWindow(innerWidth,innerHeight,innerPadding,innerClass){
	//Variables
	innerWidth === undefined ? innerWidth = 540 : innerWidth = innerWidth;
	innerHeight === undefined ? innerHeight = 304 : innerHeight = innerHeight + 'px';
	innerPadding === undefined ? innerPadding = 0 : innerPadding = innerPadding;
	innerClass === undefined ? innerClassAppend = '' : innerClassAppend = 'class="'+innerClass+'"' ;	
	var htmlHeight = $('body').height();
	htmlHeight += 177; //this is added due to the absolute position of the items in the footer
	var htmlWidth = $('body').width();
	
	//Attach overlay (gray area) as well as inner div
	$('body').append('<div id="modularOverlay" style="background:#000000;opacity:.5;filter:alpha(opacity=50); position:absolute; top:0; left:0; width:'+htmlWidth+'px; height:'+htmlHeight+'px;></div">');
	$('body').append('<div id="modularContent" '+innerClassAppend+'style="background:#000000;position:absolute; top:150px; left:50%;width:'+innerWidth+'px; height:'+innerHeight+'; margin-left:-'+((innerWidth+(innerPadding*2))*.5)+'px;"></div>');
	$('body').append('<a id="video_close" style="display:block;height:15px;width:45px;position:absolute;top:122px;left:50%;margin-left:'+((innerWidth/2)-57)+'px;background:#fff;color:#D11241;font-size:12px;padding:6px;line-height:15px;cursor:pointer;">Close X</a>');
	
	//when user clicks on the gray it goes away
	$('#modularOverlay,#video_close').bind('click',function(){
		$('#modularOverlay,#modularContent,#video_close').remove();
	});
	//pressing escape also closes the modular window
	$(document).one('keypress',function(e) { 
		var key = (e.keyCode ? e.keyCode : e.charCode);
		if(key == 27){
			$('#modularOverlay,#modularContent,#video_close').remove();
		}
	});
}
