/*
  Place application specific javascripts into this file.
  Include this into your template using javascript_include_tag('application', :theme => true)
*/

$(document).ready(function() {
  var nextclick = 2;
	$('#menu ul li ul').hide();
	$('#menu ul li').mouseenter(function() {
		$(this).addClass('selected');
		$(this).find('ul').show();
	});
	$('#menu ul li').mouseleave(function() {
		$(this).removeClass('selected');
		$(this).find('ul').hide();
	});
  $('#rotating_blocks .text_blocks .text_block_container div').click(function() {
    if ($(this).hasClass('inactive')){
      var itemnr = $(this).attr('id').replace("text","");
      var image = $('#rotating_blocks .image_blocks #image'+itemnr);
      var oldtext = $('#rotating_blocks .text_blocks .text_block_container div.active');
      oldtext.removeClass('active');
      oldtext.addClass('inactive');
      $(this).removeClass('inactive');
      $(this).addClass('active');
      var oldimage = $('#rotating_blocks .image_blocks div.active');
      oldimage.removeClass('active');
      oldimage.addClass('inactive');
      image.removeClass('inactive');
      image.addClass('active');
      nextclick = parseInt(itemnr)+1;
      if (nextclick > 3) {nextclick = 1;}
    }
  });
  var detecthome = $('#rotating_blocks');
  if (detecthome != undefined && detecthome.length > 0) {
    setInterval(function(){
      var nextonetoclick = $('#rotating_blocks .text_blocks .text_block_container #text'+nextclick);
      nextonetoclick.click();
    },6000);
  }
});


