$(document).ready(function(){


//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://www.bodoinlaw.com/images/close_popup.png" width="30px" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=90)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});



$('.profile ul li').children('ul:first').slideDown('fast'); // display first section of attorney profile
	var arrPageSizes = getPageSizes();

	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	});	
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});
/*	// display attorneys
	$("#display_attorneys").click(function () {
		$("#main").css({"display":"none"});
		$("#firm").css({"display":"none"});
		$("#practice_areas_container").css({"display":"none"});
		$("#attorneys_content").children('div').hide(); /* hide all previously viewed content */
/*    $('.list ul li').each(function () {
			$(this).removeClass("selected"); /* unselect all previously clicked list items */
/*    });
		$("#attorneys_container").css({"display":"block"});
		$("#attorneys_content").children('div:first').fadeIn(500);
	});
	$("#display_practice_areas").click(function () {
		$("#main").css({"display":"none"});
		$("#firm").css({"display":"none"});
		$("#attorneys_container").css({"display":"none"});
		$("#practice_areas_content .practice_areas").children('div').hide(); /* hide all previously viewed content */
/*    $('.list ul li').each(function () {
			$(this).removeClass("selected"); /* unselect all previously clicked list items */
/*    });
		$("#practice_areas_container").css({"display":"block"});
		$("#practice_areas_content .practice_areas").children('div:first').fadeIn(500);
	});
	// end
*/
	// list actions
/*	$(".list ul li").hover(
		function(){
			$(this).animate({paddingLeft: '+=10'}, 200);
		},
		function(){
			$(this).animate({paddingLeft: '-=10'}, 200);
		}
	);
/*	$('.list ul li').click(function () {
		// highlight selected item
    $('.list ul li').each(function () {
 	    $(this).removeClass("selected"); 
    });
		$(this).addClass("selected");
		// end highlight
	});
	
	
	
	
	// start attorney list actions
	$("#attorneys_container .list ul li").click(function () {
		$("#attorneys_content").children("div").hide();
		$("#a" + $(this).attr("rel")).show();
	  $("#a" + $(this).attr("rel") + " .profile ul li ul:first").slideDown('fast');
  });
	// end

	// start practice areas list actions
	$("#practice_areas_container .list ul li").click(function () {
		$("#practice_areas_content .practice_areas").children("div").hide();
		$("#p" + $(this).attr("rel")).show();
  });
	// end
*/
		
		
		$('.profile li').click(function () {
 
        /* FIRST SECTION */
 
        //slideup or hide all the Submenu
        $('.profile li').children('ul').slideUp('fast'); 
             
        //remove all the "Over" class, so that the arrow reset to default
        $('.profile li > a').each(function () {
            if ($(this).attr('rel')!='') {
                $(this).removeClass($(this).attr('rel') + '_selected'); 
            }
        });
             
        /* SECOND SECTION */   
             
        //show the selected submenu
        $(this).children('ul').slideDown('fast');
             
        //add "Over" class, so that the arrow pointing down
        $(this).children('a').addClass($(this).children('li a').attr('rel') + '_selected');         
 
        return false;
    });




	// start of motto actions
	$("#l1").delay(300).animate({opacity: 'show' }, "slow");
	$("#l2").delay(1200).animate({opacity: 'show' }, "slow");
	$("#l3").delay(2100).animate({opacity: 'show' }, "slow");
	// end
//	displayquotes();
//	rotatequotes(); // run function on launch

	// start of menu actions
	$("#menu #menu_panel li a").hover(function() {
		$(this).parent().find("ul#submenu").slideDown('slow').show();
		$(this).parent().hover(function() {}, function(){  
			$(this).parent().find("ul#submenu").animate({opacity: 'hide' }, "fast");
    });  
  });
/*	$("#menu #menu_panel ul li ul li").click(function () {
		$(this).parent().hide();
		$("#main").css({"display":"none"});
		$("#firm").css({"display":"none"});
		$("#attorneys_container").css({"display":"none"});
		$("#attorneys_content").children('div').hide(); /* hide all previously viewed content */
/*		$("#practice_areas_container").css({"display":"none"});
		$("#practice_areas_content .practice_areas").children('div').hide(); /* hide all previously viewed content */
/*    $('.list ul li').each(function () {
			$(this).removeClass("selected"); /* unselect all previously clicked list items */
/*    });

    if ($(this).attr("rel").substring(0,1) == "a") {
			var qqqnumber = $(this).attr("rel").substring(1,2);
			$("#attorneys_container").css({"display":"block"});
			$("#attorneys_content > div:nth-child(7)").fadeIn(500);
	    $('.profile ul li').children('ul:first').slideDown('fast');
		}
    if ($(this).attr("rel").substring(0,1) == "p") {
			var qqqnumber = $(this).attr("rel").substring(1,2);
			$("#practice_areas_container").css({"display":"block"});
			$("#practice_areas_content .practice_areas > div:nth-child(7)").fadeIn(500);
		}






/*		$("#a" + $(this).attr("rel")).show();
	  $("#a" + $(this).attr("rel") + " .profile ul li ul:first").slideDown('fast');*/
//  });

	// end


/* this is the start of the contact form */


/* this is the end of the contact form section */
});



displayquotes = function() {
	$("#quotes #content #q1").fadeIn(1000).delay(5000).fadeOut(1000);
	$("#quotes #content #q2").delay(7000).fadeIn(1000).delay(5000).fadeOut(1000);
	$("#quotes #content #q3").delay(14000).fadeIn(1000).delay(5000).fadeOut(1000);
};
rotatequotes = function(){
   play = setInterval(function(){ // set timer
     displayquotes(); //Trigger the paging and slider function
	}, 21000); // set timer speed in milliseconds
};





function getPageSizes() {
   var xScroll, yScroll;
   var windowWidth, windowHeight;
   var maxWidth, maxHeight;
   
   if (window.innerHeight && window.scrollMaxY) {
      xScroll = window.innerWidth + window.scrollMaxX;
      yScroll = window.innerHeight + window.scrollMaxY;
   } else if (document.body.scrollHeight > document.body.offsetHeight) {
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
   } else {
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
   }

   if (self.innerHeight) {
      if(document.documentElement.clientWidth){
         windowWidth = document.documentElement.clientWidth;
      } else {
         windowWidth = self.innerWidth;
      }

      windowHeight = self.innerHeight;
   } else if (document.documentElement && document.documentElement.clientHeight) {
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
   } else if (document.body) {
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
   }

   maxWidth = Math.max(windowWidth,xScroll);
   maxHeight = Math.max(windowHeight,yScroll);
   
   arrayPageSize = new Array(maxWidth,maxHeight);
   return arrayPageSize;
};

$(window).resize(function() {
        var arrPageSizes = getPageSizes();
});
