var IE = document.all?true:false
timeout = "";
activePic = 0;
$(document).ready(
   function()
   {
      if ($('.pic_links').children().length > 1)
      {
         window.setTimeout("autoToggle()", 5000);
      }
      $('.artistEntry').each(
         function() 
         { 
            var tmpId  = this.id + "";
            var params = tmpId.split("_");
            $(this).hover(
               function() 
               {
                  showArtistProductions(params[1], '', params[0]); 
               },
               function() 
               { 
                  hideArtistProductions(this.id); 
               }
            );
         }
      );
      $('.stayOpen').each(function () { $(this).hover(function() { showArtistProductions(this.id,"subbox"); }, function() { hideArtistProductions(this.id,"subbox"); });});
      $('a').focus(function() { $(this).blur(); });
      $('.hasDropdownMenu').hover(
         function()
         { 
            menuMouseOver(this);
         },
         function()
         {
            menuMouseOut(this,"parent");
         }
      );
      $('.isDropDownMenu').hover(
         function()
         {
            menuMouseOver(this, "child");
         },
         function()
         {
            menuMouseOut(this);
         }
      );
      function menuMouseOver(thisElement, type)
      {
         if (type != "child")
            $('.'+$(thisElement).attr('id')).css('display','block');
         else
            $(thisElement).show();
         if ($(thisElement).attr('id') == 'dropdownMenuFive')
         {
            $('.menuSpacerFive').css('background-image','none');
            $('.menuSpacerFiveActiveRight').css('background-color','#ffffcc');
            $('.menuSpacerFiveActiveRight').css('background-image','none');
         }
         if ($(thisElement).attr('id') == 'dropdownMenuFour')
         {
            $('.menuSpacerFour').css('background-image','none');
            $('.menuSpacerFourActive').css('background-image','url(media/png/menu_spacer_4_hover.png)');
         }
         if ($(thisElement).attr('id') == 'dropdownMenuThree')
         {
            $('.menuEndOne').css('background-image','url(media/png/menu_spacer_3_hov.png)');
            $('.menuEndOneActive').css('background-image','url(media/png/menu_spacer_3_hov.png)');
            $('.menuSpacerFourActiveRight').css('background-color','#ffffcc');
            $('.menuSpacerFourActiveRight').css('background-image','none');
         }
      }   
      formOptions = {
         'classNotEmpty': 'notEmpty',
         'classIsMail': 'isMail',
         'classClearForm': 'clearButton',
         'classSubmitForm': 'submitButton'
      };
      $('.ticketForm').formTool(formOptions);
      $('.spurenEintrag').mouseover(
         function()
         {
            $('.textBlockSpuren').css('background-image','url('+$('#rolloverText'+$(this).attr('id')).html()+')');
         }
      );
      $('.spurenMehr').click(
         function()
         {
            $('.shortText').hide();
            $('.longText').show();
            return false;
         }
      );

      var activeHeaderMediaboxEntry = -1;
      var fadeTime = 500;
      var updateHeaderMediabox = function() {
         if (activeHeaderMediaboxEntry + 1 < headerMediabox.length) {
            activeHeaderMediaboxEntry += 1;
         } else {
            activeHeaderMediaboxEntry = 0;
         }
         var mediaboxEntry = headerMediabox[activeHeaderMediaboxEntry];
         var file = 'http://data.heimat.de/tools/image_toolkit.php?file='+mediaboxEntry['path']+mediaboxEntry['file']+'&width=500&height=171&do=resize';
         $('.header-link').css({
            opacity: 0,
            backgroundImage: 'url('+file+')'
         }).animate({
            opacity: 1
         }, fadeTime, function() {
            $(this).css('background-image', 'none');
            $('.header').css('background-image','url('+file+')');
         });
         setTimeout(function() {
            $('.header-link').attr('href', mediaboxEntry['url']);
         }, parseInt(fadeTime / 2));
      };

      if (headerMediabox.length > 1) {
         updateHeaderMediabox();
         setInterval(updateHeaderMediabox, 3000);
      } else {
         fadeTime = 0;
         updateHeaderMediabox();
      }
   }
);
function autoToggle()
{
   if (timeout != "STOP")
   {
      if (activePic == $('.pic_links').children().length-1)
         activePic = 0;
      else
         ++activePic;
      $($('.pic_links').children()[activePic]).dblclick();
   }
   window.setTimeout("autoToggle()", 5000);
}
function menuMouseOut(thisElement,type)
{
   if (type == "parent")
      $('.'+$(thisElement).attr('id')).hide();
   else
      $(thisElement).hide();
   if ($(thisElement).hasClass('dropdownMenuFive'))
   {
      $('.menuSpacerFive').css('background-image','url(media/png/menu_spacer_5.png)');
      $('.menuSpacerFiveActiveRight').css('background-image','url(media/png/menu_spacer_5_active_right.png)');
   }
   if ($(thisElement).hasClass('dropdownMenuFour'))
   {
      $('.menuSpacerFour').css('background-image','url(media/png/menu_spacer_4.png)');
      $('.menuSpacerFourActive').css('background-image','url(media/png/menu_spacer_4_active.png)');
   }
   if ($(thisElement).hasClass('dropdownMenuThree'))
   {
      $('.menuEndOne').css('background-image','url(media/png/menu_spacer_3.png)');
      $('.menuEndOneActive').css('background-image','url(media/png/menu_spacer_3_active.png)');
      $('.menuSpacerFourActiveRight').css('background-image','url(media/png/menu_spacer_4_active_right.png)');
   }
}   

function switchImage(picPath, picCopy, actualElement)
{
   var image = $('<img id="detail_main_image_new" src="'+picPath+'" alt=""/>');
   image.hide();
   image.css('position','absolute');
   $('.pic_link').css('color','#000000')
   .css('cursor','pointer');
   $(actualElement).css('color','#c0c0c0')
   .css('cursor','default');
   $('#detail_main_image_copy').html(picCopy);
   if ($('#detail_main_image_copy').html() == " " || $('#detail_main_image_copy').html() == "")
      $('#detail_main_image_copy').hide();
   else
      $('#detail_main_image_copy').show();
   $(image).ready(
      function()
      {
         $(image).click(
            function()
            {
               $(this).css('cursor','default');
               timeout = "";
            }
         );
         $(image).insertBefore('#detail_main_image');
         $('#detail_main_image').fadeOut(1000);
         $('#detail_main_image_new').fadeIn(
            1000,
            function()
            {
               $('#detail_main_image_new').css('position','static');
               $('#detail_main_image').remove();
               $('#detail_main_image_new').attr('id','detail_main_image');
            }
         );
      }
   );
}

function showArtistProductions(artistId, type, artistType)
{
   var idCss = artistType + '_' + artistId;
   if (type == "subbox")
   {
      $('div#' + idCss).css('display', 'block');
   }
   else
   {
      if ($('div#artistproductions_data_' + idCss).html() == "")
         $('div#artistproductions_data_' + idCss).load('pages/kuenstlerproduktionen.php?id=' + artistId + "&type=" + artistType);
      $('div#artistproductions_' + idCss).css('display', 'block');
      $('div#artistproductions_' + idCss).css('left', mouseX+'px');
      if (IE)
         $('div#artistproductions_' + idCss).css('top', mouseY+document.documentElement.scrollTop+'px');
      else
         $('div#artistproductions_' + idCss).css('top', mouseY+'px');
      $('div#artistproductions_' + idCss).mouseover(
         function()
         {
            $(this).css('display','block');
               return false;
         }
      );
   }
}

if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
mouseX = 0;
mouseY = 0;
function getMouseXY(e)
{
  if (IE)
  {
    tempX = event.clientX + document.body.scrollLeft;
    tempY = event.clientY + document.body.scrollTop;
  }
  else
  {
    tempX = e.pageX;
    tempY = e.pageY;
  }  
  if (tempX < 0)
  {
     tempX = 0;
  }
  if (tempY < 0)
  {
     tempY = 0;
  }
  mouseX = tempX;
  mouseY = tempY;
  return true;
}
function hideArtistProductions(idCss, type)
{
   if (type == "subbox")
   {
      $('div#' + idCss).hide();
   }
   else
   {
      $('div#artistproductions_' + idCss).hide();
   }
}
function setCalendar(month, year)
{
   if (typeof(aktiv) != "undefined")
      window.clearTimeout(aktiv);
   $('#ajaxPosition').fadeOut(125,function(){
      $.get('calendar.php',{
         'top_year': year,
         'top_month': month,
         'startDate': $('.hiddenInfo .startDate').html(),
         'endDate': $('.hiddenInfo .endDate').html()
      },function(data){
         aktiv = window.setTimeout("document.location.href = $('.showMonth').attr('href');", 3000);
         $('#ajaxPosition').html(data).fadeIn(125);
      });
   });
}
function changeLogo(fade)
{
   if (fade=="in")
   {
      $('#logofade').fadeIn(1000,
         function()
         {
            setTimeout("changeLogo('out')",5000);
         }
      );
   }
   else
   {
      $('#logofade').fadeOut(1000,
         function()
         {
            setTimeout("changeLogo('in')",5000);
         }
      );
   }
}


