$(document).ready(function(){
   $('.showCateg span span').click(function(){
      if ($(this).attr('id') == 'categ_99')
         $('.showCateg span span').each(function(){
            if ($(this).attr('id') != 'categ_99')
               if ($('.'+$(this).attr('id')).css('display')=='none')
                  $(this).click();
         });
      else if ($('.'+$(this).attr('id')).css('display')=='none')
         $(this).css('background-color','#e8dfba');
      else
         $(this).css('background-color','#ffffff');
      $('.'+$(this).attr('id')).toggle();
      resizeFrame();
   });
   $('.showRegion span span').click(function(){
      if ($(this).attr('id') == 'region_99')
         $('.showRegion span span').each(function(){
            if ($(this).attr('id') != 'region_99')
               if ($('.'+$(this).attr('id')).css('display')=='none')
                  $(this).click();
         });
      else if ($('.'+$(this).attr('id')).css('display')=='none')
         $(this).css('background-color','#e8dfba');
      else
         $(this).css('background-color','#ffffff');
      $('.'+$(this).attr('id')).toggle();
      resizeFrame();
   });
   $('.entry').click(function(){
      if ($('#i_am_info_'+$(this).attr('id')).length != 0)
         $('#i_am_info_'+$(this).attr('id')).remove();
      else
      {
         $('.aiDiv').remove();
         var aiDiv = $('<div class="aiDiv" id="i_am_info_'+$(this).attr('id')+
            '"><img src="top.png" alt=""/><div class="aiContent"></div></div>');
         $(aiDiv).children('.aiContent').html($('#info_'+$(this).attr('id')).html());
         $(aiDiv)
            .css('left',$(this).offset().left+$(this).width()/2-100+'px')
            .css('top',$(this).offset().top+$(this).height()+'px')
         ;
         $('body').append($(aiDiv));
      }
   });
   $('.entry').hover(function(){
      $(this).css('color','red');
      $(this).css('cursor','pointer');
   },function(){
      $(this).css('color','black');
   });
   function resizeFrame()
   {
      $('.resizeDiv').css('height',$(window).height()-$('.resizeDiv').offset().top);
      $('#topResizer').width($('.resizeDiv').width());
   }
   $('.resizeDiv').scroll(function(){
      $('#topResizer table').css('right',$(this)[0].scrollLeft);
   });
   $(window).resize(function(){
      resizeFrame();
   });
   $('.hiddenEdit').click(function(){
      window.open("http://cb-project.de/login.php","login","toolbar=0,"+
         "location=0,directories=0,status=0,menubar=0,scrollbars=1,"+
         "copyhistory=0,resizable=1,Width=815,Height=500,screenX=50,"+
         "screenY=50,left=50,top=50");
   });
   $('.printPage').click(function(){
      var printParam = '';
      var temp = '?cats=';
      for (var i = 0; i < $('.showCateg span span').length; i++)
      {
         if ($($($('.showCateg span span')[i])).attr('id') != 'categ_99')
         {
            if ($('.'+$($($('.showCateg span span')[i])).attr('id')).css('display') != 'none')
            {
               if (temp != '?cats=')
                  temp += '+';
               temp += $($($('.showCateg span span')[i])).attr('id').replace(/[^0-9]/g,'');
            }
         }
      }
      printParam += temp;
      temp = '&regs=';
      for (var i = 0; i < $('.showRegion span span').length; i++)
      {
         if ($($($('.showRegion span span')[i])).attr('id') != 'region_99')
         {
            if ($('.'+$($($('.showRegion span span')[i])).attr('id')).css('display') != 'none')
            {
               if (temp != '&regs=')
                  temp += '+';
               temp += $($($('.showRegion span span')[i])).attr('id').replace(/[^0-9]/g,'');
            }
         }
      }
      printParam += temp;
      var newloc = document.location.href;
      newloc = newloc.replace('#','');
      newloc = newloc.replace('index.php','');

      window.open(newloc+'print.php'+printParam, '_blank').focus();
      //document.location.href = newloc+'print.php'+printParam;
   });
   resizeFrame();
});
