$(document).ready(function() {
  $('#nav li:first').addClass('first');
  $('#footerNav li:first').addClass('first');
  
  $(".monkForm legend:first").hide();

	var requiredStar = ' <span class="star">*</span>';
  $('div.required').find('label').append(requiredStar);
  $('form.monkForm label[for=text_18491]').append(requiredStar);
  $('form.monkForm span.star').css('color','red');

  
  $("#subNav").accordion({
    autoHeight: false,
    navigation: true,
    //navigationFilter: function(){
    //  var currentPage = location.href.toLowerCase();
    //  if 
    //  console.log(currentPage);
    //},
    changestart: mychanges,
    event: "click"
  });

  function mychanges(event, ui) {
    console.log(ui.newContent);
    if (!ui.newContent.length) {
      window.location = ui.newContent.context.href;
    }
    else if(ui.newContent.context.href !== "#"){
      window.location = ui.newContent.context.href;
    }
  }
  
  // have to do something special for the first item in the list
  if (!$("#subNav a:first li").length) {
    $("#subNav a:first").click(function(){
      window.location = this.href;
    });
  }

  
/*  thickbox fix
    uses code found at http://snipplr.com/view/5896/get-browser-viewport-width-and-height/
*/
var viewportheight;

if (typeof window.innerWidth != 'undefined'){
  viewportheight = window.innerHeight;
}
else if (typeof document.documentElement != 'undefined'
        && typeof document.documentElement.clientWidth != 'undefined'
        && document.documentElement.clientWidth != 0){
  viewportheight = document.documentElement.clientHeight;
}
else{
  viewportheight = document.getElementsByTagName('body')[0].clientHeight;
}

/*  thickbox fix
    uses code found at http://snipplr.com/view/5896/get-browser-viewport-width-and-height/
*/

if ((viewportheight < 600) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
   
   $('a.thickbox').unbind('click');
   $('a.thickbox').click(function() {
     window.open(this.href + '&style=http://morningwalkmedia.com/_css/login.css', '_self');
     return false;
   });
 }




});


