var AICMedia = {

	isEncodeURL: false,
    count: 0,
    indexHash: 'hello/index.php',
    mini: false,
    isSubmit: false,
    ie8: false,

    initialize: function() {
        if ($.browser.msie) {
            $('html').addClass('ie ie' + parseInt($.browser.version));
        }

		if ($.browser.msie && $.browser.version < 9) {
            if ($.browser.version == 8) {
                $('html').addClass('ie8');
                AICMedia.ie8 = true;
            } else {
		        //location.replace("http://old.aic.ru/");
		        $('html').addClass('old-browsers');
            }
        }

		this.readWindowDimenstion();

        if (AICMedia.frame.height < 880) {
            this.mini = true;
            $('body .b-container').addClass('mini-version');
        }

		this.Backdrop.initialize();
		this.TransparentBackdrop.initialize();
		this.Window.initialize();
        this.MainMenu.initialize();
        this.TopMenuButtons.initialize();
        this.PageLoader.initialize();

        $.history.init($.proxy(this.Utils.historyHook, this));
        $(window).load($.proxy(this.onLoad, this));
    },

    onLoad: function() {
        $(window).resize($.proxy(function() {
			this.MainMenu.updateBGPosition();
			this.readWindowDimenstion();
        }, this));

        this.Footer.initialize();
        this.Utils.syncHover();
    },

	readWindowDimenstion: function() {
		AICMedia.frame = { width: $(window).width(), height: $(window).height() };
	},

	redirect: function(url) {
		document.location.hash = url;
	},

    FormValidator: {
        validateForm: function(button) {
            var $button = $(button);
            var $rInputList = $('textarea.required, input', $button.parents('form'));
            $rInputList.removeClass('alert');

            var $errorList = $([]);

            $rInputList.each(function() {
                var $this = $(this);
                var error = false;
                var re = null;
                if ($this.hasClass('required') && this.value == '') {
                    error = true;
                    $this.data('oldText', $this.val());
                    $this.val($this.width() <= 185 ? 'Эй, неправильно!' : 'Эй, вы забыли меня заполнить!');
                    $errorList = $errorList.add(this);
                    return;
                } else if ($this.filter('[id*="email"]').length) {
                    re = new RegExp(/^([a-zA-Z0-9]([a-zA-Z0-9]|[-_\.][a-zA-Z0-9])*@[a-zA-Z0-9]([a-zA-Z0-9]|-[a-zA-Z0-9])*\.[a-zA-Z0-9]([a-zA-Z0-9]|-[a-zA-Z0-9])*|\s*)$/);
                } else if ($this.filter('[id*="password"]').length) {
                    re = new RegExp(/^([a-zA-Z0-9]{6,}|\s*)$/);
                } else if ($this.filter('[id*="name"]').length) {
                    re = new RegExp(/^([a-zA-Zа-яА-Я]([a-zA-Zа-яА-Я]|[- ][a-zA-Zа-яА-Я])*|\s*)$/);
                } else if ($this.filter('[id*="tel-prefix"]').length) {
                    re = new RegExp(/^([0-9]{0,5}|\s*)$/);
                } else if ($this.filter('[id*="tel"], [id*="tel-international"]').length) {
                    var re = $this.filter('[id*="tel-international"]').length ? new RegExp(/^((\+?[0-9]{1,3}(\s*|-))?(\([0-9]{1,5}\)(\s*|-))?[0-9]([0-9]|(\s+|-)[0-9])*|\s*)$/) : new RegExp(/^([0-9]([0-9]|-[0-9])*|\s*)$/);
                    if (re.test(this.value)) {
                        var str = this.value.replace(/[-\(\)\s\+]/g, '');
                        if (this.value != '' && (str.length < 5 || str.length > 15)) {
                            error = true;
                        }
                    } else {
                        error = true;
                    }
                } 

                if (re != null && !re.test(this.value)) {
                    error = true;
                }

                if (error) {
                    $this.data('oldText', $this.val());
                    $(this).val('Эй! Неправильно!');
                    $errorList = $errorList.add(this);
                }
            });

            $errorList.one('focus', function() {
                var $this = $(this);
                $this.val($this.data('oldText')).closest('div.field, div.textarea').andSelf().removeClass('alert');
                $this.removeData('oldText');
            });

            if ($errorList.closest('div.field, div.textarea').andSelf().addClass('alert').length) {
                return false;
            } else {
                return true;
            }
        },

        removeAlerts: function(form) {
            $(form).find('input.alert, textarea.alert').removeClass('alert').val('').closest('div.field.alert, div.textarea.alert').removeClass('alert');
        }
    },

    Index: {
        list: null,
        flashLogoList: [
            'flash/flash-logo-0.swf',
            'flash/flash-logo-1.swf',
            'flash/flash-logo-2.swf',
            'flash/flash-logo-3.swf',
            'flash/flash-logo-4.swf',
            'flash/flash-logo-5.swf',
            'flash/flash-logo-6.swf',
            'flash/flash-logo-7.swf',
            'flash/flash-logo-8.swf',
            'flash/flash-logo-9.swf',
            'flash/flash-logo-10.swf',
            'flash/flash-logo-11.swf',
            'flash/flash-logo-12.swf',
            'flash/flash-logo-13.swf'
        ],
        currentFlashLogoIndex: -1,
        isIndex: false,
        isAnimated: false,
        isPreloading: false,
        cbPreloading: null,
        $bdList: null,
        curBdIndex: -1,
        nextBdIndex: -1,
        DURATION: 700,

        initBackdrops: function() {
            this.$bdList = $('.frame.b-index-page a.project-link').each(function() {
                var $a = $(this);
                var $img = $a.find('img.decorator');
                $a.css({
                    width: $img.width(),
                    height: $img.height()
                });
            }).addClass('decorator');
            this.curBdIndex = 0;

            var $img = this.getCurBd().find('img');
            $img.attr('src', $img.attr('srcOnDemand'));
            $img.removeAttr('srcOnDemand');
            this.$bdList.filter(':gt(0)').hide();

            this._preloadNextBd();

            this.initWelcome();
        },

        initWelcome: function() {
            if (this.curBdIndex == -1) {
                return;
            }

            var $bd = this.getBdByIndex(this.curBdIndex);

            if (!$bd.hasClass('welcome')) {
                return;
            }

            setTimeout(function() {
                $bd.find('.hint').fadeIn(500);
            }, 1000);
        },

        resizeWelcome: function() {
            if (this.curBdIndex == -1) {
                return;
            }

            var $bd = this.getBdByIndex(this.curBdIndex);

            if (!$bd.hasClass('welcome')) {
                return;
            }

            var top = -parseFloat($bd.css('top'));
            var width = (960 / $(window).width() * 100);
            $bd.find('.welcome-content').css({
                top: top,
                bottom: top,
                width: width + '%',
                marginLeft: '-' + (width / 2) + '%'
            });
        },

        getBdByIndex: function(index) {
            return this.$bdList.filter(':eq(' + index + ')');
        },

        getCurBd: function() {
            return this.getBdByIndex(this.curBdIndex);
        },

        refreshSchema: function(bdIndex, duration) {
            bdIndex = bdIndex == 'undefined' ? this.curBdIndex : bdIndex;
            duration = duration || 0;

            setTimeout($.proxy(function() {
                AICMedia.Schemas.refresh(this.getBdByIndex(bdIndex).attr('schema'));
            }, this), duration);
        },

        _preloadNextBd: function() {
            this.isPreloading = true;
            this.nextBdIndex = (this.curBdIndex == this.$bdList.length - 1 ? 0 : this.curBdIndex + 1);

            var $img = this.getBdByIndex(this.nextBdIndex).find('img');
            if ($img.attr('src')) {
                this.isPreloading = false;
            } else {
                $img.load($.proxy(function() {
                    if (this.cbPreloading) {
                        var fn = this.cbPreloading;
                        //AICMedia.AjaxLoader.hide();
                        $('#top-menu .buttons').removeClass('loading');
                        this.cbPreloading = null;
                        this.isPreloading = false;
                        fn.apply(this);
                    } else {
                        this.isPreloading = false;
                    }
                }, this));
                $img.attr('src', $img.attr('srcOnDemand'));
                $img.removeAttr('srcOnDemand');
            }
        },

        _nextBd: function() {
            if (this.isAnimated || this.cbPreloading) {
                return;
            }

            if (this.isPreloading) {
                //AICMedia.AjaxLoader.show();
                $('#top-menu .buttons').addClass('loading');
                this.cbPreloading = this._nextBd;
                AICMedia.TopMenuButtons.isEnabled = false;
                return;
            }

            AICMedia.TopMenuButtons.isEnabled = false;
            this.isAnimated = true;

            var $curA = this.getBdByIndex(this.curBdIndex);
            var $curImg = $curA.find('img');
            var $nextA = this.getBdByIndex(this.nextBdIndex);
            var $nextImg = $nextA.find('img');

            $curA.css({zIndex: 1});

            var w = $curImg.width();
            var h = $curImg.height();
            $curA.animate({
                opacity: 0,
                top: '-=' + (h / 2) + 'px',
                left: '-=' + (w / 2) + 'px',
                height: '+=' + h + 'px',
                width: '+=' + w + 'px'
            }, this.DURATION, $.proxy(function() {
                $curA.animate({
                    opacity: 1,
                    top: '+=' + (h / 2) + 'px',
                    left: '+=' + (w / 2) + 'px',
                    height: '-=' + h + 'px',
                    width: '-=' + w + 'px'
                }, 0);

                $curA.css({
                    zIndex: 0,
                    display: 'none'
                });

                $nextA.show();
                w = $nextImg.width();
                h = $nextImg.height();
                this.refreshSchema(this.nextBdIndex);
                $nextA.animate({
                    opacity: 0,
                    top: '-=' + (h / 2) + 'px',
                    left: '-=' + (w / 2) + 'px',
                    height: '+=' + h + 'px',
                    width: '+=' + w + 'px'
                }, 0).animate({
                    opacity: 1,
                    top: '+=' + (h / 2) + 'px',
                    left: '+=' + (w / 2) + 'px',
                    height: '-=' + h + 'px',
                    width: '-=' + w + 'px'
                }, this.DURATION, $.proxy(function() {
                    this.curBdIndex = this.nextBdIndex;
                    this._preloadNextBd();

                    this.isAnimated = false;
                    AICMedia.TopMenuButtons.isEnabled = true;
                }, this));
            }, this));
        },

        refresh: function() {
            jQuery.ajax({
                url: '/minusodin.php',
                data: { dbid: this.getCurBd().attr('dbid') },
                dataType: 'json'//,
//                success: alert('success minus '+this.getCurBd().attr('dbid'))
                });
			this._nextBd();
        },

        like: function() {
            jQuery.ajax({
                url: '/plusodin.php',
                data: { dbid: this.getCurBd().attr('dbid') },
                dataType: 'json'//,
//                success: alert('success plus '+this.getCurBd().attr('dbid'))
                });

            window.location.assign(this.getCurBd().attr('href'));
        },

        _getFlashLogoUrl: function() {
            var randomIndex;

			do {
				randomIndex = $rand(0, this.flashLogoList.length - 1);
			} while (this.currentFlashLogoIndex == randomIndex && this.flashLogoList.length > 1);

            this.currentFlashLogoIndex = randomIndex;
            return this.flashLogoList[this.currentFlashLogoIndex];
        },

        updateFlashLogo: function() {
            var $logo = $('#top-menu .logo-container img.logo');
            if ((location.hash == '' || this.isIndex) && navigator.plugins["Shockwave Flash"]) {
                var $flashLogo = $('<object class="logo" data="' + this._getFlashLogoUrl() + '" type="application/x-shockwave-flash"><param name="quality" value="high" /><param name="wmode" value="opaque" /><param name="bgcolor" value="#000000" /></object>');
                $logo.after($flashLogo);
            } else {
                $('#top-menu .logo-container object.logo').remove();
            }
        }
    },

    Schemas: {
        schemas: {
            'blue': 'g-schema_blue',
            'orange': 'g-schema_orange',
            'magenta': 'g-schema_magenta',
            'green': 'g-schema_green',
            'gray': 'g-schema_gray',
            'light-blue': 'g-schema_light-blue'
        },

        refresh: function(schema) {
            if (schema != '') {
                $('#root').removeClass().addClass(this.schemas[schema]);
            }
        }
    },

    MainMenu: {
		td: null,

        initialize: function() {
            $('#main-menu a').click(function(event) {
                if (AICMedia.PageLoader.animationInProcess) {
                    event.preventDefault();
                }
            });
        },

        unselectAll: function() {
            $('#main-menu td.active').removeClass('active');
			this.td = null;
            this.updateBGPosition();
        },

        select: function(menuItem) {
            if (AICMedia.PageLoader.animationInProcess) {
                return;
            }
            this.unselectAll();
			this.td =  $(menuItem).closest('td');
            this.td.addClass('active');
			this.updateBGPosition();
        },

		updateBGPosition: function() {
			if ( this.td ) {
				$('#top-menu .wrap-menu .bg span.l').css({
					backgroundPosition: (-1422 + this.td.position().left + 59) +'px bottom'
				});
                $('#top-menu .wrap-menu .bg span.r').css({
					backgroundPosition: (-1422 + this.td.position().left + this.td.width() - 150) +'px bottom'
				});
			} else {
                $('#top-menu .wrap-menu .bg span').css('background-position', 'top');
            }
		},

        selectByName: function(name) {
            var item = $('#main-menu a[href="#' + name + '"], #main-menu a[href="#!' + name + '"]');
            if (!item.length) {
                name = name.replace(/^([^\/]*\/)(.)*$/, '$1'); //'$1index.html');
                item = $('#main-menu a[href="#' + name + '"], #main-menu a[href="#!' + name + '"]');
            }
			if ( item.length )
                this.select(item);
            else {
				this.unselectAll();
			}
        },

        compareByName: function(name1, name2) {
            var item1 = $('#main-menu a[href="#' + name1 + '"], #main-menu a[href="#!' + name1 + '"]');
            if (!item1.length) {
                name1 = name1.replace(/^([^\/]*\/)(.)*$/, '$1'); //'$1index.html');
                item1 = $('#main-menu a[href="#' + name1 + '"], #main-menu a[href="#!' + name1 + '"]');
            }
            var item2 = $('#main-menu a[href="#' + name2 + '"], #main-menu a[href="#!' + name2 + '"]');
            if (!item2.length) {
                name2 = name2.replace(/^([^\/]*\/)(.)*$/, '$1'); //'$1index.html');
                item2 = $('#main-menu a[href="#' + name2 + '"], #main-menu a[href="#!' + name2 + '"]');
            }
            var itemAll = $('#main-menu a');
            if (item1.length && item2.length) {
                if ($.inArray(item1[0], itemAll.toArray()) > $.inArray(item2[0], itemAll.toArray())) {
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return 0;
            }
        }
    },

    InnerMenu: {
        compareByName: function(name1, name2) {
            var item1 = $('.b-inner-menu .menu a[href="#' + name1 + '"], .b-inner-menu .menu a[href="#!' + name1 + '"]');
            var item2 = $('.b-inner-menu .menu a[href="#' + name2 + '"], .b-inner-menu .menu a[href="#!' + name2 + '"]');
            var itemAll = $('.b-inner-menu .menu a');
            if (item1.length && item2.length) {
                if ($.inArray(item1[0], itemAll.toArray()) > $.inArray(item2[0], itemAll.toArray())) {
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return 0;
            }
        }
    },

    BottomMenu: {
        compareByName: function(name1, name2) {
            var item1 = $('#footer .group h2 a[href="#' + name1 + '"], #footer .group h2 a[href="#!' + name1 + '"]');
            var item2 = $('#footer .group h2 a[href="#' + name2 + '"], #footer .group h2 a[href="#!' + name2 + '"]');
            var itemAll = $('#footer .group h2 a');
            if (item1.length && item2.length) {
                if ($.inArray(item1[0], itemAll.toArray()) > $.inArray(item2[0], itemAll.toArray())) {
                    return 1;
                } else {
                    return -1;
                }
            } else {
                return 0;
            }
        }
    },

    AjaxLoader: {
        show: function(callback) {
            if (AICMedia.count == 0) {
                /*if (location.hash != '') {
                $('#ajax-first-page-loader').fadeTo(250, 1, callback ? callback : void(0));
                } else {*/
                    $('#ajax-first-page-loader').addClass('one-minute');
                    location.hash == '' && AICMedia.TopMenuButtons.show(0);
                    AICMedia.Index.updateFlashLogo();
                    callback && callback();
                //}
            } else if (!AICMedia.Index.isIndex) {
                $('#ajax-loader').removeClass('b-ajax-loader_disabled');
                callback && callback();
            } else {
                AICMedia.TopMenuButtons.hide(AICMedia.PageLoader.time * 250, function() {
                    $('#ajax-loader').removeClass('b-ajax-loader_disabled');
                    callback && callback();
                });
            }
        },

        hide: function() {
            if (AICMedia.count == 0) {
                $('#ajax-first-page-loader').fadeTo(666, 0, function() {
                    $(this).css({display: 'none'});
                });
            } else {
                $('#ajax-loader').addClass('b-ajax-loader_disabled');
            }
        }

    },

    PageLoader: {
		time: 1,
        currentPage: null,
		prevPage: null,
        cachedPages: {},
        cb: {onLoad: {}, onComplete: {}, onLoadNext: {}, beforeLoad: {}, beforeLoadNext: {}, onCompleteNext: {}},
        animationInProcess: false,
		onUnloadFunction: null,

        initialize: function() {
            this.cb.beforeLoad['all'] = $.proxy(function() {
                AICMedia.AjaxLoader.hide();
                AICMedia.MainMenu.selectByName(this.currentPage);
            }, this);

            this.cb.onLoad['all'] = $.proxy(function() {
                AICMedia.PortfolioProjects.initModeText();
                AICMedia.PortfolioProjects.initModePreview();
                AICMedia.SimpleScroll.initialize();
                AICMedia.Footer.setMenu();
                AICMedia.Scroller.initialize();
                AICMedia.FAQ.initialize();
                AICMedia.ClientMorePopup.initialize();
                AICMedia.SideArrows.stop();
                AICMedia.SimpleScrollArrows.stop();
                this.fixDecorator();
                $('.js-no-select').disableTextSelect();
            }, this);

            this.cb.onComplete['all'] = $.proxy(function() {
                AICMedia.SideArrows.start();
                AICMedia.SimpleScrollArrows.start();
                AICMedia.Footer.hide();
                $('.frame.prev-page').removeClass('prev-page');
                $('.frame.cur-page').removeClass('cur-page');
            }, this);
        },

        register: function(beforeLoad, onLoad, onComplete, beforeLoadNext, onLoadNext, onCompleteNext) {
			if ( beforeLoadNext ) this.cb.beforeLoadNext[this.currentPage] = beforeLoadNext;
            if ( beforeLoad ) this.cb.beforeLoad[this.currentPage] = beforeLoad;
            if ( onLoadNext ) this.cb.onLoadNext[this.currentPage] = onLoadNext;
            if ( onLoad ) this.cb.onLoad[this.currentPage] = onLoad;
            if ( onCompleteNext ) this.cb.onCompleteNext[this.currentPage] = onCompleteNext;
			if ( onComplete ) this.cb.onComplete[this.currentPage] = onComplete;
        },

		setBackgroundColor: function(color) {
			if ( !color ) $('#root').removeAttr('style'); else $('#root').css('background-color', color);
		},

        fixDecorator: function() {
            var $frames = $('.frame.prev-page, .frame.cur-page');
            if ($frames.filter('.b-projects-list, :has(#portfolio-menu), #project-frame').length == 2) {
                $frames.find('img.decorator').css({position: 'fixed'});
            } else {
                $frames.find('img.decorator').css({position: 'absolute'});
            }
        },

        registerOnUnload: function(callback) {
			if ( callback ) this.onUnloadFunction = callback;
		},

		onUnload: function() {
			if ( this.onUnloadFunction ) {
				this.onUnloadFunction();
				this.onUnloadFunction = null;
			}
		},

        getSlideDirection: function($prevFrame, $curFrame) {
            var prevPage = this.prevPage;
            var curPage = this.currentPage;

            var dir = {
                t: 'topToBottom',
                r: 'rightToLeft',
                b: 'bottomToTop',
                l: 'leftToRight'
            };

            if (!prevPage) {
                return dir.r;
            }

            if ($prevFrame.filter('.b-projects-list').length && $curFrame.filter('#project-frame').length) {
                return dir.b;
            } else if ($prevFrame.filter('#project-frame').length && $curFrame.filter('.b-projects-list').length) {
                return dir.t;
            }

            var d = AICMedia.InnerMenu.compareByName(prevPage, curPage);
            if (d != 0) {
                if (d > 0) {
                    return dir.l;
                } else {
                    return dir.r;
                }
            }

            var d = AICMedia.BottomMenu.compareByName(prevPage, curPage);
            if (d != 0) {
                if (d > 0) {
                    return dir.l;
                } else {
                    return dir.r;
                }
            }

            if ($('.frame.prev-page .footer .prev-project').attr('href') == '#' + curPage) {
                return dir.l;
            }

            d = AICMedia.MainMenu.compareByName(prevPage, curPage);
            if (d != 0) {
                if (d > 0) {
                    return dir.l;
                } else {
                    return dir.r;
                }
            }

            return dir.r;
        },

        process: function(data, animation, force) {
            $('.frame').addClass('prev-page');
            data['content'].addClass('cur-page');

            if (this.prevPage && this.cb.beforeLoadNext[this.prevPage]) this.cb.beforeLoadNext[this.prevPage]();
            if (this.cb.beforeLoad[data['id']]) this.cb.beforeLoad[data['id']]();
            this.cb.beforeLoad.all();

            if (force) $('#current-backdrop .frame:first').detach();
            this.updateTitle(data['title']);
            
            switch (this.getSlideDirection($('.frame.prev-page'), data['content'])) {
                case 'bottomToTop':
                    $('#current-backdrop .line:first').css({width: '100%'});
                    $('#current-backdrop .line:first').append(data['content']);
                    this.currentFrame = $('#current-backdrop .frame:last');
                    fnAnimation.call(this, 'marginTop', -($(window).height()), 0, $(window).height());
                    break;

                case 'topToBottom':
                    $('#current-backdrop .line:first').css({width: '100%'});
                    $('#current-backdrop .line:first').prepend(data['content']);
                    this.currentFrame = $('#current-backdrop .frame:first');
                    if (this.prevPage) {
                        this.currentFrame.css({ marginTop: -($(window).height()) });
                    }
                    fnAnimation.call(this, 'marginTop', 0, 0, $(window).height());
                    break;

                case 'rightToLeft':
                    $('#current-backdrop .line:first').css({width: '200%'});
                    $('#current-backdrop .line:first').append(data['content']);
                    this.currentFrame = $('#current-backdrop .frame:last');
                    fnAnimation.call(this, 'marginLeft', -($(window).width()), 0, 0);
                    break;

                case 'leftToRight': // не ошибка

                default:
                    $('#current-backdrop .line:first').css({width: '200%'});
                    $('#current-backdrop .line:first').prepend(data['content']);
                    this.currentFrame = $('#current-backdrop .frame:first');
                    if (this.prevPage) {
                        this.currentFrame.css({ marginLeft: -($(window).width()) });
                    }
                    fnAnimation.call(this, 'marginLeft', 0, 0, 0);
                    break;
            }
            try{
                FB.XFBML.parse();
            }catch(ex){}

            function fnAnimation(marginType, animValue, afterValue, scrollerFadeTop) {
                AICMedia.readWindowDimenstion();
                AICMedia.Backdrop.resize();

                if (this.prevPage && this.cb.onLoadNext[this.prevPage]) this.cb.onLoadNext[this.prevPage]();
                if (this.cb.onLoad[data['id']]) this.cb.onLoad[data['id']]();
                this.cb.onLoad.all();

                if (data['content'].find('.b-scroller').length) {
                    var top = parseInt(data['content'].find('img.decorator').css('top')) - data['content'].find('.b-scroller').offset().top - scrollerFadeTop;
                    $('.b-scroller .left-fade, .b-scroller .right-fade').css({top: top + 'px'});
                }

                if ($('.cur-page, .prev-page').filter('.frame.b-projects-list').length == 2 && $('.cur-page').attr('section') == $('.prev-page').attr('section')) {
                    this.projectsListProcess();
                    return;
                }

                var objMargin = new Object();
                if (animation && AICMedia.count > 0) {
                    setTimeout($.proxy(function() {
                        if (!AICMedia.Index.isIndex) {
                            AICMedia.Schemas.refresh(data['schema']);
                        }
                        this.setBackgroundColor(this.currentFrame.attr('color'));
                    }, this), (this.time / 2) * 1000);
                    objMargin[marginType] = animValue;
                    $t($('#current-backdrop .frame:first'), objMargin).tween({
                        time: this.time,
                        transition: 'easeInOutExpo',
                        onStart: $.proxy(function() {
                            this.animationInProcess = true;
                        }, this),
                        onComplete: $.proxy(function() {
                            objMargin[marginType] = afterValue;
                            $('.frame.prev-page').removeClass('prev-page').css(objMargin).detach();
                            this.animationInProcess = false;
                            if (this.prevPage && this.cb.onCompleteNext[this.prevPage]) this.cb.onCompleteNext[this.prevPage]();
                            if (this.cb.onComplete[data['id']]) this.cb.onComplete[data['id']]();
                            this.cb.onComplete.all();
                        }, this)
                    });
                } else {
                    if (!AICMedia.Index.isIndex) {
                        AICMedia.Schemas.refresh(data['schema']);
                    }
                    this.setBackgroundColor(this.currentFrame.attr('color'));
                    if (this.prevPage && this.cb.onCompleteNext[this.prevPage]) this.cb.onCompleteNext[this.prevPage]();
                    if (this.cb.onComplete[data['id']]) this.cb.onComplete[data['id']]();
                    this.cb.onComplete.all();
                }
            }

            AICMedia.count++;
        },

        projectsListProcess: function() {
            var updateFilters = $.proxy(function(selector) {
                var $prevFilter = $prevFrame.find(selector);
                var $curFilter = $curFrame.find(selector).clone().insertAfter($prevFilter);
                $curFilter.css({
                    position: 'fixed',
                    top: $prevFilter.offset().top,
                    left: $prevFilter.offset().left,
                    opacity: 0,
                    width: $prevFilter.width(),
                    margin: 0
                }).fadeTo(DURATION / 2, 1);
                $prevFilter.fadeOut(DURATION / 2);
                setTimeout(function() {
                    $curFilter.remove();
                    $prevFilter.show();
                }, DURATION * 3 / 2);
            }, this);

            this.animationInProcess = true;
            var EASING = 'easeInOutExpo';
            var DURATION = this.time * 1000;

            var $prevFrame = $('.frame.b-projects-list.prev-page');
            var $curFrame = $('.frame.b-projects-list.cur-page');
            var $prevScroller = $prevFrame.find('.b-scroller');
            var $curScroller = $curFrame.find('.b-scroller');

            var wndHeight = $(window).height();
            var startPrevTop = $prevScroller.css('top');
            var startCurTop = $curScroller.css('top');
            var prevTop = $prevScroller.offset().top - parseFloat($prevScroller.css('marginTop'));
            var curTop = $curScroller.offset().top - parseFloat($curScroller.css('marginTop'));
            var dPrevTop = wndHeight - $prevScroller.offset().top + 10;
            var dCurTop = wndHeight - $curScroller.offset().top + 10;

            updateFilters('.filter');
            updateFilters('.mode');

            $prevScroller.css({top: prevTop}).animate({top: '+=' + dPrevTop + 'px'}, DURATION * 1.3, EASING, $.proxy(function() {
                $prevScroller.css({top: startPrevTop});
                $prevFrame.removeClass('prev-page').detach();

                $curFrame.css({
                    marginLeft: 0,
                    marginRight: 0
                });
                $curScroller.css({top: curTop + dCurTop}).animate({top: '-=' + dCurTop + 'px'}, DURATION, EASING, $.proxy(function() {
                    $curScroller.css({top: startCurTop});
                    this.animationInProcess = false;
                    this.cb.onComplete.all();
                }, this));
            }, this));
        },

		encodeURL: function(url) {
			url = url.split('?');
			if ( url[1] ) {
				url[1] = encodeURIComponent(url[1]);
				url = url[0]+'|'+url[1];
			} else url = url[0];
			return(url);
		},

        load: function(page, animation, force) {
            page = page.replace(/^!?(.+)$/, '$1');

            if ((this.currentPage != page || force) && !this.animationInProcess) {

				this.prevPage = this.currentPage;
                this.currentPage = page;

                if (this.cachedPages[page]) {
                    this.process(this.cachedPages[page], animation, force);
                } else {
                    AICMedia.AjaxLoader.show($.proxy(function() {
                        var encodedURL = AICMedia.isEncodeURL ? this.encodeURL(page) : page;
                        jQuery.ajax({
                            //url: encodedURL ? '/pages/'+encodedURL : '/',
                            url: '/'+page.replace(/^!?(.+)$/, '$1'),
                            data: { referer: document.referrer },
                            dataType: 'json',
                            success: $.proxy(function(data) {
                                var loader = $('#loader');
                                if (data && data['id']) {
                                    loader.html(data['content']);
                                    data['content'] = loader.find('.frame:first');
                                    var decorator = loader.find('img.decorator:first');
                                    if ( decorator.length ) {
                                        decorator.load($.proxy(function() {
                                            data['content'].detach();
                                            this.cachedPages[data['id']] = data;
                                            this.process(data, animation, force);
                                        }, this))
                                    } else {
                                        data['content'].detach();
                                        this.cachedPages[data['id']] = data;
                                        this.process(data, animation, force);
                                    }
                                }
                            }, this)
                        });
                    }, this));
                }
            }
        },

        updateTitle: function(newTitle) {
            document.title = newTitle.toUpperCase();
            $('#title').html(newTitle || '&nbsp;');
        }

    },

	TransparentBackdrop: {

		fadeOut: .7,
		cb: null,
		time: 0,
		onClick: null,
                fadeDuration: 300,

		initialize: function(){
			this.bg = $('#transparent-backdrop');
			this.bg.css('opacity', this.fadeOut);

			this.bg.click($.proxy(this.onBGClick, this));

		},

		onBGClick: function() {
			if ( this.onClick ) this.onClick();
		},

		show: function(onClick) {
            if (AICMedia.ie8) {
                this.bg.show();
            } else {
                this.bg.fadeIn(/*this.fadeDuration*/);
            }
			if ( onClick ) this.onClick = onClick;
		},

		hide: function() {
            if (AICMedia.ie8) {
                this.bg.hide();
            } else {
                this.bg.fadeOut(/*this.fadeDuration*/);
            }
			this.onClick = null;
		}

	},

	Window: {

		currentWindow: null,

		initialize: function() {
			$(window).resize($.proxy(this.resize, this));
		},

		attach: function(rootElement) {
			this.currentWindow = $('#'+rootElement);
            if (AICMedia.ie8) {
			    this.currentWindow.show();
            } else {
                this.currentWindow.fadeIn();
            }
			this.resize();
		},

		detach: function() {
			if ( null != this.currentWindow ) {
                if (AICMedia.ie8) {
                    this.currentWindow.hide();
                } else {
                    this.currentWindow.fadeOut();
                }
				this.currentWindow = null;
			}
		},

		updateContent: function(html) {
			this.currentWindow.find('div.wrap').html(html);
		},

		resize: function() {
			if ( null != this.currentWindow ) {
				this.currentWindow.css({
					left: $(window).width()/2 - this.currentWindow.width()/2,
					top: $(window).height()/2 - this.currentWindow.height()/2
				});
			}
		}

	},

	NewQuestion: {

		show: function() {
			AICMedia.TransparentBackdrop.show($.proxy(this.hide, this));
			AICMedia.Window.attach('new-question-window');

            var qb = $('a.new-question_button:visible');
			var qw = $('#new-question-window');
            var qf0 = $('#new-question-window .b-form:eq(0)');

			var width = this.startWidth = qw.width();
			var height = this.startHeight = qw.height();

			var endPosition = qw.offset();

			var bWidth = qb.width();
			var bHeight = qb.height();

			var startPosition = qb.offset();

			qw.css({
				width: bWidth,
				height: bHeight,
				left: startPosition.left,
				top: startPosition.top
			});

            if ($.browser.msie) {
                qw.css({filter: 'alpha(opacity=0)'});
            } else {
                qw.css({opacity: '0'});
            }

			qf0.hide();

			$t(qw, {
				left: endPosition.left,
				top: endPosition.top,
				width: width,
				height: height,
				opacity: 1,
				transition: 'easeOutExpo',
				time: .3,
				onComplete: function() {
					qf0.show();
					qw.css({
						height: 'auto'
					});
                    $('#new-question-window input:first').focus();                    
				}
			}).tween();
		},

		hide: function() {
			var objNewQuestion = this;

            var qb = $('a.new-question_button:visible');
			var qw = $('#new-question-window');
			var qf0 = $('#new-question-window .b-form:eq(0)');
			var qf1 = $('#new-question-window .b-form:not(eq(1))');

			var height = qw.height();

			qw.height(height);

			var bWidth = qb.width();
			var bHeight = qb.height();

			var startPosition = qb.offset();

			qf0.hide();
            qf1.hide();

			$t(qw, {
				left: startPosition.left,
				top: startPosition.top,
				width: bWidth,
				height: bHeight,
				opacity: 0.01,
				transition: 'easeInExpo',
				time: .5
			}).tween({
				onComplete: function() {
					AICMedia.Window.detach();
					AICMedia.TransparentBackdrop.hide();
					qw.css({
						width: objNewQuestion.startWidth,
						height: objNewQuestion.startHeight,
						display: 'none'
					});
                    qf0.show();
				}
			});
		},

		submit: function() {
            var options = {
                resetForm: true,
            	dataType:  'json',
                beforeSubmit: function(formData, $form) {
                    if (AICMedia.isSubmit || !AICMedia.FormValidator.validateForm($form.find('.submit-button')[0])) {
                        return false;
                    }
                    AICMedia.isSubmit = true;
                },

                success: function(responseText, statusText, xhr, $form) {
                    //alert(responseText.content);
                    var qf1 = $form.closest('.b-form').siblings('.b-form_' + (responseText.content == 'addok' ? 'success' : 'error'));

                    var qw = $('#new-question-window');
                    var oldWndH = qw.height();
                    qw.find('.b-form:eq(0)').hide();

                    qf1.css({display: 'block'});
                    var newWndH = qw.height();
                    qf1.css({display: 'none'});

                    qw.css({height: oldWndH}).animate({
                        height: newWndH + 'px',
                        top: (parseInt(qw.css('top')) + Math.floor((oldWndH - newWndH) / 2)) + 'px'
                    }, 200, function() {
                        qf1.show();
                        qw.css({height: 'auto'});
                    });

                    AICMedia.isSubmit = false;
                }
            };

            $('#faq-form').ajaxSubmit(options);
		}
	},

    CommentWindow: {

        show: function() {
			AICMedia.TransparentBackdrop.show($.proxy(this.hide, this));
			AICMedia.Window.attach('comment-window');

			var cb = $('.comment_button');
			var cw = $('#comment-window');

			var width = cw.width();
			var height = cw.height();

			var endPosition = cw.offset();

			var bWidth = cb.width();
			var bHeight = cb.height();

			var startPosition = cb.offset();

			cw.css({
				width: bWidth,
				height: bHeight,
				left: startPosition.left,
				top: startPosition.top
			});

            if ($.browser.msie) {
                cw.css({filter: 'alpha(opacity=0)'});
            } else {
                cw.css({opacity: '0'});
            }

			$('#comment-window table.wrap').hide();

			$t(cw, {
				left: endPosition.left,
				top: endPosition.top,
				width: width,
				height: height,
				opacity: 1,
				transition: 'easeOutExpo',
				time: .3,
				onComplete: function() {
					$('#comment-window table.wrap').show();
					cw.css({
						height: 'auto'
					});
				}
			}).tween();

        },

        hide: function() {
			var cb = $('.comment_button');
			var cw = $('#comment-window');

			var width = cw.width();
			var height = cw.height();

			cw.height(height);

			var bWidth = cb.width();
			var bHeight = cb.height();

			var startPosition = cb.offset();

			$('#comment-window .b-form').hide();

			$t(cw, {
				left: startPosition.left,
				top: startPosition.top,
				width: bWidth,
				height: bHeight,
				opacity: 0,
				transition: 'easeInExpo',
				time: .5
			}).tween({
				onComplete: function() {
					AICMedia.Window.detach();
					AICMedia.TransparentBackdrop.hide();
					$('#comment-window .b-form:first').show();
                    cw.css({
						width: width,
						height: 'auto',
						display: 'none'
					});
				}
			});

        },

        submit: function() {
            var options = {
                resetForm: true,
            	dataType:  'json',
                beforeSubmit: function(formData, $form) {
                    if (AICMedia.isSubmit || !AICMedia.FormValidator.validateForm($form.find('.submit-button')[0])) {
                        return false;
                    }
                    AICMedia.isSubmit = true;
                },

                success: function(responseText, statusText, xhr, $form) {
                    var cf1 = $form.closest('.b-form').siblings('.b-form_' + (responseText.content == 'addok' ? 'success' : 'error'));
                    //var cf1 = $('#comment-form').closest('.b-form').siblings('.b-form_success');
                    
                    var cw = $('#comment-window');
                    var oldWndH = cw.height();
                    cw.find('.b-form:eq(0)').hide();

                    cf1.css({display: 'block'});
                    var newWndH = cw.height();
                    cf1.css({display: 'none'});

                    cw.css({height: oldWndH}).animate({
                        height: newWndH + 'px',
                        top: (parseInt(cw.css('top')) + Math.floor((oldWndH - newWndH) / 2)) + 'px'
                    }, 200, function() {
                        cf1.show();
                        cw.css({height: 'auto'});
                    });

                    AICMedia.isSubmit = false;
                }
            };

            $('#comment-form').ajaxSubmit(options);
		}
    },

    Feedback: {

        show: function(tabNumber, text) {
            var aw = $('#about-window');

            tabNumber = tabNumber || 1;
            AICMedia.Tabs.setWithoutAnimation(tabNumber, aw.find('.tabs .tab:eq(' + (tabNumber - 1) + ')'));

            text = text || '';
            $('#analog-request').attr('value', text);

			AICMedia.TransparentBackdrop.show($.proxy(this.hide, this));
			AICMedia.Window.attach('about-window');

			var fb = $('#feedback-button, .order_button');

			var width = aw.width();
			var height = aw.height();

			var endPosition = aw.offset();

			var bWidth = fb.width();
			var bHeight = fb.height();

			var startPosition = fb.offset();

			aw.css({
				width: bWidth,
				height: bHeight,
				left: startPosition.left,
				top: startPosition.top
			});

            if ($.browser.msie) {
                aw.css({filter: 'alpha(opacity=0)'});
            } else {
                aw.css({opacity: '0'});
            }

			$('#about-window .b-tabs').hide();

			$t(aw, {
				left: endPosition.left,
				top: endPosition.top - $(window).scrollTop(),
				width: width,
				height: height,
				opacity: 1,
				transition: 'easeOutExpo',
				time: .3,
				onComplete: function() {
					$('#about-window .b-tabs').show();
					aw.css({
						height: 'auto'
					});
				}
			}).tween();

        },

        hide: function() {
			var fb = $('#feedback-button, .order_button');
			var aw = $('#about-window');

			var width = aw.width();
			var height = aw.height();

			aw.height(height);

			var endPosition = aw.offset();

			var bWidth = fb.width();
			var bHeight = fb.height();

			var startPosition = fb.offset();

			$('#about-window .b-tabs').hide();


			$t(aw, {
				left: startPosition.left,
				top: startPosition.top,
				width: bWidth,
				height: bHeight,
				opacity: 0,
				transition: 'easeInExpo',
				time: .5
			}).tween({
				onComplete: function() {
					AICMedia.Window.detach();
					AICMedia.TransparentBackdrop.hide();
					aw.css({
						width: width,
						height: 'auto',
						display: 'none'
					});
					$('#about-window .b-tabs').show().find('.tab-content').each(function() {
                        $(this).find('.b-form').css({display: 'none'}).filter('.b-form:eq(0)').css({display: 'block'});
                    });
				}
			});
        },

        feedbackFormSubmit: function() {
            var options = {
                resetForm: true,
                dataType:  'json',
                beforeSubmit: function(formData, $form) {
                    if (AICMedia.isSubmit || !AICMedia.FormValidator.validateForm($form.find('.submit-button')[0])) {
                        return false;
                    }
                    AICMedia.isSubmit = true;
                },

                success: function(responseText, statusText, xhr, $form) {
                    var ff1 = $form.closest('.b-form').siblings('.b-form_' + (responseText.content == 'addok' ? 'success' : 'error'));

                    var wnd = $('#about-window');
                    var curTC = wnd.find('.tabs-content');
                    var oldWndH = curTC.height();
                    curTC.find('.b-form').hide();

                    ff1.css({display: 'block'});
                    var newWndH = curTC.height();
                    ff1.css({display: 'none'});

                    curTC.css({height: oldWndH}).animate({
                        height: newWndH + 'px'
                    }, 200, function() {
                        ff1.show();
                        curTC.css({height: 'auto'});
                    });
                    wnd.animate({
                        top: (parseInt(wnd.css('top')) + Math.floor((oldWndH - newWndH) / 2)) + 'px'
                    }, 200);

                    AICMedia.isSubmit = false;
                }
            };

            $('#feedback-form').ajaxSubmit(options);
        },

        requestFormSubmit: function() {
            var options = {
                resetForm: true,
            	dataType:  'html',
                beforeSubmit: function(formData, $form) {
                    if (AICMedia.isSubmit || !AICMedia.FormValidator.validateForm($form.find('.submit-button')[0])) {
                        return false;
                    }
                    AICMedia.isSubmit = true;

                        $form.find('input[type="file"]').each(function() {
                            if ($(this).val() != '') {
                                $(this).closest('.group.file').addClass('upload');
                            }
                        });
                },

                success: function(responseText, statusText, xhr, $form) {
                    $form.find('input[type="file"]').closest('.group.file').removeClass('upload');
                    $form.find('.group.file .field input').val('');

                    //alert(responseText);

                    if (responseText != 'addok') {
                        return;
                    }

                    var rf1 = $form.closest('.b-form').siblings('#request-form-result-2');
                    //var rf1 = $('#request-form').closest('.b-form').siblings('#request-form-result-2');

                    var wnd = $('#about-window');
                    var curTC = wnd.find('.tabs-content');
                    var oldWndH = curTC.height();
                    curTC.find('.b-form').hide();

                    rf1.css({display: 'block'});
                    var newWndH = curTC.height();
                    rf1.css({display: 'none'});

                    curTC.css({height: oldWndH}).animate({
                        height: newWndH + 'px'
                    }, 200, function() {
                        rf1.show();
                        curTC.css({height: 'auto'});
                    });
                    wnd.animate({
                        top: (parseInt(wnd.css('top')) + Math.floor((oldWndH - newWndH) / 2)) + 'px'
                    }, 200);

                    AICMedia.isSubmit = false;
                }
            };

            $('#request-form').ajaxSubmit(options);
        },

        briefFormShow: function() {
            var rf1 = $('#request-form').closest('.b-form').siblings('#request-form-result-2');

            var curTC = rf1.closest('.tab-content');
            curTC.find('.b-form').hide();

            rf1.show();

            this.show(3);
        },

        briefFormSubmit: function() {
            var options = {
            dataType:  'html',
                resetForm: true,
                beforeSubmit: function(formData, $form) {
                    if (AICMedia.isSubmit || !AICMedia.FormValidator.validateForm($form.find('.submit-button')[0])) {
                        return false;
                    }
                    AICMedia.isSubmit = true;

                        $form.find('input[type="file"]').each(function() {
                            if ($(this).val() != '') {
                                $(this).closest('.group.file').addClass('upload');
                        }
                        });
                },

                success: function(responseText, statusText, xhr, $form) {
                    $form.find('input[type="file"]').closest('.group.file').removeClass('upload');
                    $form.find('.group.file .field input').val('');
                    //alert(responseText);

                    var rf1 = $form.closest('.b-form').siblings('.b-form_' + (responseText == 'addok' ? 'success' : 'error'));

                    var wnd = $('#about-window');
                    var curTC = rf1.closest('.tab-content');
                    var oldWndH = curTC.height();
                    curTC.find('.b-form').hide();

                    rf1.css({display: 'block'});
                    var newWndH = curTC.height();
                    rf1.css({display: 'none'});

                    curTC.css({height: oldWndH}).animate({
                        height: newWndH + 'px'
                    }, 200, function() {
                        rf1.show();
                        curTC.css({height: 'auto'});
                    });
                    wnd.animate({
                        top: (parseInt(wnd.css('top')) + Math.floor((oldWndH - newWndH) / 2)) + 'px'
                    }, 200);

                    AICMedia.isSubmit = false;
                }
            };

            $('#request-form-2').ajaxSubmit(options);
        }
    },

	Tabs: {

		showMap: function() {
			if ( !this.map ) {
				var geocoder = new google.maps.Geocoder();
				geocoder.geocode( { address: '127051, Москва, Садовая-Самотечная улица, дом 12' }, $.proxy(function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						this.map = new google.maps.Map(document.getElementById("map"), {
							zoom: 15,
							mapTypeId: google.maps.MapTypeId.ROADMAP,
							  panControl: false,
							  zoomControl: true,
							  mapTypeControl: false,
							  scaleControl: false,
							  streetViewControl: false
						});
						this.map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
							map: this.map,
							position: results[0].geometry.location
						});
					}
				}, this));


			}
		},

        setWithoutAnimation: function(id, element) {
            id--;
			var root = $(element).closest('.b-tabs');
			var tabs = root.find('.tabs .tab');
			var content = root.find('.tabs-content .tab-content');
			tabs.removeClass('active');
			root.find('.tabs .tab:eq('+id+')').addClass('active');
            content.removeClass('tab-content_active').css({display: 'none'});
            root.find('.tabs-content .tab-content:eq('+id+')').addClass('tab-content_active').css({display: 'block'});
            if ( 1 == id) this.showMap();
        },

		set: function(id, element) {
			id--;
			var root = $(element).closest('.b-tabs');
			var tabs = root.find('.tabs .tab');
			var content = root.find('.tabs-content .tab-content');
			tabs.removeClass('active');
			root.find('.tabs .tab:eq('+id+')').addClass('active');

            /* new size */
            var wrap = root.find('.tabs-wrap');
            var oldTab = root.find('.tabs-content .tab-content_active');
            var newTab = root.find('.tabs-content .tab-content:eq('+id+')');
            newTab.find('.b-form').hide().filter(':eq(0)').show();
            var defaultWrapH = wrap.css('height');
            var oldWrapH = wrap.height();
            oldTab.css({display: 'none'});
            newTab.css({
                visibility: 'hidden',
                display: 'block'
            });
            var newWrapH = wrap.height();
            oldTab.css({display: 'block'});
            newTab.css({
                visibility: 'visible',
                display: 'none'
            });
            /* end new size */

            wrap.height(oldWrapH);
			root.find('.tabs-content .tab-content_active').hide('fade', {}, 200, $.proxy(function(){
				content.removeClass('tab-content_active');
                wrap.animate({height: newWrapH + 'px'}, 200, $.proxy(function(){
                    root.find('.tabs-content .tab-content:eq('+id+')').show('fade',  { direction: 'right' }, 200, $.proxy(function(){
                        wrap.css({height: 'auto'});
                        if ( 1 == id) this.showMap();
                    }, this));
                }, this));

                var wnd = AICMedia.Window.currentWindow;
                if ( null != wnd ) {
					wnd.animate({top: (parseInt(wnd.css('top')) - Math.floor((newWrapH - oldWrapH) / 2)) + 'px'}, 200);
				}
                
				root.find('.tabs-content .tab-content:eq('+id+')').addClass('tab-content_active');
			}, this));
		}
	},

    Utils: {

        historyHook: function(hash) {
            if (hash) {
                var split = hash.split('/');
                if ('index' == split[0]) {
                    AICMedia.PageLoader.load(hash, false, true);
                    AICMedia.MainMenu.unselectAll();
                } else {
                    AICMedia.PageLoader.load(hash, true);
                }
            } else {
                AICMedia.PageLoader.load(AICMedia.indexHash, true);
            }
        },

        syncHover: function() {
            $("a.js-double-hover").live("mouseover",
                    function() {
                        $("a[link=" + $(this).attr("link") + "].js-double-hover").addClass("pseudo-hover")

                    }
                    );
            $("a.js-double-hover").live("mouseout",
                    function() {
                        $("a.pseudo-hover").removeClass("pseudo-hover");
                    }
                    );
        }

    },

	ServicesPage: {

		loaded: false,

		initialize: function() {
			if ( !this.loaded ) {
                var objServicesPage = this;
				this.menu = $('#services-menu');
				this.holders = this.menu.find('.holder');
                this.menu.find('.col').wrapInner('<div></div>');
                this.menu.find('.col > div').hover($.proxy(this.onMouseEnter, this), $.proxy(this.onMouseLeave, this));

				this.menu.find('.holder a').hover(function(){
					$(this).animate({ marginLeft: '+=5px' }, 100);
				}, function(){
					$(this).animate({ marginLeft: '-=5px' }, 100);
				});
				this.loaded = true;
			}
			this.holders.css('margin-left', '-100%');
		},

		onMouseEnter: function(e) {
			var target = $(e.target);
			var col = $(target).closest('.col');
			var holder = $(col).find('.holder');

			if ( !holder.hasClass('active') ) {
				if ( holder.length && !jQuery.contains(col[0], e.relatedTarget) ) {
					holder.stop().animate({ marginLeft: 0 }, 300);
					holder.addClass('active');
                    holder.closest('.col').find('.pointer').addClass('pointer_active');
				}
			}

		},

		onMouseLeave: function(e) {
			jQuery.each(this.holders, function(index, item){
				if ( $(item).hasClass('active') ) {
					$(item).stop().animate({ marginLeft: -$(item).width() }, 300);
					$(item).removeClass('active');
                    $(item).closest('.col').find('.pointer').removeClass('pointer_active');
				}
			});
		}

	},

    ClientMorePopup: {
        initialize: function() {
            $('.project-requisites .client-more').click($.proxy(function(e) {
                var target = $(e.target);
                var html = $(target).closest('.project-requisites').find('.client-description').html();
                AICMedia.TransparentBackdrop.show($.proxy(this.closeClientWindow, this));
                AICMedia.Window.attach('client-window');
                AICMedia.Window.updateContent(html)
                AICMedia.Window.resize();
                //$('#client-window').hide().fadeIn();
                e.preventDefault();
            }, this));
        },

        closeClientWindow: function() { 
			//AICMedia.Window.currentWindow.fadeOut(function() {
                AICMedia.Window.detach();
                AICMedia.TransparentBackdrop.hide();
            //});
		}
    }
};

$($.proxy(AICMedia.initialize, AICMedia));

function $rand(min, max) {
	return Math.floor(Math.random() * (max - min + 1) + min);
}


