$(function(){

	var isPracticeAreas = ($("#content-wrap.practice-areas").length !== 0)? true : false;
	
	if(!isPracticeAreas){
	  
    var midHeight = $('#mid').innerHeight();	
  	$('#right').height(midHeight+10 + 'px');
  	$('#left').height(midHeight+9 + 'px');
    if($.browser.msie){
      $('#left').height(midHeight+8 + 'px');
      $('#divider.left').css({
        display: 'none'
      });
      $('#content-wrap').css({
        backgroundColor: '#036'
      });
    }

	}
	
	//turn #bigimage images into divs with background Images
	$("#bigimage img").each(function(){
		var src = $(this).attr('src');
		$(this).replaceWith($("<div />").css({backgroundImage : 'url('+src+')'}).addClass('bottom-round'));
	});
	
	//do the slideshow
	if($("#bigimage div.bottom-round").length > 1)
	$('#bigimage').cycle({
		timeout: 4000,
		speed: 2000,
		autostop: 1
	});	
	
  
 //init the custom scrollbar
//  if(!($.browser.msie && $.browser.version=="6.0")){//detect & exclude ie6
//    
//    
//    if(!isPracticeAreas){ // not doing it on practice-areas anymore
//      $('#scroll-content')
//      .jScrollPane({
//          // dragMaxHeight:10,
//        showArrows:true,
//        scrollbarContainer: '#scrollbar',
//        animateTo: true,
//        animateInterval: 10
//      });
//    }
//  }
// 
// 
// 
// 
// if(!($.browser.msie && $.browser.version=="6.0")){//detect & exclude ie6
//    
//    
//    if(!isPracticeAreas){ // not doing it on practice-areas anymore
//      $('#scroll-content1')
//      .jScrollPane({
//          // dragMaxHeight:10,
//        showArrows:true,
//        scrollbarContainer: '#scrollbar',
//        animateTo: true,
//        animateInterval: 10
//      });
//    }
//  }
//  
// 
// 
//  
	//bullet next to name/h3
	$('#mid h2.name, #mid h3:not(.pagetitle)').prepend("<span class='square'></span>");
  
  // practice areas page scroll-navigation
  if(isPracticeAreas){
    
   $('#mid div.first h2').attr('id', 'PATOP');
   
   var $newA = $('<a class="active" rel="#PATOP">Overview</a></li>').attr('href', '#PATOP');
   var $newLi = $('<li />').append($newA);   
   $newLi.prependTo('ul.practice-areas');
   
   
   $("ul.practice-areas li a").click(function(){
     $(this).parent().parent().find('li a').removeClass('active');
     $(this).addClass('active');
     $('#mid').find('div.active').removeClass('active');
     $($(this).attr('href')).parent().addClass('active');
     return false;
   });
   
   $('#mid').addClass('paJS fp-image')
   .find('.wrap.first')
     .addClass('active')
  }// end practice areas stuff


	//Disclaimer functionality
	

	
	$("#disclaimer-link").click(function(){
		$("#shade").remove();
		var url = $(this).attr('href');
		$("<div id='shade'><div id='disclaimer-box'><div class='top'><strong>Hewit Wolensky LLP</strong></div><div class='content'><center>loading...</center></div></div></div>").prependTo($('body'));
		$.get(url, { 'textonly' : 'true'}, function(data, textStatus){
			$("#disclaimer-box div.content").html(data);
		});
		return false;
	});
	$("#shade, #shade div").live('click', function(){ $("#shade").remove(); });
	$("html").keydown(function(key){
		if(key.which == 27){ 
			$("#shade").remove();
		}
	});
	
	
	//Map functionality
	if($('body.page-id-44').length){//this is for the contact page only
		
		$('#mapBox').data('content', $('#mapBox').html()).html('');
		
		$('#content p:first').append('<br /><a href="#" id="maplink">View Map</a> <a style="display:none" href="#" id="hidemaplink">Hide Map</a>');
		$('#maplink').click(function(){
			$('#hidemaplink').css('display', 'block');
			$(this).css('display', 'none');
			$('#mapBox').fadeIn('fast').html($('#mapBox').data('content'));
			return false;
		});
		$('#hidemaplink').click(function(){
				$('#maplink').css('display', 'block');
				$(this).css('display', 'none');
				$('#mapBox').fadeOut('fast').html('');
				return false;
		});
	}//end map functionality
	
	
});
