// Prevent conflicts with other JavaScpirt frameworks
var J = jQuery.noConflict();

function ToggleNotice( cls_id ) {
   J('.'+cls_id).toggle();
}

function setBg (idx) {
   var bg_src = TMPL_IMG_PATH + '/side_menu_bckg' +
      ( typeof(idx) != 'undefined' ? ('_sel' + idx) : '' ) + '.gif';
   J('.rightMenu').css('background','url(' + bg_src + ') no-repeat');
}

function SetEvents() {
   var bg_none;

   if (typeof(CURRENT_ITEM_CONTEXT) == 'undefined') {
      if (J('.rightMenu a:first').attr('id') == 'active_menu') {
         bg_none = 1;
      } else if (J('.rightMenu a:last').attr('id') == 'active_menu') {
         bg_none = 2;
      } else {
         // undefined, default
      }
   } else {
      bg_none = CURRENT_ITEM_CONTEXT;
   }

   if (bg_none) {
      setBg(bg_none)
   }

   J('.rightMenu a:first').mouseover(function(){setBg(1)}).mouseout(function(){setBg(bg_none)});
   J('.rightMenu a:last').mouseover(function(){setBg(2)}).mouseout(function(){setBg(bg_none)}).addClass('last');
}

function HighlightServices() {
   var p1href;

   if ( J('.leftMenu div > a#active_menu').length ) {
      p1href = J('.leftMenu div > a#active_menu').parent().parent().children('a#active_menu.mainlevel').attr('href');
   }

   // Highlight the current services menu item
   J('.middleHeaderMenuBar li a').each(
      function(i,obj){
         if ((J(obj).attr('href') == p1href)||(J(obj).attr('id') == 'active_menu')) {
            J(obj).css('background','url('+TMPL_IMG_PATH+'/arrow_sel.gif) no-repeat 7px 33px').parent().addClass('current');
         }
      }
   );
}

function SetHomepageLinks() {
   J('div.mainContent div.itemWrapper').each(
      function(i,obj) {
         J(obj).find('div.itemBody img').wrap('<p><a href="'+J(obj).find('div.itemTitle a').attr('href')+'"></a></p>');
      }
   );
}

function InjectHomepageFlash () {
   if (typeof(IS_HOME) != 'undefined' && IS_HOME) {
      var flashVars = { wmode: 'transparent', menu: 'false', quality: 'high' };
      swfobject.embedSWF(TMPL_FLASH_PATH+'/spin.swf','homeFlashPlaceholder','520','228','8',false,flashVars,flashVars);
   }
}

J(document).ready(
   function(){
      SetHomepageLinks();
      InjectHomepageFlash();
      SetEvents();
      HighlightServices();
   }
);
