$(document).ready(function()
{
  /*** navigation hover when submenu ***/
  $("#navigation li ul li a").hover(
    function() { highlightNavigation(this, true, 1); },
    function() { highlightNavigation(this, false, 1); }
  )
  $("#navigation li ul ul li a").hover(
    function() { highlightNavigation(this, true, 2); },
    function() { highlightNavigation(this, false, 2); }
  )
  /*** primary image gallery panel ***/
  try
  {
    $("#primary-image-gallery .scrollable").scrollable({
      next  : ".nextPage",
      prev  : ".prevPage",
      items : "primary-items"
    }).navigator();
    var aElements = 0;
    var divWidth  = 0;
    $("#primary-image-gallery .navi a").each(function(){
      aElements++;
      divWidth = 14 * aElements;
    });
    $("#primary-image-gallery .navi").css("width",divWidth+"px");
  } catch (e) {}
  /*** re-structure H1 for styling ***/
  $("#primaryPanel h1").each(function(){
    $(this).wrapInner("<em></em>");
    var preHl = $(this).html();
    if(preHl.search(/\:.+/) != -1) {
      postHl  = preHl.replace(/<\/em>/g, "</strong></em>");
      postHl  = postHl.replace(/\:/g, ": <strong>");
      $(this).html(postHl);
    }
//    $("#content-right .feed a").each(function(){
//      var preA = $(this).html();
//      if(preA.search(/\:.+/) != -1) {
//        postA  = preA.replace(/\:/g, " ");
//        $(this).html(postA);
//      }
//    })
  })
})
highlightNavigation = function(obj, status, lvl)
{
  if(lvl == 1) { var aTag = $(obj).parent().closest("ul").prev(); }
  else { var aTag = $(obj).parent().parent().parent().closest("ul").prev(); }

  if(status == true)
  {
    aTag.css("background-color","#F28F24");
    aTag.css("color","#FFFFFF");
  } else
  {
    aTag.css("background-color","transparent");
    aTag.css("color","#393939");
  }
}
