﻿/*
*
* Copyright 2011, smartpoint IT consulting
*/


$(document).ready(function () {


    //browser switch
    var browser = navigator.appName;
    if (navigator.userAgent.indexOf('MSIE') > -1) {
        $("body").addClass("ie");
    }
    else if (navigator.userAgent.indexOf('Firefox') > -1) {
        $("body").addClass("firefox");
    }
    else if (navigator.userAgent.indexOf('Chrome') > -1) {
        $("body").addClass("chrome");
    }
    else if (navigator.userAgent.indexOf('Safari') > -1) {
        $("body").addClass("safari");
    }
	
	//correct height of homepage boxes
    var height = 0;
    $('#home #main .s4-wpTopTable').each(function () {
        if ($(this).height() > height) {
            height = $(this).height();
        }
    });
    $('#home #main .s4-wpTopTable').height(height + 12);

    if ($("#home #banner").length > 0) {
        $("#home #banner").smpSlider();
    }

    //activate first element of services banner
    $("#content .Banner .overlay").hide();
    $("#content .Banner .overlay").first().show();
    $("#content .Banner .overlay").first().addClass("active");

    //add animation for services banner
    $("#content map area").hover(function () {
        var link = $(this).attr("title");
        //link = link.substring(link.indexOf("#"), link.length).replace("#", "");
        if ($("#content .Banner .overlay.active").hasClass(link) == false) {
            $("#content map area").removeClass("active");
            $(this).addClass("active");
            $("#content .Banner .overlay").stop(true, false);

            $("#content .Banner .overlay").filter(":visible").fadeOut(600, "linear", function () {
                $("#content .Banner .overlay").css("opacity", "100");
                $("#content .Banner .overlay.active").removeClass("active");
                $("#content .Banner .overlay." + link).fadeIn(600, "linear", function () {
                    $("#content .Banner .overlay." + link).addClass("active");
                });
            });
        }
    });


    // activate lightbox for image gallery
    if ($('.gallery .gallery-items a').length > 0) {
        $('.gallery .gallery-items a').lightBox();
    }

    // activate toggle feature
    $(".toggle-item").each(function () {
        var button = $(this).children("a.toggle");
        var content = $(this).children(".toggle-content");
        $(content).hide();
        $(button).click(function () {
            if ($(content).filter(":visible").length > 0) {
                $(".toggle-item").children("a.toggle").removeClass("active");
                $(".toggle-item").children(".toggle-content").filter(":visible").slideToggle("slow");
            }
            else {
                $(".toggle-item").children("a.toggle").removeClass("active");
                $(".toggle-item").children(".toggle-content").filter(":visible").slideToggle("slow");
                $(button).addClass("active");
                $(content).slideToggle("slow");
            }
        });
    });



    $(".premises-item").each(function () {
        $(this).find("a.maplink").click(function () {
            var mapLink = $(this).parent().find(".mapsLink").attr("href");
            var largeMapLink = $(this).parent().find(".largeMapLink").attr("href");
            var directionLink = $(this).parent().find(".directionLink").attr("href");

            $("#WebPartWPQ2 iframe").attr("src", mapLink);
            $("#WebPartWPQ2 iframe").height($("#WebPartWPQ2 iframe").height());
            if ($("#WebPartWPQ2 .links").size() == 0) {
                $("#WebPartWPQ2").height($("#WebPartWPQ2").height() + 20);
            }
            else {
                $("#WebPartWPQ2 .links").remove();
            }
            $("#WebPartWPQ2").append($('<div class="links"></div>'));
            $("#WebPartWPQ2 .links").append('<a href="' + largeMapLink + '" target="_blank" >Karte anzeigen</a>');
            $("#WebPartWPQ2 .links").append('<a href="' + directionLink + '" target="_blank" >Routenplaner</a>');
        });
    });

    $(".premises-item a.maplink").first().click();



    $(".registrationForm input[type!='submit']").focus(function () {
        var value = $(this).val();
        $(this).blur(function () {
            if ($(this).val() == "") {
                $(this).val(value);
            }
        });
        $(this).val("");
    });

    $(".s4-search img.srch-gosearchimg").attr("src", "/images/search.png");
    $(".s4-search img.srch-gosearchimg").attr("onmouseover", "");
    $(".s4-search img.srch-gosearchimg").attr("onmouseout", "");


    if ($("#content .c50l .s4-wpTopTable .ms-WPBody").length == 1 && $("#content .c50r .s4-wpTopTable .ms-WPBody").length == 1) {
        var l = $("#content .c50l .s4-wpTopTable .ms-WPBody");
        var r = $("#content .c50r .s4-wpTopTable .ms-WPBody");

        if (l.height() > r.height()) {
            r.height(l.height());
        }
        else {
            l.height(r.height());
        }
    }
});



