// JavaScript Document
$(document).ready(function ()
{
    $("#header_main").css("height", $(window).height() + "px");
    var cananimate = true;
    var door_col;
    door_col = $("#doorphotogallery .smalldoorone").size();
    var line_col = parseInt((door_col + 2)  / 3);
    $("#doorphotogallery").height(line_col * 100);
    $("#doorphotogallery .smalldoorone img").each(function (k, v)
    {
        if (k) {
            $(this).css("opacity", "0.5");
        }
    });
    $("#bigdoorgallery .bigdoor_one .name").css("display", "none");
    $("#bigdoorgallery .bigdoor_one .door").css("display", "none");
    $("#bigdoorgallery .bigdoor_one .enlarge").css("display", "none");
    $("#bigdoorgallery .bigdoor_one:first .name").css("display", "block");
    $("#bigdoorgallery .bigdoor_one:first .door").css("display", "block");
    $("#bigdoorgallery .bigdoor_one:first .enlarge").css("display", "block");
    var door_col2;
    door_col2 = $("#exclusivegallery .exdoor_one").size();
    $("#exclusivegallery").width(door_col2 * 141);
    /*var WidthStep = 282;*/
    var WidthStep = 141;
    if ($(window).width() >= 1240 ) 
    {
        $("#mainexclusive").width(446);
        $("#mainexclusive .exdoorblock .excloser").width(423);
        $("#exmoveright").css("left", "425px");
        /*WidthStep = 423;*/
    }
    else 
    {
        $("#mainexclusive").width(305);
        $("#mainexclusive .exdoorblock .excloser").width(282);
        $("#exmoveright").css("left", "292px");
        /*WidthStep = 282;*/
    }
    $(window).resize(function ()
    {
        $("#header_main").css("height", $(window).height() + "px");
        if ($(window).width() >= 1240 ) 
        {
            $("#mainexclusive").width(446);
            $("#mainexclusive .exdoorblock .excloser").width(423);
            $("#exmoveright").css("left", "425px");
        }
        else 
        {
            $("#mainexclusive").width(305);
            $("#mainexclusive .exdoorblock .excloser").width(282);
            $("#exmoveright").css("left", "292px");
        }
        $("#exclusivegallery").css("left", "0");
    });
    /*    $("#main_top_menu ul li").hover(        function(){            $(this).find("a").css("color",
    "#bba181");            $(this).find("span").css("color", "#704922");        },        function(){            $(this).find("a").css("color",
    "#704922");            $(this).find("span").css("color", "#bba181");        }    );    */
    $("#exmoveright a").click(function ()
    {
        var Left = parseInt($("#exclusivegallery").css("left").replace("px", ""));
        var ExclusiveWidth = parseInt($("#exclusivegallery").width());
	
	var CloserWidth = $("#mainexclusive .exdoorblock .excloser").width();
	
        if (ExclusiveWidth > (CloserWidth - Left)) 
        {
            if (ExclusiveWidth >= (WidthStep + WidthStep - Left)) 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#exclusivegallery").animate( {
                        "left" : (Left - WidthStep)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
            else 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#exclusivegallery").animate( {
                        "left" : (WidthStep - ExclusiveWidth)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
        }
        return false;
    });
    $("#exmoveleft a").click(function ()
    {
        var Left = parseInt($("#exclusivegallery").css("left").replace("px", ""));
        var ExclusiveWidth = parseInt($("#exclusivegallery").width());
        if (Left < 0) 
        {
            if ((Left + WidthStep) <= 0) 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#exclusivegallery").animate( {
                        "left" : (Left + WidthStep)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
            else 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#exclusivegallery").animate( {
                        "left" : 0
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
        }
        return false;
    });
    $("#galup a").click(function ()
    {
        var Top = parseInt($("#doorphotogallery").css("top").replace("px", ""));
        var GalleryHeight = parseInt($("#doorphotogallery").height());
        if (Top < 0) 
        {
            if ((Top + 100) <= 0) 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#doorphotogallery").animate( {
                        "top" : (Top + 100)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
            else 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#doorphotogallery").animate( {
                        "top" : 0
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
        }
        return false;
    });
    $("#galdown a").click(function ()
    {
        var Top = parseInt($("#doorphotogallery").css("top").replace("px", ""));
        var GalleryHeight = parseInt($("#doorphotogallery").height());
        if (GalleryHeight > (200 - Top)) 
        {
            if ((GalleryHeight) >= (300 - Top)) 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#doorphotogallery").animate( {
                        "top" : (Top - 100)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
            else 
            {
                if (cananimate) 
                {
                    cananimate = false;
                    $("#doorphotogallery").animate( {
                        "top" : (200 - GalleryHeight)
                    },
                    "slow", function ()
                    {
                        cananimate = true;
                    } );
                }
            }
        }
        return false;
    });
    $("#doorphotogallery .smalldoorone a").click(function ()
    {
        if (cananimate) 
        {
            cananimate = false;
            $("#doorphotogallery .smalldoorone img").css("opacity", "0.5");
            $(this).find("img").css("opacity", "1");
            var obj = this;
            $("#bigdoorgallery .bigdoor_one .enlarge").css("display", "none");
            $("#bigdoorgallery .bigdoor_one .name").fadeOut("slow");
            $("#bigdoorgallery .bigdoor_one .door").fadeOut("slow");
            $("#bigdoor" + $(this).attr("rel")).find(".name").fadeIn("slow", function ()
            {
                cananimate = true;
            });
            $("#bigdoor" + $(this).attr("rel")).find(".door").fadeIn("slow", function ()
            {
                cananimate = true;
                $("#bigdoor" + $(obj).attr("rel")).find(".enlarge").css("display", "block");
            });
        }
        return false;
    });
    /*    $("#maingallery .enlarge a").click(function(){        return false;    });*/
    $("#maingallery .enlarge a").lightBox();
});
function fixPNG(element) 
{
    //Если браузер IE версии 5.5-6
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) 
    {
        var src;
        if (element.tagName == 'IMG')
        {
            //Если текущий элемент картинка (тэг IMG)

            {
                if (/\.png$/.test(element.src)) //Если файл картинки имеет расширение PNG

                {
                    src = element.src;
                    element.src = "/bitrix/templates/main/images/blank.gif";
                    //заменяем изображение прозрачным gif-ом
                }
            }
        }
        else
        {
            //иначе, если это не картинка а другой элемент

            {
                //если у элемента задана фоновая картинка, то присваеваем значение свойства background-шmage переменной src
                src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
                if (src) 
                {
                    src = src[1];
                    //берем из значения свойства background-image только адрес картинки
                    element.runtimeStyle.backgroundImage = "none";
                    //убираем фоновое изображение
                }
            }
            //если, src не пуст, то нужно загрузить изображение с помощью фильтра AlphaImageLoader
            if (src)
            {
                element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
            }
        }
    }
}

