﻿// JavaScript Document
/// <reference path="jquery-1.4.1-vsdoc.js" />


(function () {
    $.fn.infiniteCarousel = function () {
        function repeat(str, n) {
            //try {
            return new Array(n + 1).join(str);
            //} catch (err) {
            //return new Array(1).join(str);
            //}
        }        

        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first'),

                singleWidth = $single.outerWidth(),
                visible = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = $items.length;
                //pages = Math.ceil($items.length / visible);

                var timer;

            
            /// This is old code fore View description
            //$wrapper.after('<span class="FotoHint"></span>');
            //var $informer = $('> span', this)

            //$($informer).html($single.find('> a').attr('title'));

            /* TASKS */

            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }

            //for shadowbox :)            
            var testRel = $items.children('a').attr('rel');
            var tesrRel1 = testRel.replace('gallery', 'gallery1');
            var tesrRel2 = testRel.replace('gallery', 'gallery2');

            // 2. create the carousel padding on left and right (cloned)
            var itemsBefor = $items.slice(-visible).clone().addClass('cloned');
            var itemsAfter = $items.slice(0, visible).clone().addClass('cloned');

            itemsBefor.children('a').attr('rel',tesrRel1);
            itemsAfter.children('a').attr('rel',tesrRel2);
            $items.filter(':first').before(itemsBefor);
            $items.filter(':last').after(itemsAfter);
            $items = $slider.find('> li');

            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);            

            // 4. paging function
            /*//This move to all line
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * visible * n;

                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft: '+=' + left
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                    }

                    //$informer.html($items.filter(":not(.cloned):eq(" + (page - 1) + ")").children().attr('title'));

                    currentPage = page;
                });
            }*/

            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * 1 * n;

                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft: '+=' + left
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == -4) {
                        page = pages - 4;
                        $wrapper.scrollLeft(singleWidth * pages);
                    }

                    //$informer.html($items.filter(":not(.cloned):eq(" + (page - 1) + ")").children().attr('title'));

                    currentPage = page;
                });
            }

            function SetTimer () {
                timer = setTimeout(function () {
                                    gotoPage(currentPage + 1);
                                    SetTimer ();
                                    return false;
                                    },3000);
                return false;               
            }

            function StopTimer() {
                clearTimeout(timer);
                return false;
            }

            SetTimer();

            // 5. insert the back and forward link
            $wrapper.after('<a href="#" class="arrow back"></a><a href="#" class="arrow forward"></a>');

            // 6. bind the back and forward links
            $('a.back', this).click(function () {
                gotoPage(currentPage - 1);
                return false;
            });

            $('a.forward', this).click(function () {
                gotoPage(currentPage + 1);
                return false;
            });

            $('a.back', this).mouseover(function () {
                StopTimer();
                return false;
            });

            $('a.forward', this).mouseover(function () {
                StopTimer();
                return false;
            });

            $('a.back', this).mouseleave(function () {
                SetTimer();
                return false;
            });

            $('a.forward', this).mouseleave(function () {
                SetTimer();
                return false;
            });

            $wrapper.mouseover(function () {
                StopTimer();
                return false;
            });

            $wrapper.mouseleave(function () {
                SetTimer();
                return false;
            });

            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });

            // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);


﻿/// <reference path="jquery-1.4.1-vsdoc.js" />


function HeaderSlider(Element) {
    if (Element == undefined)
        return false;

    Element = $(Element);

    var AElements = Element.find('.picNode');
    var mainHeight = 0;
    for ( var i = 0; i < AElements.length; i++) {
		if ($(AElements[i]).height() > mainHeight) mainHeight = $(AElements[i]).height(); 
	}
    
    Element.height(mainHeight);

    /*var divPictures = $(document.createElement('div'));

    AElements.clone().appendTo(divPictures);

    Element.children().detach();
    Element.append(AElements);*/    

    AElements.each(function (Index, ElementThis) {
        $(ElementThis).css('position', 'absolute');
        $(ElementThis).css('top', '0');
        $(ElementThis).css('left', '0');
        $(ElementThis).attr('enumber', (Index + 1));
        $(ElementThis).attr('show', 'none');
        $(ElementThis).fadeOut(0);
    });

    AElements.first().attr('show', 'yes'); ;
    AElements.first().fadeIn(0);
    //Element.height(AElements.first().height());

    function StartSwitch() {
        var ShowElement = AElements.filter('.picNode[show="yes"]');
        var indexThis = parseInt(ShowElement.attr('enumber'));
        if (indexThis == AElements.length) indexThis = 1; else indexThis++;
        var hideElement = AElements.filter('.picNode[enumber="' + indexThis + '"]');

        ShowElement.attr('show', 'none');
        hideElement.attr('show', 'yes');       
        
        Element.height(hideElement.height());
        hideElement.fadeIn(3000);
        ShowElement.fadeOut(3000);        
    }

    this.repeatGo = function () {
        stopthis = false;
        GoStep1();
    }

    this.stop = function () {
        stopthis = true;
        clearTimeout(animation);
    }

    var stopthis = false;
    var animation;

    function GoStep1() {
        if (!stopthis) {
            animation = setTimeout(function () { StartSwitch(); GoStep1(); }, 9000);
        }
    }

}

function FixMailToLinks() {
    $('a').each(function (Index, Element) {
        //try {
        if (Element.href.indexOf('mailto:') != -1) {
            var temp = Element.href;
            Element.href = temp.substr(temp.indexOf('mailto:'), temp.length - temp.indexOf('mailto:'));
            //$(Element).attr('href', temp.substr(temp.indexOf('mailto:'), temp.length - temp.indexOf('mailto:')));
        }
        //} catch (err) {
        //}
    });
}

$(document).ready(function () {
    Shadowbox.init({
    // skip the automatic setup again, we do this later manually
    //skipSetup: true
    });

    if ($('#RightMainBanner>.mannybannersontop').length == 0) {
        $('#RightMainBanner').children('.picNode').css('display','block');
    	$('#RightMainBanner').height($('#RightMainBanner').children('.picNode').first().height());
	}

    if ($('#ThemeBanner>.mannybannersontop').length == 0) {
        $('#ThemeBanner').children('.picNode').css('display','block');
    	$('#ThemeBanner').height($('#ThemeBanner').children('.picNode').first().height());
	}
    
    if ($('#RightMainBanner>.mannybannersontop').length > 0) {        
    	var HeaderBanner = new HeaderSlider($('#RightMainBanner'));
    	HeaderBanner.repeatGo();
	}
    
	if ($('#ThemeBanner>.mannybannersontop').length > 0) {
		var HeaderBanner = new HeaderSlider($('#ThemeBanner'));
		HeaderBanner.repeatGo();
	}				



    var menunodes = $('.LeftMenu').find('ul.current');
    var menunod = menunodes.last();

    $('#BannerMenuThis').children('li').first().children('a').html(menunod.parent().children('a').html());
    menunod.clone().appendTo($('#BannerMenuThis').children('li').first());



$(function(){

    $(".dropdown > li").click(function() {
    
         var $container = $(this),
             $list = $container.find("ul"),
             $anchor = $container.find("a"),
             height = $list.height() * 1.1,       // Снизу должно быть достаточно места
             multiplier = height / maxHeight;     // Для ускорения перемещения, если список очень длинный
        
        // Сохраняем оригинальное значение высоты контейнера, чтобы восстановить его 
        $container.data("origHeight", $container.height());
        
        $anchor.addClass("hover");
        
        // Выпадающее меню появляется точно под соответствующим пунктом родительского списка
        $list
            .show()
            .css({
                paddingTop: $container.data("origHeight")
            });
        
        // Не делаем никаких анимаций, если список короче максимального значения
        if (multiplier > 1) {
            $container
                .css({
                    height: maxHeight,
                    overflow: "hidden"
                })
                .mousemove(function(e) {
                    var offset = $container.offset();
                    var relativeY = ((e.pageY - offset.top) * multiplier) - ($container.data("origHeight") * multiplier);
                    if (relativeY > $container.data("origHeight")) {
                        $list.css("top", -relativeY + $container.data("origHeight"));
                    };
                });
        }
        
    }/*, function() {
        
        var $el = $(this);
        
        // Устанавливаем оригинальные настройки
        $el
            .height($(this).data("origHeight"))
            .find("ul")
            .css({ top: 0 })
            .hide()
            .end()
            .find("a")
            .removeClass("hover");
    
    }*/);
    
    // Добавляем стрелку вниз только к пунктам с подпунктами
    $(".dropdown > li:has('ul')").each(function() {
        $(this).find("a:first").prepend("<img src='/images/oxus/LeftMenuPD.png' />");
    });
    
    
});
$(".dropdown > li").click();
});
