﻿var ie6 = isIE6();
var ie7 = isIE7();
var ie8 = isIE8();
var saf = isSafariChrome();
$(document).ready(function(){ 
    Cufon.replace('.header .inner .menu a, .footer .inner a, .navi td a', { fontFamily: 'ITCAvantGardePro', hover: true, hoverables: {a:true} });
    Cufon.replace('.footer .inner span', { fontFamily: 'ITCAvantGardePro' });
    if (saf) $(".inner").css("margin-left", "-494px");
    $("#start .inner .preview").hover(function(){
        $(this).find("em").each(function(){
            $(this).animate({opacity: 0});
        });
    }, function(){
        $(this).find("em").each(function(){
            /* fixes 17.05.2010 - changed from 0.7 to 0.5 */
            $(this).animate({opacity: 0.35});
        });
    });
    $("#prev1").hover(function(){overImg("l2");}, function(){outImg("l2");});
    $("#prev2").hover(function(){overImg("l3");}, function(){outImg("l3");});
    $("#prev3").hover(function(){overImg("l5");}, function(){outImg("l5");});
    $("#prev4").hover(function(){overImg("l6");}, function(){outImg("l6");});
    $("#prev5").hover(function(){overImg("l9");}, function(){outImg("l9");});
    $("#prev6").hover(function(){overImg("l2");}, function(){outImg("l2");});
    $("#prev7").hover(function(){overImg("l4");}, function(){outImg("l4");});
    $("#prev8").hover(function(){overImg("l5");}, function(){outImg("l5");});
    $("#prev9").hover(function(){overImg("l7");}, function(){outImg("l7");});
    $("#prev10").hover(function(){overImg("l8");}, function(){outImg("l8");});
    $(".back").hover(function(){
        $(".back-bg").animate({opacity: 0.9});
    }, function(){
        $(".back-bg").animate({opacity: 0});
    });
    $(".navi td.c").hover(function(){
        $(this).addClass("hover");
        Cufon.replace($(this).find("a"), { fontFamily: 'ITCAvantGardePro', color: "#ffffff"});
    }, function(){
        $(this).removeClass("hover");
        cc = $(this).attr("class");
        if (cc.indexOf("active") == -1) {
            Cufon.replace($(this).find("a"), { fontFamily: 'ITCAvantGardePro', color: "#000000"});
        }
    });
    Cufon.replace($(".navi td.active a"), { fontFamily: 'ITCAvantGardePro', color: "#ffffff"});
    setTimeout("moza()", 1000);
});

var transparentImage = "img/none.gif";
function fixTrans(){if (typeof document.body.style.maxHeight == 'undefined') {var imgs = document.getElementsByTagName("img");for (i = 0; i < imgs.length; i++){if (imgs[i].src.indexOf(transparentImage) != -1){return;}if (imgs[i].src.indexOf(".png") != -1){var src = imgs[i].src;imgs[i].src = transparentImage;imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";imgs[i].style.display = "inline-block";}}}}
if (document.all && !window.opera) attachEvent("onload", fixTrans);

function isIE6() {
   if (navigator.userAgent.toString().indexOf("MSIE 6.0") != -1) return true;
   return false;
}
function isIE7() {
   if (navigator.userAgent.toString().indexOf("MSIE 7.0") != -1) return true;
   return false;
}
function isIE8() {
   if (navigator.userAgent.toString().indexOf("MSIE 8.0") != -1) return true;
   return false;
}
function isSafariChrome() {
   if (navigator.userAgent.toString().indexOf("Safari") != -1 || navigator.userAgent.toString().indexOf("Chrome") != -1) return true;
   return false;
}

function moza() {
    $(".navi td.c a").animate({opacity: 1}, 1500);
}

/* Function for the setting of slider on text pages
 * 1=slide in after pageload
 * 2=show as default, no slide
 * 3=user must click on the tab to make the textbox slide in
 */
function setBehaviorForTextSlider(key) {
    if (key != 1 && key != 2 && key != 3 && key != 4) key = 1;
    var ml = "692px";
    if (ie7 && document.getElementById("det-inner")) ml = "693px";
    if (ie6 && document.getElementById("det-inner")) ml = "694px";
    switch(key) {
        case 1:
            $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
            $(".text-panel .tab").parent().animate({marginLeft: ml}, function(){
                $(this).find(".arrow").each(function(){$(this).animate({opacity: 0});});
                $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 1});});
            });
            /* fixes 17.05.2010 - for view/hide text panel */
            $(".text-panel .tab").click(function(){
                var _this = this;
                $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 0});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 1});});
                });
            });
            $(".text-panel .text-arrow").click(function(){
                var _this = this;
                var ml = "958px";
                if (ie8 || (ie6 && document.getElementById("det-inner"))) var ml = "959px";
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 1});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 0});});
                    ww = "31"; 
                    if (ie8) ww = "29"; 
                    if (ie7||ie6) ww = "32";
                    $(".text-panel").css("clip", "rect(0px, " + ww + "px, 394px, 0px)");
                });
            });
            /* fixes 17.05.2010 - for view/hide text panel */
            break;
        case 2:
            $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
            $(".text-panel .tab").parent().css("margin-left", ml);
            $(".text-panel .tab").find(".arrow").each(function(){$(this).css("opacity", 0);});
            $(".text-panel .tab").parent().find(".text-arrow .arrow").each(function(){$(this).css("opacity", 1);});
            break;
        case 3:
            $(".text-panel .tab").click(function(){
                var _this = this;
                $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 0});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 1});});
                });
            });
            $(".text-panel .text-arrow").click(function(){
                var _this = this;
                var ml = "958px";
                if (ie8 || (ie6 && document.getElementById("det-inner"))) var ml = "959px";
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 1});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 0});});
                    ww = "31"; 
                    if (ie8) ww = "29"; 
                    if (ie7||ie6) ww = "32";
                    $(".text-panel").css("clip", "rect(0px, " + ww + "px, 394px, 0px)");
                });
            });
            break;
        case 4:
            ml = "494px";
            var tw_tb = "417px";
            if (ie7 && document.getElementById("det-inner")) {ml = "495px"; tw_tb = "416px";}
            if (ie6 && document.getElementById("det-inner")) {ml = "496px"; tw_tb = "415px";}
            $(".text-panel .textbox").css("width", tw_tb);
            $(".text-panel").css("width", "494px");
            $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
            $(".text-panel .tab").parent().animate({marginLeft: ml}, function(){
                $(this).find(".arrow").each(function(){$(this).animate({opacity: 0});});
                $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 1});});
            });
            /* fixes 17.05.2010 - for view/hide text panel */
            $(".text-panel .tab").click(function(){
                var _this = this;
                $(".text-panel").css("clip", "rect(auto, auto, auto, auto)");
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 0});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 1});});
                });
            });
            $(".text-panel .text-arrow").click(function(){
                var _this = this;
                var ml = "958px";
                if (ie8 || (ie6 && document.getElementById("det-inner"))) var ml = "959px";
                $(this).parent().animate({marginLeft: ml}, function(){
                    $(this).find(".arrow").each(function(){$(this).animate({opacity: 1});});
                    $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 0});});
                    ww = "31"; 
                    if (ie8) ww = "29"; 
                    if (ie7||ie6) ww = "32";
                    $(".text-panel").css("clip", "rect(0px, " + ww + "px, 394px, 0px)");
                });
            });
            /* fixes 17.05.2010 - for view/hide text panel */
            break;
    }
}

/* 
 * Showing of content from content_id, id - 1, 2, 3, ...
 * id - index of the current link, content may be into hidden div with id="content_1",
 * or from server with AJAX
 * mode - 0 - content from div, 1 - content from AJAX 
 * obj - link to clicked object
 */
function setContentIntoPopup(id, mode, obj) {
    if (mode!=0 && mode!=1) return false;
    if (!id) id = 0;
    if (mode == 0) {
        if (document.getElementById("popup_1_content") == null) return false;
        if (document.getElementById("content_" + id) == null) return false;
        tmp = $("#content_" + id).html();
        $("#popup_1_content").html("");
        $(".navi td.c").removeClass("active");
        Cufon.replace($(".navi td.c a"), { fontFamily: 'ITCAvantGardePro', color: "#000000"});
        ShowDivAsPopup("popup_1");
        $(".popup .scrolling").addClass("loading");
        $(obj).addClass("active");
        Cufon.replace($(obj).find("a"), { fontFamily: 'ITCAvantGardePro', color: "#ffffff"});
        setTimeout('$("#popup_1_content").html(tmp);', 500);
        setTimeout('$(".popup .scrolling").removeClass("loading"); imgCap();', 500);
    } else if (mode == 1) {
        $("#popup_1_content").html("");
        $(".navi td.c").removeClass("active");
        Cufon.replace($(".navi td.c a"), { fontFamily: 'ITCAvantGardePro', color: "#000000"});
        Cufon.replace($(obj).find("a"), { fontFamily: 'ITCAvantGardePro', color: "#ffffff"});
        $(obj).addClass("active");
        ShowDivAsPopup("popup_1");
        try {
            $.ajax({
                url: 'index.php', // URL file on the server with code for creating answer to request
                dataType : "json", // format for answer - JSON ({'data': '<img src="img/popup/1.jpg" alt="" />'})
                success: function (data, textStatus) { 
                    res = eval("(" + data + ")");
                    if (data.data) {
                        $("#popup_1_content").html(data.data);   
                    }
                },
                error: function() {
                    alert('AJAX error!');
                }
            });
        } catch(e) {
            alert("AJAX/JSON error!");
        }
    }
}
/* fixes 17.05.2010 - for disappiering text panel */
function hideSlide() {
    var _this = $(".text-panel .text-arrow");
    var ml = "958px";
    if (ie8 || (ie6 && document.getElementById("det-inner"))) var ml = "959px";
    $(_this).parent().animate({marginLeft: ml}, function(){
        $(this).find(".arrow").each(function(){$(this).animate({opacity: 1});});
        $(this).parent().find(".text-arrow .arrow").each(function(){$(this).animate({opacity: 0});});
        ww = "31"; 
        if (ie8) ww = "29"; 
        if (ie7||ie6) ww = "32";
        $(".text-panel").css("clip", "rect(0px, " + ww + "px, 394px, 0px)");
    });
}

function imgCap() { 
       $("#popup_1_content img").each(function(){
            ww = $(this).width();
            bw = $("#popup_1_content").width();
            if (ww > bw) bw = ww;
            cs = $(this).next().next().attr("class");
            if (cs == "caption") {
                delt = Math.abs((parseInt(bw) - parseInt(ww))/2);
                if (ie6) {
                    delt = Math.floor(delt/2);
                }
                $(this).next().next().css("margin-left", delt + "px");    
            }
        });
}
function overImg(link) {
    if (!document.getElementById(link)) return false;
    Cufon.replace($("#" + link), { fontFamily: 'ITCAvantGardePro', hover: true, hoverables: {a:true}, color: '#ffffff' });  
}
function outImg(link) {
    if (!document.getElementById(link)) return false;
    Cufon.replace($("#" + link), { fontFamily: 'ITCAvantGardePro', hover: true, hoverables: {a:true}, color: '#2E6362' });    
}
