animatedPic = false;
autoAnimate = '';

function trim (string)
{
  return string.replace (/^\s+/, '').replace (/\s+$/, '');
}
function changeLogo(fade)
{
   if (fade=="in")
   {
      $('#logofade').fadeIn(1000,
         function()
         {
            setTimeout("changeLogo('out')",5000);
         }
      );
   }
   else
   {
      $('#logofade').fadeOut(1000,
         function()
         {
            setTimeout("changeLogo('in')",5000);
         }
      );
   }
}
function mouseOver(myObject)
{
   //$(myObject).parent().children('div').fadeIn(250);
   $(myObject).parent().children('div').show();
   if (trim($(myObject).parent().find('.menuTitle').attr('id')) == "sommerfestival")
   {
      if ($('#smallSpacer2').attr('alt') != "")
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small_active_left_hover.png')
      }
      if ($('#smallEnd1').attr('alt') == "")
      {
         $('#smallEnd1').attr('src','media/png/menu_end_hover.png');
      }
      else
      {
         $('#smallEnd1').attr('src','media/png/menu_end_hover_active.png');
      }
   }
   if (trim($(myObject).parent().find('.menuTitle').attr('id')) == "tickets")
   {
      if ($('#smallEnd2').attr('alt') != "")
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small_active_left_hover.png')
      }
      if ($(myObject).parent().children('span').hasClass('active'))
      {
      }
      else if ($('#smallSpacer1').attr('alt') == "")
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small_inactive.png');
      }
      else
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small_active_left_hover.png');
      }
   }
   if (trim($(myObject).parent().find('.menuTitle').attr('id')) == "service")
   {
      if ($(myObject).parent().children('span').hasClass('active'))
      {
      }
      else if ($('#smallSpacer2').attr('alt') == "")
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small_inactive.png');
      }
      else
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small_active_left_hover.png');
      }
   }
}
function mouseOut(myObject)
{
   //$(myObject).fadeOut(250);
   $(myObject).hide();
   if (trim($(myObject).find('.menuTitle').attr('id')) == "sommerfestival")
   {
      if ($('#smallSpacer2').attr('alt') != "")
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small_active_right.png')
      }
      if ($(myObject).parent().children('span').hasClass('active'))
      {
         $('#smallEnd1').attr('src','media/png/menu_end_active_right.png');
      }
      else if ($('#smallEnd1').attr('alt') == "")
      {
         $('#smallEnd1').attr('src','media/png/menu_end.png');
      }
      else
      {
         $('#smallEnd1').attr('src','media/png/menu_end_active_left.png');
      }
   }
   if (trim($(myObject).find('.menuTitle').attr('id')) == "tickets")
   {
      if ($('#smallEnd2').attr('alt') != "")
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small_active_right.png')
      }
      if ($(myObject).parent().children('span').hasClass('active'))
      {
      }
      else if ($('#smallSpacer1').attr('alt') == "")
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small.png');
      }
      else
      {
         $('#smallSpacer1').attr('src','media/png/menu_spacer_small_active_left.png');
      }
   }
   if (trim($(myObject).find('.menuTitle').attr('id')) == "service")
   {
      if ($(myObject).parent().children('span').hasClass('active'))
      {
      }
      else if ($('#smallSpacer2').attr('alt') == "")
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small.png');
      }
      else
      {
         $('#smallSpacer2').attr('src','media/png/menu_spacer_small_active_left.png');
      }
   }
}

/*function changeImage(myObject)
{
   if (!animatedPic && $(myObject).css('color') != 'rgb(160, 160, 160)')
   {
      animatedPic = true;
      $('.pictureNumbers span').css('color','#000000');
      $(myObject).css('color','#a0a0a0');
      $('<img src="'+$(myObject).children('img').attr('src')+'" alt="" style="display:none;position:absolute;left:0px;top:0px;/>')
         .appendTo('.picPlace').fadeIn(
            500,
            function()
            {
               animatedPic = false;
               $('.picPlace .copyright').html($(this).children('img').attr('alt'));
               if ($(this).children('img').attr('alt') == "")
               {
                  $('.picPlace .copyright').hide();
               }
               else
               {
                  $('.picPlace .copyright').show();
               }
            }
         );
   }
}
function autoImageToggle()
{
   if ($('.pictureNumbers span').length > 1)
   {
      for (var i=0; i<$('.pictureNumbers span').length; i++)
      {
         if ($($('.pictureNumbers span')[i]).css('color') == 'rgb(160, 160, 160)')
         {
            if (i==$('.pictureNumbers span').length-1)
            {
               i = -1;
            }
            autoAnimate = window.setTimeout("autoImageToggle()",5000);
            changeImage($('.pictureNumbers span')[i+1]);
            break;
         }
      }
   }
}*/

var slideshowPosition = 0,
   slideshowInterval = null;

function updateSlideshow(pos) {
   var item = $('.pictureNumbers span').css('color', '#000000').eq(pos).css('color', '#A0A0A0'),
      img = item.children('img');
   $(document.createElement('img'))
      .attr('src', img.attr('src'))
      .css({
         display:   'none',
         position:  'absolute',
         left:      '0px',
         top:       '0px',
         'z-index': 1
      })
      .appendTo('.picPlace')
      .fadeIn(500, function() {
         var copyright = img.attr('alt');
         
         if (copyright.length > 0) {
            $('.picPlace .copyright').html(copyright).show();
         } else {
            $('.picPlace .copyright').hide();
         }
      });
}

$(document).ready(
   function()
   {
      $('.additionalSubMenu').css('display', 'none');
      //autoAnimate = window.setTimeout("autoImageToggle()",5000);
      if (typeof(slideShow) !== 'undefined')
      {
	      slideshowInterval = setInterval(function () {
	         slideshowPosition = (slideshowPosition + 1) % $('.pictureNumbers span').length;
	         updateSlideshow(slideshowPosition);
	      }, 5000);
      }  
      $('.pictureNumbers span').click(function () {
         if (slideshowInterval !== null) {
            clearInterval(slideshowInterval);
            slideshowInterval = null;
         }
         
         updateSlideshow(parseInt($(this).text(), 10) - 1);
      });
      
      setTimeout("changeLogo('in')",5000);
      formOptions = {
         'classNotEmpty': 'notEmpty',
         'classIsMail': 'isMail',
         'classClearForm': 'clearButton',
         'classSubmitForm': 'submitButton'
      };
      $('.ticketForm').formTool(formOptions);

      $('.smallMenu span').hover(
         function()
         {
            mouseOver(this);
          
            $(this).prev('div').children('div').children('div').children('div').children('div').children('a').each(function() {
               if($(this).attr('class')== "showAdditionalMenu") {
                 $(this).mouseover(function(){
                   $('.additionalSubMenu').css('display', 'block');
                 });
               } else {
                   $(this).mouseover(function(){
                   $('.additionalSubMenu').css('display', 'none');
                 });
               }
            });
            
           //show additional Submenu when mouse over

              
         },
         function(){}
      );
      $('.dopDownMenu').hover(
         function(){},
         function()
         {
            if ($.browser.msie)
            {
               var menuElement = this;
               menuTimer = window.setTimeout(
                  function()
                  {
                     mouseOut(menuElement);
                  },
                  100
               );
            }
            else
            {
               mouseOut(this);
            }
         }
      );
     
      $('.closeMenu').hover(
         function()
         {
           $(this).parent().mouseout();
         },
         function(){}
      );
      
      if ($.browser.msie)
      {
         //TODO: fix this for damn ie7
         $('.menuEntries').css('padding-top','0px');
         $('.dopDownMenu a').hover(
            function()
            {
               window.clearTimeout(menuTimer);
            },
            function(){}
         );
      }
      if ($.browser.msie && $.browser.version == '6.0')
      {
         $('.smallMenu .entry').each(
            function()
            {
               if ($(this).parent().children('.dopDownMenu').children('.menuTitle').attr('id') == "sommerfestival")
               {
                  if ($('.languageSwitch').html()=='ENGLISH')
                  {
                     $(this).parent().css('width','112px');
                  }
                  else
                  {
                     $(this).parent().css('width','114px');
                  }
               }
               if ($(this).parent().children('.dopDownMenu').children('.menuTitle').attr('id') == "tickets")
               {
                  $(this).parent().css('width','58px');
               }
               if ($(this).parent().children('.dopDownMenu').children('.menuTitle').attr('id') == "service")
               {
                  $(this).parent().css('width','59px');
               }
            }
         );
         $('.distanceBox').css('width','599px');
         $('.linksContainer, .pagesubtitle, .inputDescription, .inputsLeft, .classForFixIE, .inputsRight, .checkBoxes input, .distanceBox .media, .topMenuPositioner a, .eventHead a, .eventHead div').css('position','relative').css('z-index','10');
         $('.shadowLight, .shadowMiddle, .shadowDark, .shadowedBox').css('right','0px').css('bottom','0px').css('left','0px').css('top','0px').css('background-image','none');
         $('.shadowLight, .shadowMiddle, .shadowDark').css('border','0px');
         $('.clear').css('display','inline');
         $('.line').css('font-size','0px');
         $('.checkText').css('padding-bottom','10px');
         $('.checkBoxes input').css('border','0px');
         $('.topMenuPositioner .clear').css('display','block');
         $('.newsletterBox form').css('width','220px').css('overflow','hidden').css('display','block');
         $('.boxBlue').css('background-image','url(media/png/blue_stripes.png)');
         $('.hpgRight').css('overflow','hidden').css('position','relative').css('width','240px');
         
         if ($('.eventSmall').length > 0)
         {
            //cause the ie6 totaly shut down its render, we need to rebuild the events from scratch
            
            //first we save all events into an array
            var i = 0;
            var events = new Array();
            while (i < $('.eventSmall').length)
            {
               events[i] = $($('.eventSmall')[i]);
               i++;
            }
            //then we remove them, which lets the ie6 display the page again.
            $('.eventSmall, .distanceBoxLeft clear').remove();
            
            //now we have to create the event-table
            var i = 0;
            var x = 0;
            var table = '<table><tr>';
            while (i < events.length)
            {
               if (x == 3)
               {
                  x = 0;
                  table += '</tr><tr>';
               }
               table += '<td style="vertical-align:top;"><div class="eventSmall" style="float:none;">'+$(events[i]).html()+'</div></td>';
               x++;
               i++;
            }
            while (x < 3)
            {
               table += '<td>&nbsp;</td>';
               x++;
            }
            table += '</tr></table>';
            
            //and at last, we need to put the table into the page
            $('.distanceBoxLeft').prepend(table);
            
            //solution: 30% of all user are using ie6. please upgrade!!!
         }
         
         /*
         $('.pictureNumbers span').click(
            function()
            {
               $('.pictureNumbers span').css('color','#000000');
               $(this).css('color','#a0a0a0');
               $('.picPlace img').attr('src',$(this).children('img').attr('src'));
               $('.picPlace .copyright').html($(this).children('img').attr('alt'));
               if ($(this).children('img').attr('alt') == "")
               {
                  $('.picPlace .copyright').hide();
               }
               else
               {
                  $('.picPlace .copyright').show();
               }
            }
         );
         */
         
         $('img').ifixpng(); 
      }
   }
);

