
/*
 *************************************************************************
 * jQuery HeroSlider
 *
 * copyright (c) MHR Interactive, all rights reserved.
 *
 * @version 1.0
 * @licensee: HDnet GmbH & Co. KG
 *
 *************************************************************************
 */

var slideWidth = 960;
var slideCount = 0;
var currentSlide = 0;
var lock = 0;

$(document).ready(function() {
	
	/* BEN: navLang */
	$('#navLang').hover(function() {
		$(this).animate({'height':'32px'},250);				 
	},function(){
		$(this).animate({'height':'17px'},250);	
	});
	
	
	// analyze how mayn hero images we have int he dom
	slideCount = $('#stage').children().size() -1; // minus clearer
	
	// show thumbnails only if >1 image available
	if(slideCount>1) {
		//$('#heroThumbs').css('width',$('#heroThumbs').width());
		$('#heroThumbs').fadeIn('slow');
		thumbActivate(0);
		$('#heroSliderRight').fadeIn('slow');

		}
	
	$('#heroSliderLeft').click(function() {
		left(1);
		}
	);
	
	$('#heroSliderRight').click(function() {
		right(1);
		}
	);
	
	/* BEN: Make navMain work inostrusive & properly */	
	//$('.heroNavi').hide();
	//$('ul#navMain li img.act').hide();
	$('ul#navMain li').hover(function() {
		$(this).addClass('hover');
		$(this).find('.heroNavi').show();
		$(this).find('>a>img.no').hide();
		$(this).find('>a>img.act').show();
	},function() {
		$(this).removeClass('hover');
		$(this).find('.heroNavi').hide();
		if($(this).hasClass('act')) {
			$(this).find('>a>img.no').hide();
			$(this).find('>a>img.act').show();
		} else {
			$(this).find('>a>img.act').hide();
			$(this).find('>a>img.no').show();
		}
	});
	
	//Adjusting height of level2 depending on number of nav-items
	$('ul.heroNaviLevel1').each(function() {
		var space = $(this).find('>li').length * 28 + 20;
		//console.log(space);
		$(this).parent().height(space);
		$(this).parent().find('.heroNaviTransparent').height(space);
	});
	
	$('ul.heroNaviLevel1 li').hover(function() {
		$(this).find('.heroNaviLevel2').show();
	},function() {
		$(this).find('.heroNaviLevel2').hide();
	});
	$('ul#navMain li.act>a>img.no').hide();
	$('ul#navMain li.act>a>img.act').show();
	
	/* BEN: Tabs */
	$('ul.tabHeadlines li:first').addClass('active');
	$('div.tabContent div.tabCon:first').addClass('active');
	 $('ul.tabHeadlines li').each(function(i){
		$(this).click(function(){
			$(this).parent().children('.active').removeClass('active');
			$(this).addClass('active');		
			$('div.tabContent div.tabCon').each(function(j) {
				$(this).removeClass('active');
				if(i==j) $(this).addClass('active');
			});
		});
	});	
	 
	/* BEN: Newsletter */
	$('form#newsletter input').each(function(i){
		$(this).attr({rel:$(this).val()});					 
		$(this).focus(function() {
        	if($(this).attr('rel')==$(this).val()){
				$(this).val('');
			}
    	});
	});
	$('form#newsletter input').blur(function() {
         if($(this).val()==''){
			$(this).val($(this).attr('rel')); 
		 }
    });
});

function left(steps) {
	var currentStagePos = -1*currentSlide * slideWidth;
	var scrollOffset = (currentStagePos + (steps * slideWidth));

	currentSlide = currentSlide - steps;

	if(currentSlide <= 0) {
		$('#heroSliderLeft').fadeOut(10);
	} 
	
	if(currentSlide < slideCount)
		$('#heroSliderRight').fadeIn('fast');

	thumbActivate(currentSlide);

	$('#stage').stop(false,true).animate(
			{
				left: scrollOffset
	  		}, 		
	  			{
		  			duration: 850,
		  			easing: 'easeOutCubic'
		  		} 
			)
	}

function right(steps) {
	var currentStagePos = -1*currentSlide * slideWidth;
	var scrollOffset = (currentStagePos - (steps * slideWidth));
	
	currentSlide = currentSlide + steps;
	
	if(currentSlide > 0)
		$('#heroSliderLeft').fadeIn('slow');
	
	if(currentSlide+1 >= slideCount) {
		$('#heroSliderRight').fadeOut(10);
	} 
	
	thumbActivate(currentSlide);
	
	$('#stage').stop(false,true).animate(
			{
				left: scrollOffset
	  		}, 		
			{
				duration: 850,
				easing: 'easeOutCubic'
			}
		)	
	}

function goto(obj) {
		
	var step = obj.id.substring(9);	// id of caller must be "heroThumbINTEGER"	
	var stepOffset;
	
	if(step == currentSlide) {	
		return;
		}
	
	if(step > currentSlide) {
		stepOffset =  step - currentSlide;
		right(stepOffset);	
		}
	
	if(step < currentSlide) {
		// x nach links	
		stepOffset = currentSlide - step;
		left(stepOffset);
		}
}

function thumbActivate(no) {
	
		// hide all others
		var target = '#heroThumb' + no;
		$('.heroThumb').find('.heroThumbOverlay').stop(true,true).animate(
			{
				opacity: 0.5
	  		}, 		
			{
				duration: 20,
				easing: 'easeOutCubic'
			}
		)	
		
		// this on
		$(target).find('.heroThumbOverlay').stop(true,true).animate(
			{
				opacity: 0
	  		}, 		
			{
				duration: 20,
				easing: 'easeOutCubic'
			}
		)	
	}
	
	
/* heroNav helper functions*/
/*
function heroNaviLevelOver(obj,swap) {
	$(obj).addClass('active');
	$(obj).find('.heroNaviLevel2').show(); 
	$(obj).find('img:first').attr('src', swap);
}

function heroNaviLevelOut(obj,swap) {
	$(obj).removeClass('active');	
	$(obj).find('.heroNaviLevel2').hide();
	$(obj).find('img:first').attr('src', swap);	
}

// navMain helper 
function navMainHeroNaviShow(target,hover) {
	$(target).next().show();
	$(target).find('img').attr('src', hover);
	
}

function navMainHeroNaviHide(target,hover) {
	$(target).next().hide();
	$(target).find('img').attr('src', hover);
}
*/


// fce-tabs helper 
/*
function tabActivate(obj) {
	var no;
	
	// who am i?
	var allMySiblings = $(obj).parent().children();
	for(var i=0;i<allMySiblings.length;i++) {
		if(allMySiblings[i] == obj) {
			 no = i;
			 $(obj).addClass('active');				  
		} else {
			$(allMySiblings[i]).removeClass('active'); 
		}
	
	}
	
	// handle content tabs
	var c = $('.tabContent').children();
	for(var x=0; x < c.length; x++) {
		if(x == no) {
			$(c[x]).show();
		} else {
			$(c[x]).hide();
		}
	}
}
*/


