// JavaScript Document

if( !console) var console = {log:function(){}};
// redirector for flash
function ziel(url) 
{
	console.log(url); 
	var continent = url.split('?')[1].split('=')[1].split('&')[0];
	var country = url.split('?')[1].split('=')[2];
	if( country=='Australia') window.location.href = 'http://www.merck.com.au/en/index.html';
	else if( country=='Austria') window.location.href = 'http://www.merck.at/en/index.html';
	else if( country=='Brazil') window.location.href = 'http://www.merck.com.br/pt/index.html';
	else if( country=='Canada') window.location.href = 'http://www.emdserono.ca/en/index.html';
	else if( country=='China') window.location.href = 'http://www.merck.cn/zh/index.html';
	else if( country=='France') window.location.href = 'http://www.merck.fr/en/index.html';
	else if( country=='Poland') window.location.href = 'http://www.merck.pl/en/index.html';
	else alert('Sorry, only Australia, Austria, Brazil, Canada, China, France and Poland are available for testing by now.');
}
// redirector for HTML dropdown
function ziel2(url)
{
	console.log(url);
	window.location.href = url;
	
}
function sleep(ms){
var zeit=(new Date()).getTime();
var stoppZeit=zeit+ms;
while((new Date()).getTime()<stoppZeit){
	}; 
}
window.addEvent( 'domready', function()
{
	
	
	// main navi dropdowns
	$$('#navMain > ul > li').each( function(num)
	{
		var over = false;
		var outDelay = $empty.delay(100);
		var hideDelay = $empty.delay(100);
		var layer = num.getElements('ul.layer')[0];
		layer.fade('hide').setStyle('display','none');
		num.addEvent('mouseover', function(e)
		{
			over = true;
			if( !Browser.Engine.trident) layer.set( 'tween', {duration:250}).setStyles({ display:'block' }).fade('in');
			else layer.setStyle('display','block').fade('show');
		});
		num.addEvent('mouseout', function(e)
		{
			over = false;
			$clear( outDelay);
			$clear( hideDelay);
			outDelay = (function()
			{
				if( over==false)
				{
					if( !Browser.Engine.trident)
					{
						layer.set( 'tween', {duration:500}).fade('out');
						hideDelay = (function()
						{
							layer.setStyle('display','none');
						}).delay(500);
					}
					else layer.setStyle('display','none');
				}
			}).delay(50);
		});
	});
	




	// teasers
if (document.getElementById("teasers") == null) {
	// no teaser - do nothing 
	} else {
    
// teaser - start dom script


function startPeriod()
	{
		clearPeriod();
		tPeriod = nextTeaser.periodical(tWait);
	//	$('autoplayBar').tween('width',789);
	}
	function clearPeriod()
	{
		$clear( tPeriod);
		$clear( tTimeout)
		$('autoplayBar').setStyle('width',1).set('tween',{duration:tWait,transition:'linear'});
	}	




	$('teasers').fade('in');
	var teasers = [];
	var tPeriod = $empty.delay(1);
	var tTimeout = $empty.delay(1);
	// Variable kann im Tridion �berschrieben werden 
	var tWait = (typeof waitDuration != "undefined") ? waitDuration : 40000; 
	$$('#teasers .teaser').each( function(num)

	{
	
	
		teasers.push( num.fade('hide'));
		num.getElements('.nextLink').fade('hide');
		num.getElements('.fullText').fade('hide');
		num.getElements('.article-podcast').fade('hide');
		num.getElements('.article-podcast-play').fade('hide');
		num.getElements('.teaserImgCaption').fade('hide');
		num.getElements('.bg')[0].fade(0.75);
		num.getElements('.bgleft')[0].fade(0.50);
		num.getElements('.shortText')[0].addEvent( 'mouseenter', function()
		{
			//(function(){ 
                                               sleep(500);
                                               var newHeight = num.getElements('.content .left')[0].getSize().y;
                                               if( num.getElements('.content .right')[0].getSize().y > newHeight) newHeight = num.getElements('.content .right')[0].getSize().y
                                               num.getElements('.bg')[0].set('tween',{duration:800}).tween( 'height', newHeight);
                                               num.getElements('.bgleft')[0].set('tween',{duration:800}).tween( 'height', newHeight);
                                               num.getElements('.nextLink').set('tween',{duration:300}).fade('in');
                                               num.getElements('.fullText').set('tween',{duration:1200}).fade('in');
                                               num.getElements('.article-podcast').set('tween',{duration:2000}).fade('in');
                                               num.getElements('.article-podcast-play').set('tween',{duration:2500}).fade('in');
                                               num.getElements('.teaserImgCaption').set('tween',{duration:2500}).fade('in');
                                               num.getElements('.shortText').set('tween',{duration:300}).fade('out');
                                               clearPeriod();
                                               $('autoplayTrack').set('tween',{duration:300}).fade('out');
			//}).delay(500)
		});
		num.getElements('.left h2')[0].addEvent( 'mouseenter', function()
		{
			                                               //(function(){ 
                                               sleep(500);
                                               var newHeight = num.getElements('.content .left')[0].getSize().y;
                                               if( num.getElements('.content .right')[0].getSize().y > newHeight) newHeight = num.getElements('.content .right')[0].getSize().y
                                               num.getElements('.bg')[0].set('tween',{duration:800}).tween( 'height', newHeight);
                                               num.getElements('.bgleft')[0].set('tween',{duration:800}).tween( 'height', newHeight);
                                               num.getElements('.nextLink').set('tween',{duration:300}).fade('in');
                                               num.getElements('.fullText').set('tween',{duration:1200}).fade('in');
                                               num.getElements('.article-podcast').set('tween',{duration:2000}).fade('in');
                                               num.getElements('.article-podcast-play').set('tween',{duration:2500}).fade('in');
                                               num.getElements('.teaserImgCaption').set('tween',{duration:2500}).fade('in');
                                               num.getElements('.shortText').set('tween',{duration:300}).fade('out');
                                               clearPeriod();
                                               $('autoplayTrack').set('tween',{duration:300}).fade('out');
			
		});
		
		num.getElements('.content')[0].addEvent( 'mouseleave', function()
		{
			                                   num.getElements('.bg')[0].set('tween',{duration:1000}).tween( 'height', 70);
                                               num.getElements('.bgleft')[0].set('tween',{duration:1000}).tween( 'height', 70);
                                               num.getElements('.nextLink').set('tween',{duration:100}).fade('out');
                                               num.getElements('.fullText').set('tween',{duration:600}).fade('out');
                                               num.getElements('.article-podcast').set('tween',{duration:500}).fade('out');
                                               num.getElements('.article-podcast-play').set('tween',{duration:500}).fade('out');
                                               num.getElements('.teaserImgCaption').set('tween',{duration:500}).fade('out');
                                               num.getElements('.shortText').set('tween',{duration:100}).fade('in'); 
                                               startPeriod();
                                               $('autoplayTrack').set('tween',{duration:2500}).fade('in');
  		})
	});
	var bn = $$('#teasers #btnNext')[0];
	bn.addEvent( 'mouseover', function() { bn.set('src', bn.get('src').replace(/-trans\.png/,'_over-trans.png')); });
	bn.addEvent( 'mouseout', function() { bn.set('src', bn.get('src').replace(/_over-trans\.png/,'-trans.png')); });
	bn.addEvent( 'mousedown', function() { bn.set('src', bn.get('src').replace(/_over-trans\.png/,'_down-trans.png')); });
	bn.addEvent( 'mouseup', function() { bn.set('src', bn.get('src').replace(/_down-trans\.png/,'_over-trans.png')); }); 
	bn.addEvent( 'click', function() { nextTeaser(); });
	var bp = $$('#teasers #btnPrev')[0];
	bp.addEvent( 'mouseover', function() { bp.set('src', bp.get('src').replace(/\-trans.png/,'_over-trans.png')); });
	bp.addEvent( 'mouseout', function() { bp.set('src', bp.get('src').replace(/_over-trans\.png/,'-trans.png')); }); 
	bp.addEvent( 'mousedown', function() { bp.set('src', bp.get('src').replace(/_over-trans\.png/,'_down-trans.png')); }); 
	bp.addEvent( 'mouseup', function() { bp.set('src', bp.get('src').replace(/_down-trans\.png/,'_over-trans.png')); }); 
	bp.addEvent( 'click', function() { prevTeaser(); });
	var actTeaser = teasers.length -1; // Gesamtanzahl der Teaser
	//alert (actTeaser);
	
	//actTeaser =10;
	var ln = $$('#teasers .nextArticle a');
	ln.addEvent( 'click', function() { nextTeaser(); });
	
	function prevTeaser()
	{
		var nt = actTeaser - 1;
		if( nt<0) nt = teasers.length-1;
		teasers.each( function(num) { num.set('tween',{duration:200}).fade('out'); });
		teasers[nt].dispose().inject( $('teasers')).set('tween',{duration:700}).fade('in');
		actTeaser = nt;
		startPeriod();
	}
	
	
		function nextTeaser()
	{
		 var nt = actTeaser + 1;
              var maxteaser = teasers.length;
			  var beteaser = maxteaser - nt;
			  var nt = actTeaser + 1;
			
		if( nt>teasers.length-1) nt = 0;
		teasers.each( function(num) { num.set('tween',{duration:200}).fade('out'); });
		teasers[nt].dispose().inject( $('teasers')).set('tween',{duration:700}).fade('in');
		actTeaser = nt;
		startPeriod();
	}
	
	
	
	function nextTeaserStart()
	{
		 var nt = actTeaser + 1;
	          var maxteaser = teasers.length;
			  var beteaser = maxteaser - nt;
			  var random = $random(1, nt);
	          var nt = random;
    	if( nt>teasers.length-1) nt = 0;
		teasers.each( function(num) { num.set('tween',{duration:200}).fade('out'); });
		teasers[nt].dispose().inject( $('teasers')).set('tween',{duration:700}).fade('in');
		actTeaser = nt;
		startPeriod();
	}
	nextTeaserStart();
//###	function startPeriod()
//###	{
//###		clearPeriod();
//###		tPeriod = nextTeaser.periodical(tWait);
//###	//	$('autoplayBar').tween('width',789);
//###	}
//###	function clearPeriod()
//###	{
//###		$clear( tPeriod);
//###		$clear( tTimeout)
//###		$('autoplayBar').setStyle('width',1).set('tween',{duration:tWait,transition:'linear'});
//###	}
	startPeriod();
}});



function logging(num){
			var newHeight = num.getElements('.content .left')[0].getSize().y;
			if( num.getElements('.content .right')[0].getSize().y > newHeight) newHeight = num.getElements('.content .right')[0].getSize().y
			num.getElements('.bg')[0].set('tween',{duration:300}).tween( 'height', newHeight);
			num.getElements('.bgleft')[0].set('tween',{duration:300}).tween( 'height', newHeight);
			num.getElements('.nextLink').set('tween',{duration:600}).fade('in');
			num.getElements('.fullText').set('tween',{duration:600}).fade('in');
			num.getElements('.shortText').set('tween',{duration:1000}).fade('out');
			clearPeriod();
			$('autoplayTrack').set('tween',{duration:300}).fade('out');
				}

var handler=false;
function nothing(){
}

//}




