window.addEvent("domready",function(){

var isIE6 = /MSIE 6/i.test(navigator.userAgent);

   if($('nav')) {

      var overEvent = false;
      var subActive = false;
      var subActive2 = false;

      $('nav').getElements('li').each(function(listitem){
         
         if(listitem.className.match(/active/))
         {
            listitem.getElements('a')[0].style.backgroundColor = "#0069aa";
            listitem.getElements('.link-wrapper')[0].style.backgroundColor = "#0069aa";
         }
         
         if(listitem.className.match(/active/) && listitem.className.match(/l2/)){
            subActive = listitem.parentNode.parentNode;
            listitem.parentNode.parentNode.style.overflow = "visible";
         }
         if(listitem.className.match(/active/) && listitem.className.match(/l3/)){
            subActive2 = listitem.parentNode.parentNode;
            listitem.parentNode.parentNode.style.overflow = "visible";
         }

         listitem.addEvent('mouseenter',function(){

            listitem.style.overflow = "visible";
            if(subActive && subActive != listitem && subActive != listitem.parentNode.parentNode && subActive != listitem.parentNode.parentNode.parentNode.parentNode)
            {
               subActive.style.overflow = "hidden";
            }
            if(subActive2 && ((subActive2 != listitem.parentNode.parentNode && subActive != listitem && subActive != listitem.parentNode.parentNode) || (subActive2 != listitem && subActive == listitem.parentNode.parentNode)))
            {
               subActive2.style.overflow = "hidden";
            }

            if(isIE6)

               listitem.style.height = (listitem.offsetHeight + 5) + "px";

            if(!listitem.className.match(/active/))

               listitem.style.backgroundColor = "#0069aa";

            overEvent = true;

         });

         listitem.addEvent('mouseleave',function(){

            if(overEvent){

               listitem.style.overflow = "hidden";
            if(subActive)
            {
               subActive.style.overflow = "visible";
               if(subActive2)
               {
                  subActive2.style.overflow = "visible";
               }
            }

               if(isIE6)

                  listitem.style.height = (listitem.offsetHeight - 5) + "px";

               if(!listitem.className.match(/active/))

                  listitem.style.backgroundColor = "#00506b";

            }

         });

      });

   }

   

   if($('top-tabs')) {

      $('top-tabs').getElements('.tabs').each(function(tabs){

         tabs.addEvent('click',function(e){

            e.stop();

            $('top-tabs').getElements('.tabs').each(function(tabs2){

               tabs2.className = "tabs";

               $(tabs2.id + "-content").style.display = "none";

            });

            tabs.className = "tabs tab-selected";

            $(tabs.id + "-content").style.display = "block";

            resizeRightPatterns();

         });

      });

   }

   

   if($('news-tabs')) {

      $('news-tabs').getElements('.tabs').each(function(tabs){

         tabs.addEvent('click',function(e){

            e.stop();

            $('news-tabs').getElements('.tabs').each(function(tabs2){

               tabs2.className = "tabs";

               $(tabs2.id + "-content").style.display = "none";

            });

            tabs.className = "tabs tab-selected";

            $(tabs.id + "-content").style.display = "block";

            resizeRightPatterns();

         });

      });

   }

   

   $$('.news-item').each(function(news){

      news.addEvent('mouseenter',function(){

         news.style.height = "auto";

         resizeRightPatterns();

      });

      news.addEvent('mouseleave',function(){

         news.style.height = "20px";

         resizeRightPatterns();

      });

   });


   resizeLeftPattern();
   resizeRightPatterns();

   window.addEvent('resize', resizeRightPatterns);
   window.addEvent('resize', resizeLeftPattern);
   
});



function resizeRightPatterns()

{

   $('extend1').setStyle('height', $('top-tabs-content').offsetHeight - 16 + "px");

   $('extend2').setStyle('height', $('news-tabs-content').offsetHeight - 16 + "px");

   if (($(document.body).offsetWidth - 1024) < 1)

   {

      $$('.patternExtendRight').each(function(extend)

      {

         extend.setStyle('width', '100%');

      });

   }

   else

   {

      $$('.patternExtendRight').each(function(extend)

      {

         extend.setStyle('width', (($(document.body).offsetWidth - 1024) /  2) + 275 + 'px');

      });

   }

}

function resizeLeftPattern()
{

   $('extend3').setStyle('height', $('content-container').offsetHeight + 268 + "px");
   $('extend3').setStyle('margin-top', 0 - 268 + "px");
   if (($(document.body).offsetWidth - 1024) < 1)
   {
      $('extend3').setStyle('width', 80 + 'px');
      $('extend3').setStyle('margin-left', 0 + 'px');
   }
   else
   {
      var side = (($(document.body).offsetWidth - 1024) /  2) + 80;
      $('extend3').setStyle('width', side + 'px');
      $('extend3').setStyle('margin-left', 0 - side + 80 + 'px');

      $('extendMenuLeft').setStyle('width', side + 'px');
      $('extendMenuLeft').setStyle('margin-left', 0 - side + 'px');
   }
}