
/*  Mega Menu */
$.fn.dropdown = function() {
  $(this).hover(function(){
    $(this).addClass("hover");
    $('> .dir',this).addClass("open");
    $('ul:first',this).css('visibility', 'visible');
  },function(){
    $(this).removeClass("hover");
    $('.open',this).removeClass("open");
    $('ul:first',this).css('visibility', 'hidden');
  });
}

/*  Tagcloud */

$(function(){
  $('form[name=newsletter-reg]').submit(function() {
    if( $('#iwagbaccepted').attr('checked') == true){
      return true;
    }
    else {      
      alert('Bitten stimmen Sie den Datenschutzbestimmungen zu.');
      return false;
    }
  });
  //if (document.getElementById('tagcloud')) {
    $('#tagcloud').tagcloud({
    zoom:120,
    min_zoom:50,
      centrex:120,
      centrey:120,
      foreground_colour:'#444',
      background_colour:'#fff'
      });
	//fix tagcloud-bug "text behind the linktag"
	$('div.point','#tagcloud').each(function(){
    	if(!$('a',this).text())$(this).contents().filter(function(){return this.nodeType==3;}).appendTo($('a',this));
	});
  //}
});

function advisorClick(){
    jQuery(this).parents('.advisorBlock:first').nextAll('.advisorBlock:first').toggle(400);
}



$(document).ready(function() {
  /* news box */
  if ( $(".news-latest-item").length > 0 ) {
    $(".news-latest-item").corner("45px tl");
  }
  /* footer background */
  if (document.getElementById('footer')) {
    $("#footer").corner("90px tl");  
  }
  //Slideshow
  if(jQuery('#gallery .content').length > 0){
    slideShow();
  }
  
  //menuSlideshow for Contacts
  if(jQuery('#page_700').length > 0){
  document.getElementById("headerImage").style.background = "none";
  document.getElementById('headerImage').innerHTML =
          '<span class="show" style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_ThorstenP.jpg " alt="Gesch�ftsf�hrer: Thorsten Pr�ser" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_GudrunM.jpg " alt="Vertriebsleitung: Gudrun M�ller" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_KerstinL.jpg " alt="Vertrieb: Kerstin L�hrsen" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_AlexandraB.jpg " alt="Vertrieb: Alexandra Bobert" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_SusanneJ.jpg " alt="Vertrieb: Susanne Jan�en" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_TimG.jpg " alt="Vertriebsassistenz und Recruiting: Tim Grossmann" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_AndreasM.jpg " alt="Vertriebsassistenz und Recruiting: Andreas M&ouml;ller" width="938" height="390" /></span>'
          + '<span style="opacity: 0;"> <img src="fileadmin/neusta-consulting/template/images/kontakt/consulting_Kontakt_MirelaM.jpg " alt="Office Management: Mirela Miljkovic" width="938" height="390" /></span>';
    menuSlideShow();
  }    
  /* beraterb�rse toggle text*/ 
  advisorChange();

  
});


function advisorChange(){
  jQuery('.advisorBlock').each(function(i,j){
    if(i%2 == 1){
      jQuery(this).hide();
    }
    if(i%2 == 0){
      jQuery(this).append(jQuery('<div />', {
        'html': '<p>[mehr]</p>',
        'class' : 'advisorMore',
        'click' : advisorClick
      }));
    }
  });
}



function slideShow() {

  //Set the opacity of all images to 0
  jQuery('#gallery span').css({opacity: 0.0});
  
  //Get the first image and display it (set it to full opacity)
  jQuery('#gallery span:first').css({opacity: 1.0});
  
  //Set the caption background to semi-transparent
  jQuery('#gallery .caption').css({opacity: 0.7});

  //Resize the width of the caption according to the image width
  jQuery('#gallery .caption').css({width: jQuery('#gallery span').find('img').css('width')});
  
  //Get the caption of the first image from REL attribute and display it
  jQuery('#gallery .content').html(jQuery('#gallery span:first').find('img').attr('rel')).animate({opacity: 0.7}, 400);
  
  //Call the gallery function to run the slideshow, 3000 = change to next image after 3 seconds
  setInterval('gallery()',3000);
  
}

function gallery() {
  
  //if no IMGs have the show class, grab the first image
  var current = (jQuery('#gallery span.show')?  jQuery('#gallery span.show') : jQuery('#gallery span:first'));

  //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  var next = ((current.next().length) ? ((current.next().hasClass('caption'))? jQuery('#gallery span:first') :current.next()) : jQuery('#gallery span:first'));  
  
  //Get next image caption
  var caption = next.find('img').attr('rel');  
  
  //Set the fade in effect for the next image, show class has higher z-index
  next.css({opacity: 0.0})
  .addClass('show')
  .animate({opacity: 1.0}, 1000);

  //Hide the current image
  current.animate({opacity: 0.0}, 1000)
  .removeClass('show');
  
  //Set the opacity to 0 and height to 1px
  jQuery('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });  
  
  //Animate the caption, opacity to 0.7 and heigth to 50px, a slide up effect
  jQuery('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '50px'},500 );
  
  //Display the content
  jQuery('#gallery .content').html(caption);
    
}

function menuSlideShow() {

  //Set the opacity of all images to 0
  jQuery('#headerImage span').css({opacity: 0.0});
  
  //Get the first image and display it (set it to full opacity)
  jQuery('#headerImage span:first').css({opacity: 1.0});
  
  //Set the caption background to semi-transparent
/*  jQuery('#headerImage .caption').css({opacity: 0.7}); */

  //Resize the width of the caption according to the image width
/*  jQuery('#headerImage .caption').css({width: jQuery('#headerImage span').find('img').css('width')}); */
  
  //Get the caption of the first image from REL attribute and display it
/*  jQuery('#headerImage .content').html(jQuery('#headerImage span:first').find('img').attr('rel')).animate({opacity: 0.7}, 400); */
  
  //Call the menuGallery function to run the slideshow, 3000 = change to next image after 3 seconds
  setInterval('menuGallery()',12000);
  
}

function menuGallery() {
  
  //if no IMGs have the show class, grab the first image
  var current = (jQuery('#headerImage span.show')?  jQuery('#headerImage span.show') : jQuery('#headerImage span:first'));

  //Get next image, if it reached the end of the slideshow, rotate it back to the first image
  var next = ((current.next().length) ? ((current.next().hasClass('caption'))? jQuery('#headerImage span:first') :current.next()) : jQuery('#headerImage span:first'));  
  
  //Get next image caption
  /* var caption = next.find('img').attr('rel');   */
  
  //Set the fade in effect for the next image, show class has higher z-index
  next.css({opacity: 0.0})
  .addClass('show')
  .animate({opacity: 1.0}, 1000);

  //Hide the current image
  current.animate({opacity: 0.0}, 1000)
  .removeClass('show');
/*  
  //Set the opacity to 0 and height to 1px
  jQuery('#headerImage .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });  
  
  //Animate the caption, opacity to 0.7 and heigth to 50px, a slide up effect
  jQuery('#headerImage .caption').animate({opacity: 0.7},100 ).animate({height: '50px'},500 );
  
  //Display the content
  jQuery('#headerImage .content').html(caption);
*/  
    
}
