﻿function fancyIframe(element, width, height){
    $(document).ready(function() { 
        $(element).fancybox({ 
            'zoomSpeedIn': 100, 
            'zoomSpeedOut': 100, 
            'overlayShow': true,
            'overlayOpacity' : 0.5, 
            'frameWidth' : width,
            'frameHeight' : height,
            'hideOnContentClick': true 
            });
    });
}

// Bilder in Fancybox öffnen -> container = umgebender Frames
function fancyImages(container) {
    $(document).ready(function() {
        $(container + " a").fancybox({
            'zoomSpeedIn': 100,
            'zoomSpeedOut': 100,
            'overlayShow': true,
            'overlayOpacity': 0.5,
            'hideOnContentClick': true
        });
    });
}


function loadImage(id) {
    // The code for the image to load
    if ($(".yellowBorder img:eq(" + id + "):visible").length == 0) {
        $(".yellowBorder img").fadeOut(500);
        $(".yellowBorder img:eq(" + id + ")").fadeIn(500);
    }
}


$(document).ready(function() {
    // Bild dyn. nachladen und anschließend Funktion ausführen
//    $.fn.image = function(src, f) {
//        return this.each(function() {
//            var i = new Image();
//            i.src = src;
//            i.style.display = "none";
//            i.width = $(".yellowBorder img:last-child").width();
//            this.appendChild(i);
//            i.onload = f;
//        });
//    }



    // Navigation
    $('ul.sf-menu li a')
    .not('ul.sf-menu li.active a')
    .not('ul.sf-menu li.active ul li')
    .not('ul.sf-menu li.noChilds')
    .click(
        function () {
            $('ul.sf-menu ul').hide();
            $(this).find("ul:first").show();
        },
        function () {
            $('ul.sf-menu li.active ul').show();
            $(this).find("ul:first").hide();
        });

    // navigation hover/color effekt
    $('.sf-menu li a, .spnSiteBy a').not(".sf-menu li a.active").hover(function () {
        $(this).css({ color: '#fff' }, 300);
    }, function () {
        $(this).animate({ color: '#5e5e5e' }, 300)
    });
    $('.sf-menu li a.active').hover(function () {
        $(this).css({ color: '#fff' }, 400);
    }, function () {
        $(this).animate({ color: '#f7c627' }, 400)
    });



    // Hover Thumbs
    $(".thumbs a").hover(
      function() {
          $(this).fadeTo("fast", 1.0);
      },
      function() {
          if ($(this).attr("class") == "") {
              $(this).fadeTo("fast", 0.4);
          }
      }
    );

    // Thumb Active
    $(".thumbs a").click(function() {
        $(".thumbs a").removeClass("active");
        $(".thumbs a").not(this).fadeTo("fast", 0.4);
        $(this).addClass("active");
        $(this).fadeTo("fast", 1.0);
    });

    // Elemente skalieren
    fitElements()

});

$(window).load(function() {
    fitElements();
});

$(window).resize(function() {
    fitElements();
});

// Alle Elemente skalieren und neue Werte in Cookie speichern.
function fitElements() {
    var options = { path: '/', expires: 10 };
    
    // Muss skaliert werden?
    if ($(window).width() < 1250 && $(window).width() > 960) {
        // Skalierungsfaktor     
        var faktor = 900 / ($(window).width() - 330);

        $("#rightpart, .yellowBorder, .yellowBorder img").width(Math.round(900 / faktor) + "px");
        $(".yellowBorder, .yellowBorder img").height(Math.round(440 / faktor) + "px");
        $(".yellowBorder.small").height(Math.round(150 / faktor) + "px");
        $(".twoOfThree, .threeOfThree").width(Math.round(240 / faktor) + "px");
        $(".oneOfThree").width(Math.round(210 / faktor) + "px");
        $(".thumbs img").width(Math.round(91 / faktor) + "px");
        $(".thumbs img").height(Math.round(61 / faktor) + "px");
        $(".thumbs").css("top", Math.round(425 / faktor) - $(".thumbs img:first").height() + 135 + "px")
        $(".oneOfTwo, .twoOfTwo").width(Math.round(360 / faktor) + "px");
        $(".oneTwo").width(Math.round(240 / faktor) + "px");
        $(".twoTwo").width(Math.round(515 / faktor) + "px");
        $("#masterframe").width(($(window).width() - 60) + "px");
        
        $.cookie("#rightpart", "width:" + Math.round(900 / faktor) + "px;", options);
        $.cookie(".yellowBorder", "width:" + Math.round(900 / faktor) + "px;height:" + Math.round(440 / faktor) + "px;", options);
        $.cookie(".yellowBorder_img", "width:" + Math.round(900 / faktor) + "px;height:" + Math.round(440 / faktor) + "px;", options);
        $.cookie(".yellowBorder.small", "width:" + Math.round(900 / faktor) + "px;height:" + Math.round(150 / faktor) + "px;", options);
        $.cookie(".oneOfThree", "width:" + Math.round(210 / faktor) + "px;", options);
        $.cookie(".twoOfThree", "width:" + Math.round(240 / faktor) + "px;", options);
        $.cookie(".threeOfThree", "width:" + Math.round(240 / faktor) + "px;", options);
        $.cookie(".thumbs_img", "width:" + Math.round(240 / faktor) + "px;", options);
        $.cookie(".thumbs", "top:" + Math.round(425 / faktor) - $(".thumbs img:first").height() + 135 + "px;", options);
        $.cookie(".oneOfTwo", "width:" + Math.round(360 / faktor) + "px;", options);
        $.cookie(".twoOfTwo", "width:" + Math.round(360 / faktor) + "px;", options);
        $.cookie(".oneTwo", "width:" + Math.round(240 / faktor) + "px;", options);
        $.cookie(".twoTwo", "width:" + Math.round(515 / faktor) + "px;", options);
        $.cookie("#masterframe", "width:" + ($(window).width() - 30) + "px;", options);
        
    }
    
    if ($(window).width() >= 1250) {
        $("#rightpart, .yellowBorder, .yellowBorder img").width("900px");
        $(".yellowBorder, .yellowBorder img").height("440px");
        $(".yellowBorder.small").height("150px");
        $(".twoOfThree, .threeOfThree").width("240px");
        $(".oneOfThree").width("210px");
        $(".thumbs").css("top", "470px")
        $(".thumbs img").width("91px");
        $(".thumbs img").height("61px");
        $(".oneOfTwo, .twoOfTwo").width("360px");
        $(".oneTwo").width("240px");
        $(".twoTwo").width("515px");
        $("#masterframe").width("1170px");

        $.cookie("#rightpart", null, options);
        $.cookie(".yellowBorder", null, options);
        $.cookie(".yellowBorder_img", null, options);
        $.cookie(".yellowBorder.small", null, options);
        $.cookie(".oneOfThree", null, options);
        $.cookie(".twoOfThree", null, options);
        $.cookie(".threeOfThree", null, options);
        $.cookie(".thumbs", null, options);
        $.cookie(".thumbs_img", null, options);
        $.cookie(".oneOfTwo", null, options);
        $.cookie(".twoOfTwo", null, options);
        $.cookie(".oneTwo", null, options);
        $.cookie(".twoTwo", null, options);
        $.cookie("#masterframe", null, options);
    }
}


/* Effekte Updatepanel */

function showAfterLoad() {
    $(document).ready(function () {
        $('.hideOnLoad').fadeIn(500);
    });
}

function hideBeforeLoad() {
    $(document).ready(function () {
        $('.hideOnLoad').fadeOut(100);
    });
}
