var $BannerSpeed = 500;
var $BannerIntervalSec = 12; //seconds

$(document).ready(function(){
   try{
      $.nyroModalSettings({minWidth:600,minHeight:400});
   }catch(ex){}
   //$('table>tr:odd,tbody>tr:odd').addClass('odd');
   $('table').each( function(){ $(this).find('>tbody>tr:odd').addClass('odd'); } );
   //$('table>tr:even,tbody>tr:even').addClass('even');
   $('table').each( function(){ $(this).find('>tbody>tr:even').addClass('even'); } );
   $('tr>th:first-child,tr>td:first-child').addClass('first-child');
   $('tr>th:last-child,tr>td:last-child').addClass('last-child');
   $('img').removeAttr('hspace').removeAttr('vspace');
   $('img[align=left]').addClass('img-align-left');
   $('img[align=right]').addClass('img-align-right');
   /*++ Search Events +++++++++++++++++++++++++++++++++++++*/
   $('#txt-search').keypress( function(e){
      if( e.which==13 )
      {
         $('#btn-search').click();
         return false;
      }
   });
   $('#btn-search').click( function(){
      var _keyword = $('#txt-search').val();
      if( _keyword.length!='' )
      {
         window.document.location.replace( 'advancedsearch.aspx?keywordsearch=' + _keyword );
      }else{
         $('#txt-search').focus();
         alert("Please enter a search term");
      }
      return false;
   });
   /*++ FontSize Events +++++++++++++++++++++++++++++++++++*/
	$('#size-more').click(  $App.$Handler_SizeMore );
	$('#size-minus').click( $App.$Handler_SizeMinus );
	
	$('.left-branding, .right-branding').equalizeCols();
	
	$('#main-banner').each(function(){
	   var oControl = $(this);
	   var $BannerItems = new Array();
	   var $BannerPos = 0;
	   oControl.data('status','run');
	   var $handler_effect = function(isLeft){
	      if( oControl.data('status')=='run')
	      {
	         oControl.data('status','animating');
	         var vBanner = $BannerItems[$BannerPos];
	         if(isLeft==true){
	            $BannerPos=$BannerPos<=0?$BannerItems.length-1:$BannerPos-1;
	         }else{
	            $BannerPos=$BannerPos>=$BannerItems.length-1?0:$BannerPos+1;
	         }
	         var vBannerNew = $BannerItems[$BannerPos];
	         if(isLeft==true){
	            $('ul.banner-items>li', oControl).css({'z-index':10,display:'none'});
	            var _next = $(vBannerNew).next();
	            if(_next.length<=0){
	               _next= $('ul.banner-items>li:first-child', oControl);
	            }
	            _next.css({'z-index':10,display:'block'});
	            $(vBannerNew).css({left:600,'display':'block','z-index':11})
	               .animate({left:0},$BannerSpeed,function(){
	                  oControl.data('status','run');
                  });
	         }else{
	            $(vBannerNew).css({left:0,'display':'block','z-index':10});
	            $(vBanner).css('z-index','11')
	               .animate({left:600},$BannerSpeed,function(){
	                  $(this).css('display','none');
   	               oControl.data('status','run');
                  });
            }
	      }
      };
	   $('ul.banner-items>li:last-child', oControl).addClass('last-child');
	   $('ul.banner-items>li', oControl).each(function(){
			$BannerItems.push(this);
			if( $(this).hasClass('last-child') )
			{
				oControl.data('timer', setInterval($handler_effect,$BannerIntervalSec*1000) );
			}
		});
		$('a.btn-left', oControl).click(function(){
		   if( oControl.data('status')=='run'){
		      clearInterval(oControl.data('timer'));
		      $handler_effect(true);
		      oControl.data('timer', setInterval($handler_effect,$BannerIntervalSec*1000) );
		   }
		});
		$('a.btn-right', oControl).click(function(){
		   if( oControl.data('status')=='run'){
		      clearInterval(oControl.data('timer'));
		      $handler_effect();
		      oControl.data('timer', setInterval($handler_effect,$BannerIntervalSec*1000) );
         }
		});
	});						
});
function $print_popup( url )
{
   var width=664, height=600;
   var left = (window.screen.availWidth-width)/2;
   var top = (window.screen.availHeight-height)/2;
   var params="location=no,menubar=no,status=no,toolbar=no,resizable=no,scrollbars=yes,width="+width+",height="+height+",left="+left+",top="+top;
   var popup=window.open(url,"Print",params);
   return false;
}
function $email_popup( url )
{
   var width=700, height=600;
   var left = (window.screen.availWidth-width)/2;
   var top = (window.screen.availHeight-height)/2;
   var params="location=no,menubar=yes,status=no,toolbar=no,resizable=yes,scrollbars=yes,width="+width+",height="+height+",left="+left+",top="+top;
   var popup=window.open(url,"Print",params);
   return false;
}

/* =jQuery Plugins*/
(function($){
	/* =plug-in : equal-heights */
	$.fn.equalizeCols = function(){
		var height = 0,
			 reset = $.browser.msie ? "1%" : "auto";
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
				var h = $(this).outerHeight(true);
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
	};
})(jQuery);

var $App = new function()
{
	var config = { size: 90, size_min: 90, size_max: 110 };
	this.$Handler_SizeMore = function()
	{
		if(config.size==100)
		{
		  config.size+=10;
		  $('head').append('<link id="css-large" rel="stylesheet" type="text/css" href="common/css/manatt-large.css"/>');		  
		}
		if(config.size==90)
		{		  
			  /*$('#css-small').remove();*/
			  $('link[href$=manatt-small.css]').remove();
			 config.size+=10;
			 if ($.browser.msie){
				  $('head').append('<link id="css-normal" rel="stylesheet" type="text/css" href="common/css/manatt-normal.css"/>');
			 }
		}
		return false;
	};
	
	this.$Handler_SizeMinus = function()
	{		
		if(config.size==100)
		{	
			config.size-=10;
			/*$('#css-large').remove();*/
			$('link[href$=manatt-large.css]').remove();
			$('head').append('<link id="css-small" rel="stylesheet" type="text/css" href="common/css/manatt-small.css"/>');
		}
		if(config.size==110)
		{			
			$('link[href$=manatt-large.css]').remove();
			config.size-=10;
			if ($.browser.msie){
				  $('head').append('<link id="css-normal" rel="stylesheet" type="text/css" href="common/css/manatt-normal.css"/>');
			 }
		}
		return false;
	};
};



function endKeyEvent(key_event,key,target){
   try{
      if(key_event==key){
         var _target=document.getElementById(target);
         _target.click();
         return false;
      }
   }catch(ex){
   }
}

function validate_Attorney()
{
var xName=document.getElementById("ctl00_ContentPlaceHolder1_Name");
var xLaw=document.getElementById("ctl00_ContentPlaceHolder1_LawSchools");
var xPractice=document.getElementById("ctl00_ContentPlaceHolder1_PracArea");
var xOffice=document.getElementById("ctl00_ContentPlaceHolder1_OfficeList");
 
 
if ((xName.value=="" || xName.value==null ) && (xLaw.value=="" || xLaw.value==null || xLaw.value=="0") && (xPractice.value=="" || xPractice.value==null || xPractice.value=="0") && (xOffice.value=="" || xOffice.value==null || xOffice.value=="0") )
 {  alert("Please enter a search term");return (false);}
else { return (true); }
}
