$(document).ready(function() {
  
  combinewidgets(['text-3','text-11']);
  combinewidgets(['text-4','text-16']);
  
  $('.multiplewidgets .navi a').live('click',function(){
    number = $(this).parent()[0].className;
    $(this).closest('.multiplewidgets').find('.box').hide().closest('.multiplewidgets').find('.box:eq('+number+')').show();
    $(this).closest('.navi').find('a').removeClass('active');
    $(this).addClass('active');
    return false;
  });
  
  if (!($.browser.msie && parseInt($.browser.version) < 7)) {
  
  
      
  $('a[href*=".pdf"], a[href*="download.php"]').not('a.nosymbol, .media a').each(function(){
    var bild = $(this).find('img').clone();
    $(this).find('img').remove();
    $(this).addClass('pdflink').prepend('<span class="icon">&nbsp;</span>').prepend(bild);
  });
  
  $('a[href^="http"]').not('a[href*="sennewald.de"], a.nosymbol').each(function(){
    var bild = $(this).find('img').clone();
    $(this).find('img').remove();
    if (!$(this).hasClass('pdflink')) {
      $(this).addClass('external').prepend('<span class="icon">&nbsp;</span>').prepend(bild);
    }
  });
  
  $('.media a.video').click(function(){
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { 
		  window.open('/wp-content/themes/sennewald/video.php?video='+this.href, '_self');
		} else {
		  window.open('/wp-content/themes/sennewald/video.php?video='+this.href, 'video', "width=800,height=600,left=100,top=100,scrollbars=no,menubar=no,resizable=no,status=no,toolbar=no");
		}
		return false;
  });
  
}
  
   projekktor('video', {
   	playerFlashMP4:		'/wp-content/themes/sennewald/js/jarisplayer.swf'
    });
    
    $('#gallery img').hide();
    $('#gallery img:first-child').addClass('active').show();
    
    
    $('.page-id-33 h3').next().hide();
  	    $('.page-id-33 h3').click(function(){
  	      $(this).toggleClass('active');
  	      if ($(this).next().css('display') == "none") {
  	        $(this).next().slideDown(400);
  	    } else {
  	      $(this).next().slideUp(400);
  	    }
  	    });

  		$('.page-id-188 h3').next().hide();
  		    $('.page-id-188 h3').click(function(){
  		      $(this).toggleClass('active');
  		      if ($(this).next().css('display') == "none") {
  		        $(this).next().slideDown(400);
  		    } else {
  		      $(this).next().slideUp(400);
  		    }
  		    });
    
                  
});


setInterval("nextimage()",6000);

function nextimage() {
  $('#gallery .active').fadeOut(1200, function(){
    $(this).removeClass('active')
  });
  
  if (!$('#gallery .active').next().attr('src')) {
    var next = $('#gallery img:first-child');
  } else {
    var next = $('#gallery .active').next();
  }
  
  $(next).fadeIn(1200, function(){
    $(this).addClass('active');
  });  
}


function combinewidgets(ids) {
  multid = "multi-"+parseInt(Math.random() * 1000);
  $('#'+ids[0]).wrap('<div id="'+multid+'" class="multiplewidgets"></div>');
  
  $('#'+multid).prepend('<ul class="navi"></ul>');
  
  $(ids).each(function(i){
    if (i != 0) {
      $('#'+this).appendTo('#'+multid).hide();
    }
  });
  $(ids).each(function(i){
    headline = $('#'+this+' h2').text();
    $('#'+this+' h2').remove();
    $('#'+multid+' .navi').append('<li class="'+i+'"><a href="#">'+headline+'</a></li>');
  });
  $('#'+multid+' .navi li:eq(0) a').addClass('active');
  
}
