﻿$(document).ready(function() {

    $(".navigation").Suckerfish();

    $(".carrousel").each(function() {
        $(this).cycle({
            fx: "fade",
            timeout: 4000,
            autostop: 3
        });

        $(this).find("img:first").hide();
        $(this).find("img:first").fadeIn(1000);
        $(this).css("visibility", "visible");
    });

    $(".slider").each(function() {
        $(this).find("img:first").hide();
        $(this).find("img:first").fadeIn(1000);
        $(this).css("visibility", "visible");
    });

    $("a.fancyzoom").fancybox({
        frameWidth: 605,
        frameHeight: 385,
        padding: 10,
        overlayOpacity: 0.7,
        overlayColor: "#000",
        showCloseButton: false
    });

    $("a.fancylink").fancybox({
        frameWidth: 635,
        frameHeight: 385,
        padding: 2,
        overlayOpacity: 0.7,
        overlayColor: "#000"
    });

    //forms    
    $(".contactform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendContactForm.aspx"
    });

    $(".callmebackform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendCallMeBackForm.aspx"
    });

    $(".moreinfoform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendMoreInfoForm.aspx"
    });

    $(".docmapform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendDocMapForm.aspx"
    });

    $(".applyforofferform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendApplyForOfferForm.aspx"
    });

    $(".makeappointmentform").Ajaxform({
        falsecolor: "#ff2a00",
        enableanalytics: true,
        executionpath: "/ajax/SendMakeAppointmentForm.aspx"
    });

    //visualize and show selected tree
    $(".navigation").each(function() {

        $(this).find(".selected").each(function() {
            if ($(this).parents("ul:first").is(":not(.root)")) {
                $(this).children("ul").each(function() {
                    $(this).children("li").each(function() {
                        $(this).find("a").css("color", "#fff");
                    });
                });
            }

            $(this).parents("li:first").each(function() {
                if ($(this).parents("ul:first").is(":not(.root)")) {
                    $(this).children("ul").each(function() {
                        $(this).children("li").each(function() {
                            $(this).find("a").css("color", "#fff");
                        });
                    });
                }
            });

            $(this).parents("li").each(function() {
                $(this).children("a").css("color", "#fff");
                $(this).children("ul").each(function() {
                    $(this).show();
                });
            });

            $(this).children("ul").show();
        });
    });

    //cycle plugin call
    var amountofslides = $(".slider").find("a").length;

    $(".slider").cycle({
        fx: "fade",
        timeout: 6000,
        autostop: amountofslides,
        pauseOnPagerHover: true,
        pagerEvent: "click",
        pager: ".slidenav",
        pagerAnchorBuilder: function(idx, slide) {
            return ".slidenav li:eq(" + idx + ") a";
        }
    });

    $(".navwrapper").WallszSlider({
        suffix: ""
    });

    function ActivateLinkedImages(parent) {
        $(parent).find("img").each(function() {
            var image = $(this).attr("rel");
            $(this).attr({
                src: image
            });
        });
    }

    //product details
    $(".detaillink").click(function() {

        //ActivateLinkedImages(".slider-linked");

        $(".backlink").fadeIn(300);
        $(".detaillink").hide();
        $(".techspec").hide();
        $(".slider-linked").fadeIn(300);
        $(".navwrapper-linked").fadeIn(300);

        $(".slider").hide();
        $(".navwrapper").hide();

        $(".pagetext").hide();
        $(".textcontent h2").hide();

        if ($("input[name=initslideshow]").val() == "true") {

            //cycle plugin call
            var amountofslides = $(".slider-linked").find("a").length;

            $(".slider-linked").cycle({
                fx: "fade",
                timeout: 6000,
                autostop: amountofslides,
                pauseOnPagerHover: true,
                pagerEvent: "click",
                pager: ".slidenav-linked",
                pagerAnchorBuilder: function(idx, slide) {
                    return ".slidenav-linked li:eq(" + idx + ") a";
                }
            });

            $(".navwrapper-linked").WallszSlider({
                suffix: "-linked"
            });
        }

        $("input[name=initslideshow]").each(function() {
            $(this).val("false");
        });

        // Magnifier
        $(".magnifier").addClass("magnifier-linked");
        $(".magnifier").removeClass("magnifier");

        var link = $(".slidenav-linked").find("a.activeSlide").find("img").attr("src");
        link = link.replace("/_thumb", "");

        $(".magnifier-linked").each(function() {
            $(this).find("a").each(function() {
                $(this).attr({
                    href: link
                });
            });
        });
    });

    $(".backlink").live("click", function() {
        $(".backlink").hide();
        $(".detaillink").fadeIn(300);
        $(".techspec").fadeIn(300);
        $(".slider").fadeIn(300);
        $(".navwrapper").fadeIn(300);

        // Magnifier
        $(".magnifier-linked").addClass("magnifier");
        $(".magnifier-linked").removeClass("magnifier-linked");

        var link = $(".slidenav").find("a.activeSlide").find("img").attr("src");
        link = link.replace("/_thumb", "");

        $(".magnifier").each(function() {
            $(this).find("a").each(function() {
                $(this).attr({
                    href: link
                });
            });
        });

        $(".slider-linked").hide();
        $(".navwrapper-linked").hide();

        $(".pagetext").fadeIn(300);
        $(".textcontent h2").fadeIn(300);
    });

    $(".rightfloat").each(function() {
        if ($.browser.msie) {
            if ($.browser.version == "7.0") {
                $(this).css("margin-top", "-142px");
                $(this).find(".input").css("height", "83px");
            }
        }
    });

    // Tagcloud
    $(".tagcloud").each(function() {
        var amountofelements = $(this).find("a").size();

        $(this).find("a:lt(" + (amountofelements - 1) + ")").each(function() {
            $(this).html($(this).html() + ", ");
        });
    });

});
