/* taken from Wikipedia mobile version 4 Sep 2011 */


$(document).ready(function(){
  $("h3.section_heading").click(function() {
    var section_idx = parseInt($(this).get(0).id.replace( /section_(\d+)/, "$1" ));
    wm_toggle_section( section_idx );
  })
 $("a").click(function() {
    var link = $(this).get(0)
    if( link.hash.indexOf("#") == 0 ) {
      wm_reveal_for_hash( link.hash )
    }
  })
  if( document.location.hash.indexOf("#") == 0 ) {
    wm_reveal_for_hash( document.location.hash )
  }
;
});

function wm_reveal_for_hash( hash ) {
 var targetel = $('div.content_block [id]').filter(function(i){ return $(this).attr('id') === hash.substring(1); }).eq(0); 
 if(targetel) {
   var parentdiv = targetel.parents("div.content_block")
   if(parentdiv.length > 0 && ! parentdiv.is(':visible')) {
     var section_idx = parseInt(parentdiv.get(0).id.replace( /content_(\d+)/, "$1" ));
     wm_toggle_section( section_idx )
   }
 }
}

function wm_toggle_section( section_id ) {
  $("h3#section_" + section_id).children("button.show").toggle();
  $("h3#section_" + section_id).children("button.hide").toggle();

  $("div#content_" + section_id).toggle()
  $("div#anchor_" + section_id).toggle()
}


