$(document).ready(function(){


   //expand unibox Links
   $('.unibox').each(function(){
      if( $(this).find('a').length == 1 )
      {
          var linkHref=$(this).find('a').attr('href');
          $(this).addClass('linkedBox').click(function(){
              window.location.href = linkHref;
          });
      }

   });

   $('.linkedBox').hover(function(){
       $(this).find('a').css('text-decoration','underline');
   },function(){
       $(this).find('a').css('text-decoration','none');
   });


   $('#s,input[name=s]').attr('placeholder','Suche');

   //Slider if present
   if($('#sliderCage').length > 0) {
      var slides = $('.slide').length;
      var pause = 8500;
      intval = window.setInterval('moveIt(800,'+slides+')',pause);

	  $('.slide a').hover(function(){
		$(this).children('span').stop().animate({fontSize : '26px',bottom: '2px'},200);
	  },function(){
	    $(this).children('span').stop().animate({fontSize : '22px',bottom: '0px'},200);
	  });
      $('#sliderCage').hover(function(){
        $('a.ffd,a.back').stop().fadeTo(200,1);
      },function(){
        $('a.ffd,a.back').stop().fadeTo(200,0.6);
      });

      
// slide navigation
      $('a.back').click(function(){
          clearInterval(intval);
          pause=12500;
          moveBack(800,slides,pause);
          intval=window.setInterval('moveIt(800,'+slides+')',pause);
      });

      $('a.ffd').click(function(){
          clearInterval(intval);
          pause=12500;
          moveIt(800,slides,pause);
          intval = window.setInterval('moveIt(800,'+slides+')',pause);

      });
  } // endif;


  $('strong:empty,p:empty').remove();
  $('.equal').equalHeights();



});// end doc ready



// variables and functions
var cycle = 1;

//easing method
jQuery.easing['jswing'] = jQuery.easing['swing'];
jQuery.extend( jQuery.easing,
{
	def: 'easeInOutQuad',
    easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	}

});

// slider func
function moveIt(speed, imgCount){
      if(cycle < imgCount) {
          //console.log('ffd - cycle: '+cycle+' imgCount: '+imgCount);
        $('#view').animate({left: '-=1000'}, speed, 'easeInOutQuad', function() {
              cycle++;
        });
      }
      else {
        $('#view').animate({left: '+='+(imgCount-1)+'000'}, speed, 'easeInOutQuad', function() {
            //console.log('ffdX - cycle: '+cycle+' imgCount: '+imgCount);
              cycle = 1;
        });
      }
}
function moveBack(speed, imgCount){
      if(cycle >= 2) {
          console.log('back - cycle: '+cycle+' imgCount: '+imgCount);
        $('#view').animate({left: '+=1000'}, speed, 'easeInOutQuad', function() {
              cycle--;
        });
      }
      else {
        $('#view').animate({left: '-='+(imgCount-1)+'000'}, speed, 'easeInOutQuad', function() {
            console.log('backX - cycle: '+cycle+' imgCount: '+imgCount);
              cycle = imgCount;

        });
      }
}

// equal heights for boxes type=equal
$.fn.equalHeights = function(px) {
	var currentTallest = 0;
	$('.equal').each(function(){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height();}
	});
	$('.equal div').css({'height': (currentTallest-=20)});
};


