$(document).ready(function(){
	
	if($.browser.mozilla) $('.imagelist li').addClass('clearfix');
	// worldwide submenu function
	$('#subww').hide(); // hide submenu worldwide if js is on
	
	$('#worldwide').click(function(){
		$('#ds_subww').remove(); // remove shadows
		$('#subww').slideToggle("fast",function(){
			var lp = ($('#worldwide').attr("style")&&$('#worldwide').attr("style").indexOf('98px')>-1)?'98px':($('#worldwide').attr("style")&&$('#worldwide').attr("style").indexOf('105px')>-1)?'105px':'80px';
			if($('#subww').css('display')== 'block') {
				$('#subww').dropShadow({top: 2,left: -1, bottom: 1, right: 1, blur: 2});
				$('#worldwide').css("background-position", lp+" -175px");
			} else {
				$('#worldwide').css("background-position", lp+" -215px");
			}
		});
		return false;
	});
	
	$('img').each(function() {
		$(this).attr('title',$(this).attr('alt'));
	});
	
	$('a').each(function() {
		if($(this).attr('href')&&$(this).attr('href').indexOf('disclaimer.jsp')>-1) {
			$(this).click(function() {
				return popup($(this).attr('href'),440,370);
			});
		}		
	});
	
	$('#footer .recommend').click(function() {
		return popup('recomen.php',440,570);
	});
	
	$('.tou').each(function() {
		$(this).click(function() {
			return popup('terms.php',440,570);
		});
	});
	$('.btn_patient a').each(function() {
		$(this).click(function() {
			return popup(/*VIPURL*/'/wcms_pm/pradaxa_prod/Site-Service/Home/confirm_professional.jsp',440,400);
		});
	});
		
	// Menufunctions
	$('#menu ul li').not('.active').children('ul').hide();
	$('#menu ul li span a').each(function(i){
		$(this).click(function(){
			$(this).parent().next().slideToggle('fast').parent().siblings().children('ul').slideUp('fast');
			$(this).parent().parent().toggleClass('active').siblings('.active').removeClass('active');
			setPosition();
			return false;
		});
	});
		
	// to change fontsize if js is on
	var nn = /*VIPURL*/'images/fontsize_normal.gif';
	var nh = /*VIPURL*/'images/fontsize_normal_h.gif';
	var mn = /*VIPURL*/'images/fontsize_middle.gif';
	var mh = /*VIPURL*/'images/fontsize_middle_h.gif';
	var bn = /*VIPURL*/'images/fontsize_big.gif';
	var bh = /*VIPURL*/'images/fontsize_big_h.gif';
	$('#menu').append('<p class="fontsize"><span>Tamaņo de texto</span> <img src="' + nh + '" id="normal" /><img src="' + mn + '" id="middle" /><img src="' + bn + '" id="big" /></p>');
	$('.fontsize #normal').click(function(){
		$('.dropShadow').remove();
		$(this).attr("src", nh).next('#middle').attr("src", mn).next('#big').attr("src", bn);
		$('body').css("font-size", "0.75em");	
		$('a#worldwide').css("background-position","80px -215px");
		$('.searchbox a.submit').css({top: "2px", right: "6px"});
		$('.searchbox #searchfield').css("margin-right","55px");
		$('#content .fontsize span').css("float", "left");
		setPosition();			
		setTimeout('loadShadow()',1500);
		return false;
	});
	$('.fontsize #middle').click(function(){
		//$('.dropShadow').remove();
		$(this).attr("src", mh).prev('#normal').attr("src", nn);
		$(this).attr("src", mh).next('#big').attr("src", bn);
		$('body').css("font-size", "0.85em");
		$('a#worldwide').css("background-position","98px -215px");
		$('.searchbox a.submit').css({top: "24px", right: "20px"});
		$('.searchbox #searchfield').css("margin-right","0px");
		$('#content .fontsize span').css("float", "none");
		setPosition();
		setTimeout('loadShadow()',1500);
		return false;
	});
	$('.fontsize #big').click(function(){
		$('.dropShadow').remove();
		$(this).attr("src", bh).prev('#middle').attr("src", mn).prev('#normal').attr("src", nn);
		$('body').css("font-size", "0.95em");
		$('a#worldwide').css("background-position","105px -215px");
		$('.searchbox a.submit').css({top: "24px", right: "20px"});
		$('.searchbox #searchfield').css("margin-right","0px");
		$('#content .fontsize span').css("float", "none");
		setPosition();
		setTimeout('loadShadow()',1500);
		return false;
	});
	
	setTimeout('loadShadow()',1500); // sIFR is too slow so the shadows must wait
	
	var laenge=self.location.search.length;
	$('.toggle-container div').hide();
	$('.toggle-container .toggle-link').each(function(i){
		if(laenge>0) {
			var param=self.location.search.substring(1,laenge);
			param=param.substr(param.indexOf("toggle")+7,param.length);
			if(i==param) {
				$('.dropShadow').remove();
				$(this).toggleClass('open');
				$(this).next('.toggle').slideToggle('fast');
				setTimeout('setPosition()',200);
				setTimeout('loadShadow()',1500);
			}
		} else {
			if(i==0&&$(this).attr('id')!='keepclose') {
				$('.dropShadow').remove();
				$(this).addClass('open');
				$(this).next('.toggle').slideToggle('fast');
				setTimeout('setPosition()',200);
				setTimeout('loadShadow()',1500);
			}			
		}
		$(this).click(function(){
			$('.dropShadow').remove();
			$(this).toggleClass('open');
			$(this).next('.toggle').slideToggle('fast');
			setTimeout('setPosition()',200);
			setTimeout('loadShadow()',1500);
			return false;
		});
	});
	
	$('.tab-container .register a').each(function(){
		$(this).click(function(){
			setTimeout('setPosition()',800);
		});
	});

	setTimeout('setPosition()',300);
	fixFlash();
	setTimeout('hideAdblock()',1300);
	
	$('.zoomIn').show();
	$('.subtext').hide();
	$('.zoomIn a').append('<span>Maximizar</span>');
	
	$('.zoomIn a').each(function(){
		var si = $(this).parent().siblings('img').width();
		$(this).parent().css('width',(si-6));
		$(this).click(function(){
			var imgPath			= $(this).parent().siblings('img').attr('src');
			var imgPathNamePos	= imgPath.lastIndexOf('_')+1;
			var imgAttrPos		= imgPath.lastIndexOf('.');
			var imgPathName		= imgPath.substr(0,imgPathNamePos);
			var imgAttr			= imgPath.substr(imgAttrPos);
			$('.dropShadow').remove();
			if($(this).parent().siblings('img').width()<545) {
				$('.zoomIn a span').html('Minimizar');
				$(this).parent().parent('.imageContainer').animate({width:'545px'});
				$(this).parent().parent('.imageRightContainer').animate({width:'545px'});
				$(this).parent().siblings('img').attr({src: imgPathName+'gross'+imgAttr}).animate({width:'545px'}).parent().children('.zoomIn').animate({width:'99%'}).children('a').children('img').attr({src: 'images/icon_zoomout.gif'});
				$(this).parent().parent().children('.subtext').slideDown('slow');
			} else {
				$('.zoomIn a span').html('Maximizar');
				$(this).parent().parent('.imageContainer').animate({width:(si+20)+'px'});
				$(this).parent().parent('.imageRightContainer').animate({width:(si+20)+'px'});
				$(this).parent().parent().children('.subtext').slideUp();
				$(this).parent().siblings('img').animate({width: si+'px'}).attr({src: imgPathName+'klein'+imgAttr}).parent().children('.zoomIn').animate({width:si+'px'}).children('a').children('img').attr({src:'images/icon_zoomin.gif'});
			}
			setTimeout('loadShadow()',1500);
			setTimeout('setPosition()',500);
			return false;
		});
	});
	
	
	$('<div id="tooltip"><h5>Referencia</h5><p></p></div>')
		// add to document
		.appendTo(document.body)
		// hide it at first
		.hide();
	$('ul.footnotes').hide();

	//substitute footnotes for tooltips
	$('a.footnote').mouseover(function(event){
		//First set infos in Tooltip
		var htmlText = $('a[name='+$(this).attr('href').substr(1)+']').parent().children('span').html();
		$('#tooltip p').html(htmlText);
		
		//display it
		posleft = event.pageX + 5;
		postop = event.pageY + 20;
		$('#tooltip').css({
			left: posleft + 'px',
			top: postop + 'px',
			opacity: 0
		}).show();
		postop = event.pageY + 5;
		$('#tooltip').animate({
			top: postop + 'px',
			opacity: 1
		}, 300);
		
	});
	$('a.footnote').mouseout(function(event){
		$('#tooltip').animate({
			opacity: 0
		}, 300);
	});
	$('a.footnote').click(function(event){
		return false;
	});
});

$('.close').click(function(){
	self.close();
});

// shaddow loading after sIFR is ready
function loadShadow() {
		if($('.shadow').html()!='') $('.shadow').dropShadow({top: 0,left: -1, bottom: 1, right: 1, opacity: 0.3, blur: 2});
		if($('.double').html()!='') $('.double').dropShadow({top: 0,left: -1, bottom: 1, right: 1, opacity: 0.3, blur: 2});
		//$('#main .articlebox').dropShadow({top: 0,left: -1, right: 2, bottom: 2, opacity: 0.2, blur: 1});
		if($('#main .box').html()!='') $('#main .box').dropShadow({top: 0,left: -1, bottom: 2, right: 2, opacity: 0.3, blur: 1});
}

function setPosition() {
	//alert('DEBUG: '+$('#main').height()+' - '+$('#menu ul').height()+' = '+($('#main').height()-$('#menu ul').height()));
	//$('.fontsize').append('<br />DEBUG: '+$('#main').height()+' - '+$('#menu ul').height()+' = '+($('#main').height()-$('#menu ul').height()));
	if(($('#main').height()-60)<($('#menu ul').height()+20)) {
		$('.fontsize').css('top',($('#menu ul').height()+20));
	}else {
		$('.fontsize').css('top',($('#main').height()-60));	
	}
}

//	popup function */
var p;
function popup(url, w, h, posL, posT, options) {	
	var screenW = (screen.availWidth) ? screen.availWidth : 800;
	var screenH = (screen.availHeight) ? screen.availHeight : 600;
	if ((w != null) && (w <= 100)) w = 100;
	if ((w == null) || (w < 100) || (w> screenW)) w = screenW - 100;
	if ((h != null) && (h <= 100)) h = 100;
	if ((h == null) || (h < 100) || (h > screenH-120)) h = screenH - 120;
	if ( (posL == null) || (posL < 0) || (screenW < posL + w) ) posL = (screenW - w) / 2; // mitte des bildschirms
	if ( (posT == null) || (posT < 0) || (screenH < posT + h) ) posT = (screenH - h) / 2 - 20; // mitte des bildschirms
	if (posT < 0) posT = 0;
	if (p && (p.closed != true)) p.close();
	if (!options) options = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
	p = window.open(url, 'popup', options + ',width=' +w+ ',height=' +h+ ',left=' +posL+ ',top=' +posT);
	p.focus();
	return false;
}

function fixFlash() {
	theObjects = $("object");
	for (var i = 0; i < theObjects.length; i++) {
	theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

function hideAdblock() {
	$('a.visible.ontop').attr('class', 'hide');
}
