// JavaScript Document
$(function(){
			$('#slides').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				effect: 'fade',
				crossfade: true,
				fadeSpeed: 1000,
				play: 3500,
				pause: 2500,
				hoverPause: true,
				animationStart: function(){
					$('.caption').animate({
						bottom:0
					},100);
				},
				animationComplete: function(current){
					$('.caption').animate({
						bottom:0
					},200);
					if (window.console && console.log) {
						// example return of current slide number
						console.log(current);
					};
				}
			});
		});
		
				$(function() {
    //find all form with class jqtransform and apply the plugin
    $("form.jqtransform").jqTransform();
});

function initMenu() {
 $('.exptext').hide();
 $('.expheader').click(
	function() {
			$(this).next().slideToggle('normal');
			$(this).toggleClass("open");
			$(this).next().toggleClass("focused");
			}
 		);
 	}
 $(document).ready(function() {initMenu();
										
});

$(document).ready(function() {
			$(".lightbox").fancybox({
				'width'				: '60%',
				'height'			: '85%',
				'autoScale'			: true,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		});
		
$(document).ready(function() {

  // Creating custom :external selector
  $.expr[':'].external = function(obj){
      return !obj.href.match(/^mailto\:/)
			  && !obj.href.match(/^javascript\:/)
              && (obj.hostname != location.hostname)
			  && obj.href;
  };

  // Add 'external' CSS class to all external links
  $('a:external').addClass('external');
  $('.c_login_doccheck a:external').removeClass('external')
  
  $('.external').click(function() {
    var link = $(this).attr('href');
    $('<div>You are now leaving the MSandAction Web site, and are moving to external Web sites independently operated and not managed by the Novartis Pharmaceuticals Corporation. Novartis assumes no responsibility for these sites.<br><br>If you do not wish to leave this site, click Cancel. Click Continue to leave the site.</div>').dialog({
      title: "",
      modal : true,
      overlay: {
        backgroundColor: '#000',
        opacity: 0.5
      },
      buttons: {
        'Continue': function() {
          $(this).dialog('close').remove();
          window.open(link);
        },
        'Cancel': function() {
          $(this).dialog('close').remove();
          return false;
        }
      }
    });

    return false;
  });
});



/*global dotLBInitialize, $, window, txGlossary, alert*/

// TODO: refactor
if (typeof dotLBInitialize === "undefined") {

    var trans = (function () {
        // private
        var tooltip = "<div class='tooltip hidden'><div></div></div>",
            moveInterval = 175,
            questionTimeout,

            getPosition = function (node) {
                var x = 0,
                    y = 0;
                do {
                    x += node.offsetLeft;
                    y += node.offsetTop;
                } while ((node = node.offsetParent));

                return {
                    x: x,
                    y: y
                };
            };

        // public
        return {
            contentNode: $("#content"),

            // TODO: use a plugin
            tooltip: function () {
                var text = $(this).attr("sltitle"),
                    tooltipheight;

                if (questionTimeout) {
                    clearTimeout(questionTimeout);
                }

                if (typeof tooltip === "string") {
                    tooltip = $("div#wrapper").after(tooltip).next();
                    tooltip.mouseover(function () {
                        if (questionTimeout) {
                            clearTimeout(questionTimeout);
                        }
                    }).mouseout(function () {
                        trans.setQuestionTimeout();
                    });
                }

                tooltip.stop(true)
                        .addClass("hidden")
                        .removeAttr("style");

                if (text) {
                    tooltip.children("div").html(text);

                    if ($(this).hasClass("question")) {
                        (function () {
                            var questionNode = $("div.homepage-specials"),
                                position = getPosition(questionNode.get(0));

                            tooltip
                                    .removeClass("tooltip-glossar")
                                    .addClass("tooltip-question")
                                    .css("left", position.x + questionNode.width() /
                                            2 - tooltip.width() / 2 + "px")
                                    .css("top", position.y - tooltip.height() - 10 + "px")
                                    .removeClass("hidden");
                        }());
                    } else if ($(this).hasClass("glossar")) {

                        tooltip
                                .addClass("tooltip-glossar")
                                .removeClass("tooltip-question")
                                .removeClass("tooltip-rudimental");
                        tooltipheight = tooltip.height();
                        $(this).mousemove(function (e) {
                            var x = e.pageX - 20,
                                y = e.pageY + 20,
                                windowwidth = $(window).width(),
                                windowheight = $(window).height();

                            if (windowwidth && windowwidth < x + 320) {
                                x -= 230;
                                tooltip.addClass("tooltip-rudimental");
                            }

                            if (tooltipheight && windowheight &&
                                    windowheight < y + tooltipheight + 50) {
                                y -= tooltipheight + 50;
                                tooltip.addClass("tooltip-rudimental");
                            }

                            tooltip
                                    .css("left", x + "px")
                                    .css("top", y + "px")
                                    .removeClass("hidden");
                        });
                    }
                }
            },

            extooltip: function (tooltipType) {
                if (typeof tooltip !== "string") {
                    tooltip.hide("fast", function () {
                        tooltip.addClass("hidden").removeAttr("style");
                    });
                }
            },

            setQuestionTimeout: function () {
                if (questionTimeout) {
                    clearTimeout(questionTimeout);
                }
                questionTimeout = setTimeout(function () {
                    trans.extooltip("tooltip-question");
                }, 3000);
            },

            loadOverview: function () {
                var overviewUrl = $(this).attr("href");
                if (!$("#content div.overview", trans.contentNode).length) {
                    $("#content", trans.contentNode)
                            .append('<div class="overview hidden"></div>')
                            .find("div.overview")
                            .load(overviewUrl, function () {
                        $(this).children("div.text")
                                .append('<a class="button close"><span>Etappen&uuml;bersicht ' +
                                'schlie&szlig;en</span></a>');
                        trans.toggleOverview();
                    });
                } else {
                    trans.toggleOverview();
                }

                return false;
            },

            toggleOverview: function () {
                $("#content div.overview, #content div.step", trans.contentNode)
                        .slideToggle();
                return false;
            },


            // TODO: refactor this, see http://www.ueberleben-mit-brustkrebs.de/
            renderGlossary: function () { // searchs side for glossary entries
                if (/glossar\.html$/.test(location.pathname) || typeof txGlossary === "undefined" ||
                        !txGlossary) {
                    return;
                }
                var node, text, reqex, newText;

                node = $("#content div.text");
                node = !node.length ? $("#content-left") : node;
                node = !node.length ? $("#content") : node;
                node = !node.length ? $(".teaser-content .teaser .text") : node;

                if (node.length) {
                    node.each(function (n) {
                        text = node.eq(n).html();
                        if (text) {
                            for (var key in txGlossary) {
                                if (txGlossary.hasOwnProperty(key)) {
                                    try {
                                        reqex = new RegExp(["(>[^<]*)(", key, ")"].join(""));
                                        newText = ["$1", '<span class="glossar" sltitle="',
                                                txGlossary[key], '">', "$2", '</span>'].join("");
                                        text = text.replace(reqex, newText);
                                    } catch(error) {
                                    }
                                }
                            }
                            node.eq(n).html(text);
                            //Re-Bind tooltip
                            $("span.glossar, a.question")
                                    .mouseover(trans.tooltip)
                                    .mouseout(trans.extooltip);
                        }
                    });
                }
            },

            placeZoom: function (zoom) {
                zoom = zoom || $("a.thickbox[href$='jpg'], a.thickbox[href$='jpeg'], " +
                        "a.thickbox[href$='gif'], a.thickbox[href$='png']")
                        .append('<div class="zoomwrap"><img src="/_global/images/zoom.png" alt=""' +
                        ' class="zoom" /></div>').find("img.zoom");
                return zoom;
            }
        };
    }());

    $("span.glossar, a.question").mouseover(trans.tooltip);
    $("span.glossar").mouseout(trans.extooltip);
    $("a.question").mouseout(trans.setQuestionTimeout);

    $("#content a.overview", trans.contentNode).live("click", trans.loadOverview);

    $("#content a.close", trans.contentNode).live("click", trans.toggleOverview);

    trans.renderGlossary();

}

$('h1 > span').removeClass('glossar')
$('.secondlevel-select > ul').parent().addClass('withchildren')
$('.secondlevel-last-select > ul').parent().addClass('withchildren')
$(".arrow-link-internal a:empty").parent().addClass('empty')
$(".pdf-link a:empty").parent().addClass('empty')
$("a > .spot").parent().addClass('decor')



