/*_*/

/* Sorry for all the mess in js */
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPod = navigator.userAgent.match(/iPod/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
var isAndroid = navigator.userAgent.match(/android/i) != null;

//$(document).ready(function(){
if(!(isiPad||isAndroid||isiPhone||isiPod)){
	$('head').append('<style type="text/css"> A.b-thumblist-item-in:hover { border-color:#3A3A3A; } A.b-thumblist-item-in:hover .b-thumblist-item-i { visibility:visible; } A.b-thumblist-item-in:hover .b-thumblist-item-top { background-position:0 -359px; } A.b-thumblist-item-in:hover .b-thumblist-item-top-in { background-position:100% -369px; } A.b-thumblist-item-in:hover .b-thumblist-item-bottom { background-position:0 -364px; } A.b-thumblist-item-in:hover .b-thumblist-item-bottom-in { background-position:100% -374px; } </style>');
}
//}
document.documentElement.id = "js";

var isIE6 = navigator.userAgent.contains('MSIE 6.0');

/* Fix for attrNames with gyphen */
Selectors.RegExps.combined = (/\.([\w-]+)|\[([\w-]+)(?:([!*^$~|]?=)(["']?)([^\4]*?)\4)?\]|:([\w-]+)(?:\(["']?(.*?)?["']?\)|$)/g);

        var pBlock = new Class({

                initialize: function(el,initTag){
                        this.el = el;

                        this.onIndex = $$('.b-page_index').length ? true : false;
                        this.onInner = $$('.b-page_inner').length ? true : false;
						this.auto = $$('.b-photolist-auto').length ? true : false;
                        this.fxInProcess = 0;
                        this.fx = new Fx.Tween(this.el,{
                                'duration': 1000,
                                'fps': 30,
                                'link': 'cancel'
                        });

                        /* Some magic for Opera 10.50, however mootools can't determine exactly 10.50 lol */
                        if (Browser.Engine.presto && Browser.Engine.version == '960') {
                                this.fx.addEvent('complete',function() {
                                        if (this.el.getStyle('text-indent') == '0px') {
                                                this.el.setStyle('text-indent','0.01px');
                                        }
                                }.bind(this));
                        }
                        /* end magic */

                        // Init Items & state
                        this.items = [];
                        this.initState = [];
                        this.byId = new Hash();
						
                        this.el.getElements('.b-photolist-item').each(function(item,index) {
																			 
                                var blockItem = new Hash({
                                        el: item,
                                        index: index,
                                        id: item.get('id')
                                });
                                this.byId[blockItem.id] = index;
                                item.removeProperty('id');
                                this.items.push(blockItem);
                                this.initState[index] = index;
                        }.bind(this));

                        this.state = $A(this.initState);

                        this.current = this.items[0];

                        // Create Nav
                        this.nav = new Element('span',{
                                'class':'b-photolist-nav-in',
                                'html':'<span class="b-photolist-nav-l"><span class="b-photolist-nav-l-in"></span></span><span class="b-photolist-nav-r"><span class="b-photolist-nav-r-in"></span></span>'
                        })

                        this.nav.addEvents({
                                'disable': function() {
                                        this.addClass('js-invisible');
                                },
                                'enable': function() {
                                        this.removeClass('js-invisible');
                                }
                        });

                        this.wrap = this.el.getParent();
                        this.wrap.addEvents({
                                'disable': function() {
                                        this.addClass('js-hidden');
                                },
                                'enable': function() {
                                        this.removeClass('js-hidden');
                                }
                        });
                        this.prev = new Element('span',{
                                'class':'b-button b-button-prev',
                                'title':'Предыдущая или стрелка <- на клавиатуре',
                                'html':'<span class="b-button-i"></span><span class="b-button-ico">?<span class="b-button-ico-in"></span></span>'
                        }).inject(this.nav);

                        if (this.onIndex || this.onInner) {
                                this.items.each(function(item,index){
                                        item.dotWrap = new Element('span',{
                                                'class':'b-photolist-nav-item-wrap'
                                        }).inject(this.nav);
                                        item.dot = new Element('span',{
                                                'class':'b-photolist-nav-item',
                                                'html':'<span class="b-photolist-nav-item-i"></span>'
                                        }).inject(item.dotWrap);
                                        item.dotThumb = new Element('span',{
                                                'class':'b-photolist-nav-item-thumb',
                                                'html':'<span class="b-photolist-nav-item-thumb-i"></span>'
                                        }).inject(item.dotWrap);
                                        item.dotThumb.setStyle('background-image','url(' + item.el.getElement('img').get('rel') + ')');
                                

                                        if (!Browser.Engine.trident) {
                                                item.dotFx = new Fx.Tween(item.dotThumb,{
                                                        'duration': 240,
                                                        'fps': 30,
                                                        'link': 'cancel'
                                                });

                                                item.dotFx2 = new Fx.Tween(item.dotThumb,{
                                                        'duration': 240,
                                                        'fps': 30,
                                                        'link': 'cancel'
                                                });
                                                item.dotFx.set('opacity', 0);
                                                item.dotFx2.set('top', -100);
                                        }
                                        /* Maybe change to the same ext or any ohter */
                                        item.dotWrap.addEvents({
                                                'click': function() {
                                                        if (this.current.index != item.index) {
                                                                this.goTo(item.index);
                                                        }
                                                        if (!Browser.Engine.trident) {
                                                                item.dotFx.start('opacity', 0);
                                                                item.dotFx2.start('top', -100);
                                                        } else {
                                                                item.dotThumb.setStyle('display','none');
                                                        }
                                                }.bind(this),
                                                'disable': function() {
                                                        item.dot.removeClass('b-photolist-nav-item-current');
                                                },
                                                'enable': function() {
                                                        item.dot.addClass('b-photolist-nav-item-current');
                                                },
                                                'mouseenter': function() {
                                                        if (!Browser.Engine.trident && this.current.index != item.index) {
                                                                item.dotFx.start('opacity', 1);
                                                                item.dotFx2.start('top', -76);
                                                        } else if (Browser.Engine.trident) {
                                                                item.dotThumb.setStyle('display','block');
                                                        }
                                                }.bind(this),
                                                'mouseleave': function() {
                                                        if (!Browser.Engine.trident && this.current.index != item.index) {
                                                                item.dotFx.start('opacity', 0);
                                                                item.dotFx2.start('top', -100);
                                                        } else if (Browser.Engine.trident) {
                                                                item.dotThumb.setStyle('display','none');
                                                        }
                                                }.bind(this)
                                        });

                                        item.el.addEvents({
                                                'disable': function() {
                                                        item.el.addClass('js-hidden');
                                                        item.dot.addClass('js-hidden');
                                                },
                                                'enable': function() {
                                                        item.el.removeClass('js-hidden');
                                                        item.dot.removeClass('js-hidden');
                                                }
                                        });
                                }.bind(this));








                        }








                        this.next = new Element('span',{
                                'class':'b-button b-button-next',
                                'title':'Следующая или стрелка -> на клавиатуре',
                                'html':'<span class="b-button-i"></span><span class="b-button-ico">?<span class="b-button-ico-in"></span></span>'
                        }).inject(this.nav);
						
						if(this.auto){
							
						 this.playpause = new Element('span',{
                                'class':'b-button b-button-playpause ',
                                'title':'Прервать/Продолжить '
                                
                        }).inject(this.nav);
						 var play = true
						 this.playpause.addEvents({
                                'click': function() {
									
									if(play){
										play=false
                                        clearInterval(tt);
										
										this.playpause.className += ' playpause-pause'; 
									} else {
										play=true
										autos();
										 this.playpause.className = this.playpause.className.replace('playpause-pause','');
									}
										
                                }.bind(this)
                        });
						 
						 
						}

                        //                this.nav.inject(new Element('span',{ 'class':'b-photolist-nav' }).inject(this.el,'after'));

                        if (!this.onInner) this.nav.inject(new Element('span',{
                                'class':'b-photolist-nav'
                        }).inject(this.el,'after'));

                        /* Extra controls if not on Index */
                        if (this.onInner) {
                        //                                this.slideshow = new Element('span',{
                        //                                        'class':'b-button b-button-pause',
                        //                                        'title':'Iinoaaeou ia iaoco',
                        //                                        'html':'<span class="b-button-i"></span><span class="b-button-ico"><span class="b-button-ico-in"></span></span>'
                        //                                }).inject(this.el.getParent());
                        /*  this.toThumbs = new Element('span',{
                                        'class':'b-button-all'
                                }).inject(this.el.getParent());*/
                        /*  this.slideshow.addEvents({
                                        'click': function() {
                                                this.slideshow.toggleClass('b-button-pause').toggleClass('b-button-play');
                                                alert('Ooieoeiiaeuiinou neaeaoio au? ia aioiaa');
                                        }.bind(this)
                                });*/
                        /* this.toThumbs.addEvents({
                                        'click': function() {
                                                $$('.b-thumblist')[0].removeClass('js-off');
                                                $$('.b-gallery')[0].addClass('js-off');
                                                $$('.b-subnav').setStyle('height',$$('.b-box-in')[0].getSize().y);
                                                HistoryManager.setState('');
                                        }.bind(this)
                                });*/
                        }

                        /* set width of nav */
                        this.nav.setStyles({
                                'width': this.items.length * 20 + 36 + 'px',
                                'marginLeft': -(this.items.length * 20 + 36)/2 + 'px'
                        });

                        // Next&Prev events
                        this.prev.addEvents({
                                'click': function() {
                                        if (!this.isFirst(this.current.index)) {
                                                this.goTo(this.state[this.state.indexOf(this.current.index) - 1]);
                                        } else {
                                                this.goTo(this.state[this.state.length-1]);
                                        }
                                }.bind(this)/*,
			'disable': function() {
				this.addClass('b-button_disabled');
			},
			'enable': function() {
				this.removeClass('b-button_disabled');
			}*/
                        });
                        this.next.addEvents({
                                'click': function() {
                                        if (!this.isLast(this.current.index)) {
                                                this.goTo(this.state[this.state.indexOf(this.current.index) + 1]);
                                        } else {
                                                this.goTo(this.state[0]);
                                        }
                                }.bind(this)/*,
			'disable': function() {
				this.addClass('b-button_disabled');
			},
			'enable': function() {
				this.removeClass('b-button_disabled');
			}*/
                        });
						var tt;
						if(this.auto){
						var gg = this
						function autos(){
						
						tt=setInterval(function(){	
									 if (!gg.isLast(gg.current.index)) {
                                                gg.goTo(gg.state[gg.state.indexOf(gg.current.index) + 1]);
                                        } else {
                                                gg.goTo(gg.state[0]);
                                        }
								},8000);
						}
						autos();
						
						}
						if(this.auto){
						 	/*$$('.b-photolist-image').addEvents({
							'click' : function(){
						
							 	if (!this.isLast(this.current.index)) {
                                                this.goTo(this.state[this.state.indexOf(this.current.index) + 1]);
                                        } else {
                                                this.goTo(this.state[0]);
                                        }
										return false;
										
							}.bind(this)
							
							})	*/
							
							jQuery(window).bind('keydown',function(e){
				
									if(e.keyCode==39){
											if(!gg.isLast(gg.current.index)) {
                                                gg.goTo(gg.state[gg.state.indexOf(gg.current.index) + 1]);
                                        } else {
                                                gg.goTo(gg.state[0]);
                                        }
									} else if(e.keyCode==37){
										 if (!gg.isFirst(gg.current.index)) {
                                                gg.goTo(gg.state[gg.state.indexOf(gg.current.index) - 1]);
                                        } else {
                                                gg.goTo(gg.state[gg.state.length-1]);
                                        }
									}
							})
							
						 
						 
						} else {
							 $$('.b-photolist-image').addEvents({
								'click' : function(){
							
								location.href = $$('.b-button-next').get('lnk');
								return false;
											
							}.bind(this)
							})	
							 
							 
							jQuery(window).bind('keydown',function(e){
				
									if(e.keyCode==39){
											location.href = $$('.b-button-next').get('lnk');
									} else if(e.keyCode==37){
										 location.href = $$('.b-button-prev').get('lnk');
									}
							}) 
							 
						}
						
						
						
						
						
                        this.history = HistoryManager.register(
                                '',
                                [''],
                                function(values) {
                                        if ($chk(this.byId[values[0]])) {
                                                this.setTo(this.byId[values[0]]);
                                        } else {
                                        //					$$('.b-gallery')[0].addClass('js-off');
                                        //					$$('.b-thumblist')[0].removeClass('js-off');
                                        //					$$('.b-subnav').setStyle('height',$$('.b-box-in')[0].getSize().y);
                                        }
                                        this.history.setValue('');
                                }.bind(this),
                                function(values) {
                                        return values[0];
                                }.bind(this),
                                '(.+)'
                                ); 

                        if (this.inInner) {
                                var startItem = top.location.href.replace(/[^#]+(#Item)?(\d*)/,'$2') || 0;
                                if (startItem) {
                                        this.setTo(startItem);
                                }
                        } else {
                                this.setTo(0);
                        }

                },

                isFirst: function(index, where) {
                        if ($chk(where)){
                                return where.indexOf(index) == 0;
                        } else {
                                return this.state.indexOf(index) == 0;
                        }
                },

                isLast: function(index, where) {
                        if ($chk(where)){
                                return where.indexOf(index) + 1 == where.length;
                        } else {
                                return this.state.indexOf(index) + 1 == this.state.length;
                        }
                },

                check: function(where){
                        var from = this.current.index;

                        this.el.scrollLeft = 0;

                        if ($$('.b-gallery')[0] && $$('.b-gallery')[0].hasClass('js-off')) {
                                $$('.b-thumblist')[0].addClass('js-off');
                                $$('.b-gallery')[0].removeClass('js-off');
                        }

                        if (this.onIndex || this.onInner) {
                                this.items[from].dotWrap.fireEvent('disable');
                                this.items[where].dotWrap.fireEvent('enable');
                        }
                        if (this.isFirst(from)) {
                                this.prev.fireEvent('enable');
                        }
                        if (this.isLast(from)) {
                                this.next.fireEvent('enable');
                        }
                        if (this.isFirst(where)) {
                                this.prev.fireEvent('disable');
                        }
                        if (this.isLast(where)) {
                                this.next.fireEvent('disable');
                        }

                        this.current = this.items[where];

                //$$('.b-subnav').setStyle('height',$$('.b-box-in')[0].getSize().y);
                },

                setTo: function(where){
                        if ($chk(where)) {
							
                                this.check(where);
                                this.fx.set('text-indent', - where * this.el.getSize().x);
                        }
                },

                goTo: function(where){
                        if ($chk(where)) {
                                this.check(where);
                                var $img = $$('.b-photolist li')[where].getElements('img');
								if($$('.b-photolist li')[where+1]!=undefined){
									var $imgNext = $$('.b-photolist li')[where+1].getElements('img');
									
									$imgNext.set({
                                        'src': $imgNext.get('presrc')
                                      });
									
								}
                                $img.set({
                                        'src': $img.get('presrc')
                                        });
								
                                this.fx.start('text-indent', - this.state.indexOf(where) * this.el.getSize().x);
                                if (this.onInner) {
                                        HistoryManager.setState(this.current.id);
                                }
                        }
                }
        });

        window.addEvent('domready', function() {
                var isIndex = $$('.b-page_index').length ? true : false;
                var isInner = $$('.b-page_inner').length ? true : false;

                if (isInner) {
                        HistoryManager.initialize();
                }

                var fixNav = function() {
                        /* OMGWTFBBQ Safari???11111oneoneone */
                        if (Browser.Engine.webkit) {
                        /* setTimeout(function() {
                                        $$('.b-subnav').setStyle('height',$$('.b-box-in')[0].getSize().y);
                                }, 50);*/
                        } else {
							
                // $$('.b-subnav').setStyle('height',$$('.b-box-in')[0].getSize().y);
                }
                }

                /* Init of scrollers */
                if ($$('.b-photolist')[0]) {
                        $$('.b-photolist').each(function(el) {
                                el.pictures = new pBlock($$('.b-photolist')[0]);
                        });
                        $$('.b-photolist-image').setStyle('visibility','hidden')
                        /* resizing (must move to pictures) */
                        if (isIndex || isInner) {
                                var imgWrap = $$('.b-photolist-in,.b-photolist-item');
                                var winHeight = document.documentElement.clientHeight;
                                var paddings = isIndex ? 204 : 280;

                                var chkBox = function() {
                                      //  var boxMax = (winHeight - paddings).limit(480,900);
                                       // var boxMin = (winHeight - paddings).limit(380,boxMax);
                                        //                                        imgWrap.setStyle('height',boxMax);
                                       // imgWrap.setStyle('height',900);
                                        $$('.b-photolist-image').each(function(item,index) {
                                                //                                                var imgSize = item.getSize().y || item.getProperty('height');
                                                //                                                if (imgSize > boxMax) {
                                                //                                                        item.setStyle('marginTop',-parseInt((imgSize-boxMax)/2,10));
                                                //                                                } else if (imgSize <= boxMin) {
                                                //                                                        item.setStyle('marginTop',parseInt((boxMax-imgSize)/2,10));
                                                //                                                }
                                                item.setStyle('marginTop',0);
                                        });
                                        fixNav();
                                }
                                chkBox();
                                window.addEvent('load',function(){
                                        $$('.b-photolist-image').setStyle('visibility','');
                                        chkBox();
                                });
                                window.addEvent('resize', function() {
                                        if (document.documentElement.clientHeight != winHeight) {
                                                chkBox();
                                        }
                                        winHeight = document.documentElement.clientHeight;
                                        var pictures = $$('.b-photolist')[0].pictures;
                                        pictures.el.setStyle('text-indent',-pictures.current.index * pictures.el.getSize().x + 'px'); /* fixing position (move to class later) */
                                });
                        } else {
                                window.addEvent('resize', function() {
                                        fixNav();
                                });
                        }
                } else {
                        window.addEvent('resize', function() {
                                fixNav();
                        });
                }

                var tt;
                /* Subnav */
                var showSubnav = function (el) {
                        tt = setTimeout(function(){
                                //alert(el.getParent().length)
                                //el.getParent().setStyle({'display':'block'});
                                var subnav = el.getChildren('.b-subnav')[0];
                                subnav.setStyle('display','block');
                                el.myFx1.start('opacity', 1);
                                el.myFx2.start('paddingTop', 34);
                        },300);
                }

                var hideSubnav = function (el) {
                        clearTimeout(tt)
                        var subnav = el.getChildren('.b-subnav')[0];
                        subnav.setStyle('display','none');
                        el.myFx1.set('opacity', 0);
                        el.myFx2.set('paddingTop', 0);
                }
				$$('.b-nav').removeClass('b-nav-nav');
                $$('.b-nav-item_tree').each(function(el) {
                        var subnav = el.getChildren('.b-subnav')[0];
                        el.myFx1 = new Fx.Tween(subnav.getChildren('.b-subnav-in')[0],{
                                'duration': 150,
                                'fps': 30,
                                'link': 'cancel'
                        });
                        el.myFx2 = new Fx.Tween(subnav.getChildren('.b-subnav-in')[0],{
                                'duration': 150,
                                'fps': 30,
                                'link': 'cancel'
                        });
                        el.addEvents({
                                'mouseenter': function() {
                                        showSubnav(el);
										el.setStyle('zIndex',11)
                                },
                                'mouseleave': function() {
                                        hideSubnav(el);
										el.setStyle('zIndex',9)
                                }
                        });
                        el.getChildren('.b-nav-item-in')[0].addEvents({
                                'focus': function() {
                                        showSubnav(el);
                                },
								 'click': function() {
									if(isiPad||isAndroid||isiPhone||isiPod){
										if (!($(this).closest('.b-nav-item').find('.b-subnav:visible').html())){
											showSubnav(el);
											return false;
										}
									 }
                                }
                        });
                }.bind(this));

                /* init thumbs gallery */
                $$('.b-thumblist-item-img').each(function(el,index) {


                        var link = el.getParent();
                        link.setStyle('background-image','url('+ el.get('src') +')')
                        if(link.get('backgrcolor')=='1')
                                link.setStyle('background-color','#000')
                        el.setStyle('opacity','0');
                        /*if ($$('.b-photolist')[0]) {
                                var pictures = $$('.b-photolist')[0].pictures;
                                if (pictures) {
                                        link.addEvent('click', function() {
                                                pictures.setTo(index);
                                                HistoryManager.setState(pictures.current.id);
                                                fixNav();
                                                return false;
                                        });
                                }
                        }*/
                });


                if (isInner && $$('.b-photolist')[0]) {





                    





                        /* Gallery tools animation */
                        //            var galTools = new Element('ul',{
                        //                'class':'b-gallery-tools',
                        //                'html':'<li class="b-gallery-tool"><i class="b-gallery-tool-l"><i class="b-gallery-tool-l-in"></i></i><i class="b-gallery-tool-ico b-gallery-tool-ico_descr"></i><span class="b-gallery-tool-in">Iienaiea</span><i class="b-gallery-tool-r"><i class="b-gallery-tool-r-in"></i></i></li><li class="b-gallery-tool"><i class="b-gallery-tool-l"><i class="b-gallery-tool-l-in"></i></i><i class="b-gallery-tool-ico b-gallery-tool-ico_like"></i><span class="b-gallery-tool-in">A eca?aiiia</span><i class="b-gallery-tool-r"><i class="b-gallery-tool-r-in"></i></i></li><li class="b-gallery-tool"><i class="b-gallery-tool-l"><i class="b-gallery-tool-l-in"></i></i><i class="b-gallery-tool-ico b-gallery-tool-ico_print"></i><span class="b-gallery-tool-in">Ia?aou</span><i class="b-gallery-tool-r"><i class="b-gallery-tool-r-in"></i></i></li>'
                        //            }).inject($$('.b-gallery')[0]);

                        /* Showing/hiding description */
                        //            if (Cookie.read('showDescription') == 1) { /* cookie! */
                        //                if (!Browser.Engine.trident) {
                        //                    $$('.b-photolist-descr').setStyles({
                        //                        'opacity': 1,
                        //                        'visibility': 'visible'
                        //                    });
                        //                } else {
                        //                    $$('.b-photolist-descr').setStyles({
                        //                        'display': 'block'
                        //                    });
                        //                }
                        //            } else {
                        //                if (!Browser.Engine.trident) {
                        //                    $$('.b-photolist-descr').setStyles({
                        //                        'opacity': 0,
                        //                        'visibility': 'hidden'
                        //                    });
                        //                } else {
                        //                    $$('.b-photolist-descr').setStyles({
                        //                        'display': 'none'
                        //                    });
                        //                }
                        //            }

                        //            if (!Browser.Engine.trident) {
                        //                $$('.b-photolist-descr').each(function(el) {
                        //                    el.desrNavFx = new Fx.Tween(el,{
                        //                        'duration': 180,
                        //                        'fps': 30,
                        //                        'link': 'cancel'
                        //                    }).addEvent('complete',function() {
                        //                        if (el.getStyle('opacity')==1) {
                        //                            $$('.b-photolist-descr').setStyles({
                        //                                'opacity': 1,
                        //                                'visibility': 'visible'
                        //                            });
                        //                        } else {
                        //                            $$('.b-photolist-descr').setStyles({
                        //                                'opacity': 0,
                        //                                'visibility': 'hidden'
                        //                            });
                        //                        }
                        //                    });
                        //                });
                        //            }

                        $$('.b-gallery-tool-ico_descr').getParent('.b-gallery-tool').addEvents({
                                'click': function() {
                                        var mustShow = $$('.b-photolist-descr')[$$('.b-photolist')[0].pictures.current.index].getStyle('opacity')==0?1:0;
                                        if (Browser.Engine.trident) {
                                                mustShow = $$('.b-photolist-descr')[0].getStyle('display')=='none'?1:0;
                                        }

                                        if (!Browser.Engine.trident) {
                                                $$('.b-photolist-descr')[$$('.b-photolist')[0].pictures.current.index].desrNavFx.start('opacity', mustShow);
                                        } else {
                                                $$('.b-photolist-descr').setStyles({
                                                        'display': (mustShow?'block':'none')
                                                });
                                        }
                                        Cookie.write('showDescription',mustShow);
                                }
                        });

                        HistoryManager.start();
                }

                /* Expanding buttons */
                $$('.b-gallery-tool').each(function(el) {
                        var item = el.getChildren('.b-gallery-tool-in')[0];
                        el.itemFx = new Fx.Tween(item,{
                                'duration': 120,
                                'fps': 30,
                                'link': 'cancel'
                        })

                        /* Some magic for Safari -_- */
                        var width = item.getSize().x + 9;
                        var nul = 0;
                        if (Browser.Engine.webkit) {
                                nul = 1;
                                item.setStyle('display','none');
                                el.itemFx.addEvents({
                                        'complete': function() {
                                                if (item.getStyle('width') == '1px') {
                                                        item.setStyle('display','none');
                                                }
                                        },
                                        'start': function(){
                                                if (item.getStyle('width') == '1px') {
                                                        item.setStyle('display','block');
                                                }
                                        }
                                });
                        }
                        /* end magic */

                        el.itemFx.set('width',nul);
                        el.addEvents({
                                'mouseenter': function() {
                                        el.itemFx.start('width', width);
                                },
                                'mouseleave': function() {
                                        el.itemFx.start('width', nul);
                                }
                        });
                });

                /* Showing/hiding navigation */
                if (isIndex && !Browser.Engine.trident && $$('.b-photolist').length) {
						
                        var plNavFx = new Fx.Tween($$('.b-photolist')[0].pictures.nav,{
                                'duration': 180,
                                'fps': 30,
                                'link': 'cancel'
                        });
                        plNavFx.set('opacity', 0);
                        $$('.b-content').addEvents({
                                'mouseenter': function() {
                                        plNavFx.start('opacity', 1);
                                },
                                'mouseleave': function() {
                                        plNavFx.start('opacity', 0);
                                }
                        });
                }

                /* Show extra 10 items on thumblist */
                $$('.b-thumblist-in').each(function(el) {
                        var extras = el.getElements('.b-thumblist-item.js-none');
						
                        if (extras.length) {
                                var more = new Element('li',{
                                        'class':'b-thumblist-item',
                                        'html':'<a class="b-thumblist-item-in"><i class="b-thumblist-item-i"></i><b class="b-thumblist-item-top"><b class="b-thumblist-item-top-in"></b></b><span class="b-thumblist-item-more">вЂ¦</span><img class="b-thumblist-item-img" src="/i/0.gif" alt="" /><b class="b-thumblist-item-bottom"><b class="b-thumblist-item-bottom-in"></b></b></a>'
                                }).inject(el);
                                more.addEvent('click',function() {
                                        var i = 0;
                                        var extras = el.getElements('.b-thumblist-item.js-none');
                                        extras.each(function(item) {
                                                if (i++<8) {
                                                        item.removeClass('js-none');
                                                }
                                        })
                                        if (extras.length < 10) {
                                                this.destroy();
                                        }
                                        fixNav();
                                });
                        }
                })

                /* Show extra 10 items on publications*/
                var pubItems = $$('.b-publication.js-none');

                if (pubItems.length) {
                        var pubMore = new Element('p',{
                                'class':'b-publications-more',
                                'text':'Iieacaou aua ' + pubItems.length.limit(0,10) + 'вЂ¦'
                        }).inject(pubItems[0].getParent());
                        pubMore.addEvent('click',function() {
                                var i = 0;
                                var pubItems = $$('.b-publication.js-none');
                                pubItems.each(function(item) {
                                        if (i++<8) {
                                                item.removeClass('js-none');
                                        }
                                })
                                if (pubItems.length < 10) {
                                        this.destroy();
                                } else {
                                        pubMore.set('text','Iieacaou aua ' + $$('.b-publication.js-none').length.limit(0,10) + 'вЂ¦')
                                }
                                fixNav();
                        });
                }

                /* Accordion Expander */
                if ($$('.b-expander-handle')[0] && $$('.b-expander-handle+.b-expander-content')[0]) {
                        $$('.b-expander-handle').each(function(el) {
                                el.expanderFx = new Fx.Tween(el,{
                                        'link': 'cancel'
                                });
                                el.expanderFx2 = new Fx.Tween(el,{
                                        'link': 'cancel'
                                });

                        });
                        var needFx = false;
                        var Expander = new Fx.Accordion($$('.b-expander-handle'), $$('.b-expander-handle+.b-expander-content'),{
                                'initialDisplayFx': false,
                                'onActive': function(handle,content){
                                        if (needFx) {
                                                handle.expanderFx.start('font-size',24);
                                                handle.expanderFx2.start('left',-32);
                                        } else {
                                                handle.expanderFx.set('font-size',24);
                                                handle.expanderFx2.set('left',-32);
                                        }
                                        handle.removeClass('b-expander-handle_inactive').addClass('b-expander-handle_active');
                                        content.removeClass('b-expander-content_inactive').addClass('b-expander-content_active');
                                },
                                'onBackground': function(handle,content){
                                        if (needFx) {
                                                handle.expanderFx.start('font-size',18);
                                                handle.expanderFx2.start('left',-16);
                                        } else {
                                                handle.expanderFx.set('font-size',18);
                                                handle.expanderFx2.set('left',-16);
                                        }
                                        handle.addClass('b-expander-handle_inactive').removeClass('b-expander-handle_active');
                                        content.addClass('b-expander-content_inactive').removeClass('b-expander-content_active');
                                },
                                'onComplete': function(handle){
                                        fixNav();
                                }
                        });
                        needFx = true;
                }

                /* Almanac Accordion */
                if ($$('.b-almanac-nav-handle')[0] && $$('.b-almanac-nav-handle+.b-almanac-nav-content')[0]) {

                        $$('.b-almanac-nav').each(function(el) {
                                var n = parseInt(el.getAttribute('data-active'));
                                el.AlmanacExpander = new Fx.Accordion(el.getElements('.b-almanac-nav-handle'), el.getElements('.b-almanac-nav-handle+.b-almanac-nav-content'),{
                                        'display': n,
                                        'initialDisplayFx': false,
                                        'onActive': function(handle,content){
                                                handle.addClass('b-almanac-nav-handle_active');
                                        },
                                        'onBackground': function(handle,content){
                                                handle.removeClass('b-almanac-nav-handle_active');
                                        },
                                        'onComplete': function(handle){
                                                fixNav();
                                        }
                                });
                        });
                }

                /* Almanac Years Accordion */
                if ($$('.b-almanac-nav-year')[1]) {
                        var YearsExpander = new Fx.Accordion($$('.b-almanac-nav-year'), $$('.b-almanac-nav'),{
                                'initialDisplayFx': false,
                                'height': false,
                                'opacity': false,
                                'onActive': function(handle,content){
                                        handle.addClass('b-almanac-nav-year_active');
                                        content.removeClass('js-none');
                                },
                                'onBackground': function(handle,content){
                                        handle.removeClass('b-almanac-nav-year_active');
                                        content.addClass('js-none');
                                },
                                'onComplete': function(handle){
                                        fixNav();
                                }
                        });
                }

                if ($('Auth')) {
                        if(top.location.href.contains('#Auth')) {
                                $('Auth').removeClass('js-hidden');
                                $$('#Auth .b-popup')[0].setStyle('margin-top',parseInt(-$$('#Auth .b-popup')[0].getSize().y/2,10))
                                $$('#Auth INPUT')[0].focus();
                        }
                        /* Auth window opener */
                        $$('.b-mini-button_auth').addEvent('click', function() {
                                $('Auth').removeClass('js-hidden');
                                $$('#Auth .b-popup')[0].setStyle('margin-top',parseInt(-$$('#Auth .b-popup')[0].getSize().y/2,10))
                                $$('#Auth INPUT')[0].focus();
                                return false;
                        });

                        /* Auth window closers */
                        document.addEvent('keydown', function(event){
                                if (event.key == "esc") {
                                        $('Auth').addClass('js-hidden');
                                }
                        });
                /*

		$('Auth').addEvent('click', function(event) {
			if(event.target.className.contains('b-overlay')) {
				$('Auth').addClass('js-hidden');
			}
		});

		$$('#Auth .b-popup-close').addEvent('click', function() {
			$('Auth').addClass('js-hidden');
		});

                */
                }

                /* Overtexts */
                if ($$('#FavEmail').length) {
                        new OverText($('FavEmail'));
                }
                if ($$('#FavPhone').length) {
                        new OverText($('FavPhone'));
                }

                /* Deleting Favorites */
                $$('.b-thumblist_deletable .b-thumblist-item').each(function(el) {
            
                        if (!el.getElement('.b-thumblist-item-more')) {
                                el.deleter = new Element('span',{
                                        'class':'b-thumblist-item-deleter',
                                        'text':'Oaaeeou'
                                }).inject(el);

                                el.deleter.addEvent('click',function() {
                                        /* Must delete only after correct ajax delete request */
                                        if (true) {
                                                var parent = el.getParent();
                                                var extras = parent.getElements('.b-thumblist-item.js-none');
                                                if (extras.length) {
                                                        if (extras.length > 2) {
                                                                extras[0].removeClass('js-none');
                                                        }
                                                        if (extras.length <= 2) {
                                                                parent.getElement('.b-thumblist-item:last-child').destroy();
                                                                parent.getElements('.b-thumblist-item.js-none').removeClass('js-none');
                                                        }
                                                }
                                                var globalCounter = $$('.b-notification-header-count')[0] || $$('.b-button-fav-counter-inin')[0];
                                                var newCount = globalCounter.get('text')-1;
                                                globalCounter.set('text',newCount);
                                                $$('.b-button-fav-counter-inin')[0].set('text',newCount);

                                                var counter = parent.getPrevious().getElement('.b-thumblist-header-count');
                                                if (counter.get('text') > 1) {
                                                        counter.set('text',counter.get('text')-1);
                                                } else {
                                                        counter.getParent().getParent().destroy();
                                                        el.destroy();
                                                        parent.destroy();
                                                }
                                                el.destroy();
                                        }
                                });

                                el.delFx = new Fx.Tween(el.deleter,{
                                        'duration': 240,
                                        'fps': 30,
                                        'link': 'cancel'
                                });

                                el.delFx2 = new Fx.Tween(el.deleter,{
                                        'duration': 240,
                                        'fps': 30,
                                        'link': 'cancel'
                                });
                                el.delFx.set('opacity', 0);
                                el.delFx2.set('bottom', 0);

                                el.addEvents({
                                        'mouseenter': function() {
                                                el.delFx.start('opacity', 1);
                                                el.delFx2.start('bottom', -20);
                                        },
                                        'mouseleave': function() {
                                                el.delFx.start('opacity', 0);
                                                el.delFx2.start('bottom', 0);
                                        }
                                });
                        }
                });

                /* Search usable submit */
                var $search = $$('#Search');
                function searchCheck() {
                        if ($search.get('value') == '') {
                                $search.getParent().getParent().addClass('b-search_empty');
                        } else {
                                $search.getParent().getParent().removeClass('b-search_empty');
                        }
                }
                $search.addEvents({
                        'keyup' : function() {
                                searchCheck();
                        },
                        'change' : function() {
                                searchCheck();
                        },
                        'click' : function() {
                                searchCheck();
                        }
                });
                searchCheck();

                /* Advanced search link */
                if ($$('.b-search-link-ext').length) {
                        var extSearchFx = new Fx.Tween($$('.b-search-link-ext')[0],{
                                'duration': 240,
                                'fps': 30,
                                'link': 'cancel'
                        });
                        $$('.b-header form')[0].addEvents({
                                'mouseenter': function() {
                                        extSearchFx.start('top', 52);
                                },
                                'mouseleave': function() {
                                        extSearchFx.start('top', 35);
                                }
                        });

                }

                /* Accordion Collapser */
                if ($$('.b-collapser-head')[0] && $$('.b-collapser-head+.b-collapser-content')[0]) {
                        var YearsExpander = new Fx.Accordion($$('.b-collapser-head'), $$('.b-collapser-head+.b-collapser-content'),{
                                'initialDisplayFx': false,
                                'link': 'cancel',
                                'onActive': function(handle){
                                        handle.removeClass('b-collapser-head_inactive');
                                },
                                'onBackground': function(handle){
                                        handle.addClass('b-collapser-head_inactive');
                                },
                                'onComplete': function(handle){
                                        fixNav();
                                }
                        });
                }


                fixNav();


        //        $('.b-photolist-nav-item-i').each(callback, args)
        


        });
        //







        function CheckEmail(data) { // i?iaa?ea ei??aeoiinoe email
                return /^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9.]+$/.test(data);
        }

        function checkdigits(data)
        {
                return  (/^\d+$/.test(data)) && (data>0);
        }



        function trim(str, chars) {
                return ltrim(rtrim(str, chars), chars);
        }

        function ltrim(str, chars) {
                chars = chars || "\\s";
                return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
        }

        function rtrim(str, chars) {
                chars = chars || "\\s";
                return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
        }






		
        jQuery(function() {
						
				
			
						
						
                $('.b-photolist-nav-item').mouseover(function(){
                        rel=$(this).attr('rel');
                        $('.viewpic'+rel).show();
                }).mouseout(function(){
                        $('.viewpic'+rel).hide();
                });


			
                $('.b-photolist-nav-item, .b-button-prev, .b-button-next, .b-button-all').click(function(){

                        lnk=$(this).attr('lnk');
                        if (lnk) window.location.href=lnk;
                })
        
                $('#favor').click(function(){
                        id=$(this).attr('rel');
                        infav=$(this).attr('dir1');
                        if (infav=='infav') {
                                $('#allreadyinfav').show();

//                                $.ajax({
//                                        type: "POST",
//                                        url: "/application/views/rosbri/infoblocks/favorite/ajax.php",
//                                        data: "action=remove&id="+id,
//                                        success: function(msg){
//                                                if (msg==0) {
//                                                        $('.b-button-fav-counter-in').html('');
////                                                        $('.b-button-fav').hide();
//                                                        $('.selected').hide();
//                                                } else {
//                                                        $('a.selected').show();
//                                                        $('.b-button-fav-counter-in').html('<span class="b-button-fav-counter-inin">'+msg+'</span>');
//                                                }
//                                                //                        $('.b-button-fav-counter-in').html('<span class="b-button-fav-counter-inin">'+msg+'</span>');
//                                                $('#favor').attr('dir1','');
//                                                $('#favor img').attr('src','/application/views/rosbri/images/favor.png');
//
//                                                $('.b-overlay').hide();
//                                                $('#cbok').hide();
//                                                $('.b-fieldsnull input').val('');
//                                                return false;
//
//
//                                        }
//                                });
                        } else {
                                $.ajax({
                                        type: "POST",
                                        url: "/application/views/rosbri/infoblocks/favorite/ajax.php",
                                        data: "action=add&id="+id,
                                        success: function(msg){

                                                

                                                $('.b-button-fav-counter-in').html('<span class="b-button-fav-counter-inin">'+msg+'</span>');

                                                $('.selected').show();
                                                $('.selected').attr('style','position:absolute; right:50%;  top:25px;');

//                                                $('.b-button-fav').show();
//                                                $('#favor img').attr('src','/application/views/rosbri/images/favor_act.png');
                                                $('#favor').attr('dir1','infav');

                                                $('.b-overlay').hide();
                                                $('#cbok').hide();
                                                $('.b-fieldsnull input').val('');
                                                return false;
                                        }
                                });
                        }
                        return false;
            
                })


                $('.b-thumblist-item').bind("mouseenter",function(){
                        id=$(this).attr('rel');
                        $('.outfav'+id).show('slow');
                }).bind("mouseleave",function(){
                        $('.outfav'+id).hide('slow');
                });


                $('.b-thumblist-item-deleter').live('click',function(){
                        var id=$(this).attr('rel');
                        $.ajax({
                                type: "POST",
                                url: "/application/views/rosbri/infoblocks/favorite/ajax.php",
                                data: "action=remove&id="+id,
                                success: function(msg){
                                        if (msg==0) {
                                                $('.b-button-fav-counter-in').html('');
//                                                $('.b-thumblist_deletable').html('<div style="color: white; padding:10px 16px;">Нет отобранных товаров</div>');
                                                $('.b-thumblist_deletable').html('<div style="color: white; padding:10px 16px;"></div>');
                                                $('.b-thumblist_deletable').css('background-color','#313127');
//                                                $('.b-button-fav').hide();
                                                $('.selected').hide();
                                                $('.b-notification-header').html('Отложенные вами товары отсутствуют. Чтобы отложить товар, воспользуйтесь кнопкой \"Узнать цену\" на странице товара');


                                        } else {
                                                $('.b-button-fav-counter-in').html('<span class="b-button-fav-counter-inin">'+msg+'</span>');
                                                $('.b-notification-header-count').html(msg);
                                        }
                                        $('.b-thumblist-item[rel='+id+']').hide();
                                }
                        });
                        return false;
                })


                $(".ico_descr").click(function(){
                        if($.cookie("RosbriDescrView") && $.cookie("RosbriDescrView")==1) {
                                $('.b-photolist-descr').hide();
//                                $('.b-photolist-descr-2').hide();
                                $.cookie("RosbriDescrView", 0);
                        } else {
                                $('.b-photolist-descr').show();
//                                $('.b-photolist-descr-2').show();
                                $.cookie("RosbriDescrView", 1);
                        }
                        return false;
                })


//                $(".ico_descr").click(function(){
//                        $('.b-photolist-descr').toggle();
//                        $('.b-photolist-descr-2').toggle();
//                        return false;
//                })


                $('.order-call-a').click(function(){
                        $('#CallQuery').show();
                        return false;
                })
        
                $('.order-call').click(function(){
                        $('#CallQuery').show();
                        return false;
                })


                $('.b-mini-button_auth').click(function(){
                        $('#Auth').show();
                        return false;
                })

                $('#knowtheprice').click(function(){
                        $('#favor').attr('rel',$(this).attr('rel'));
                        $('#KnownPriceQuery').show();
                        return false;
                })


                $('.b-popup-close').click(function(){
                        $('.b-overlay').hide();
                        $('#allreadyinfav').hide();
                        $('#cbok').hide();
                        $('.b-fieldsnull input').val('');
                        $('.errortxt').html('');
                        return false;
                })

                function FocusField(){
                        var $f = $('input.focus,textarea.focus');
                        $f.each(function(){
                                var $obj = $(this);
                                var $d = this.defaultValue;
                                $obj.focus(function(){
                                        $obj.val()==$d?$obj.val(''):'';
                                }).blur(function(){
                                        $obj.val()==''?$obj.val($d):'';
                                });
                        });
                }
                FocusField();



                $("#CallSubm").click(function(){
                        fio=$('#CallName').val();
                        phone=$('#CallPhone').val();
                        if (phone!='') {
                                $('.errortxt').html('');
                                $.ajax({
                                        type: "POST",
                                        url: "/application/views/rosbri/infoblocks/callback/ajax.php",
                                        data: "action=callback&phone="+phone+"&fio="+fio,
                                        success: function(msg){
                                                if (msg=='1') {
                                                        $('#cbok').fadeIn(300);
                                                        $('.errortxt').html('Запрос успешно сохранен');
                                                        $('#CallName').val('');
                                                        $('#CallPhone').val('');

                                                }
                                        }
                                });
                        } else {
                                $('#cbok').fadeIn(300);
                                $('.errortxt').html('Введите Ваш номер телефона');
                        }

                        return false;
                })



                $("#KnownPriceSubm").click(function(){
                        email=trim($('#KnownPriceEmail').val());
                        phone=trim($('#KnownPricePhone').val());
                        city=$('#KnownPriceCity option:selected').val();
                        name=trim($('#KnownPriceName').val());
                        lastname=trim($('#KnownPriceLastName').val());
			if ($('#KnownPriceMailer').is(':checked'))
				mailer = 1;
			else
				mailer = 0;
                        id_good=$('#favor').attr('rel');
                        if (phone!='' && email!='' && name!='' && lastname!='') {
                                $.ajax({
                                        type: "POST",
                                        url: "/application/views/rosbri/infoblocks/favorite/ajax.php",
                                        data: "action=sendmessage&phone="+phone+"&email="+email+"&city="+city+"&id_good="+id_good+"&name="+name+"&lname="+lastname+"&mailer="+mailer,
                                        success: function(msg){
                                                if (msg=='1') {
                                                        $('#KnownPriceTxt1').html('Запрос успешно сохранен');
                                                        $('#KnownPriceTxt').fadeIn(300);
                                                        $('#CallName').val('');
                                                        $('#CallPhone').val('');
                                                }
                                        }
                                });
                        } else {
                                if (name==''){
				   msg='Введите Ваше имя';
                                } else if (lastname==''){
                                   msg='Введите Вашу фамилию';
                                }else
                                if (phone=='' && email==''){
                                      msg='Введите адрес Вашей электронной почты и Ваш номер телефона';
                                } else if (phone=='') {
                                      msg='Введите Ваш номер телефона';
                                } else {
                                        msg='Введите адрес Вашей электронной почты';
                                }
                                $('#KnownPriceTxt1').html(msg);
                                $('#KnownPriceTxt').fadeIn(300);

                        }
                        return false;
                })


                $('.close2').click(function(){
                        $('.bublik').hide();
                        return false;
                })



                $('#login').live('change',function() {
                        var login=$(this).val();
                        $.ajax({
                                type: "POST",
                                url: "/application/views/rosbri/infoblocks/registration/ajax.php?action=checklogin&login="+login,
                                success: function(html){
                                        if (html!='') {
                                                $("#errormsg").html('sВыбранный логин уже занят другим пользователем!');
                                                $("#login").val("");
                                                //                        $("#regform input,select").attr("disabled","disabled");
                                                $("#errorbox").show();
                                        }
                                }
                        });
                })

                $('#email').live('change',function() {
                        var email=$(this).val();
                        $.ajax({
                                type: "POST",
                                url: "/application/views/rosbri/infoblocks/registration/ajax.php?action=checkemail&email="+email,
                                success: function(html){
                                        if (html!='') {
                                                $("#errormsg").html('Выбранный логин уже занят другим пользователем!');
                                                $("#email").val("");
                                                //                        $("#regform input,select").attr("disabled","disabled");
                                                $("#errorbox").show();
                                        }
                                }
                        });
                })



                $('#regsubm').live("click",function() {
                        var error='';
                        var template = /^[A-Za-z0-9](([A-Za-z0-9]+)*)+$/;

                        if (trim($("#login").val())=='') error += 'Не заполнено поле "Имя пользователя"<br/>';
                        if (trim($("#login").val())!='' && (!template.test($("#login").val()))) error += 'Имя пользователя может состоять только из букв латинского алфавита и цифр<br/>';
                        if (trim($("#password").val())!='' && (!template.test($("#password").val()))) error += 'Пароль может состоять только из букв латинского алфавита и цифр<br/>';
                        if (trim($("#password").val())=='') error += 'Не заполнено поле "Пароль"<br/>';
                        if (trim($("#repassword").val())=='') error += 'Подтвердите пароль<br/>';
                        if ($("#repassword").val()!=$("#password").val()) error += 'Пароли не совпадают<br/>';
                        if (trim($("#fio").val())=='') error += 'Пароли не совпадают"<br/>';
                        if (trim($("#company").val())=='') error += 'Не заполнено поле "Компания"<br/>';
                        if (trim($("#email").val())=='') error += 'Не заполнено поле "Е-mail"<br/>';
                        if ($("#email").val()!='' && !CheckEmail($("#email").val())) error += 'Поле "Е-mail" заполнено с ошибками<br/>';
                        if (trim($("#phone").val())=='') error += 'Не заполнено поле "Телефон"<br/>';
            
                        if (error!='') {
                                $("#errormsg").html(error);
                                $("#errorbox").show();
                        }
                        else {
                                $('#regform').submit();
                        }
                        return false;
                });


                $("#AuthSubm").click(function(){
                        login=trim($('#authlogin').val());
                        pass=trim($('#authpassword').val());
                        if (login!='' && pass!='') {
                                $.ajax({
                                        type: "POST",
                                        url: "/application/views/rosbri/infoblocks/registration/ajax.php",
                                        data: "action=auth&login="+login+"&pass="+pass,
                                        success: function(msg){
                                                //                                                alert(msg);
                                                if (msg=='Вы успешно авторизовались') {
                                                        $('.errortxt').html(msg);
                                                        $('#cbok2').fadeIn(300);
                                                } else {
                                                        $('.errortxt').html(msg);
                                                        $('#cbok1').fadeIn(300);
                                                }

                                        }
                                });
                        } else {
                                if (login=='' && pass=='') {
                                        msg='Для авторизации введите логин и пароль';
                                } else if(login=='') {
                                        msg='Для авторизации введите логин';
                                } else {
                                        msg='Для авторизации введите пароль';
                                }
                                $('.errortxt').html(msg);
                                $('#cbok1').fadeIn(300);

                        }
                        return false;
                })


                $('#FeedbackSubmit').live("click",function() {
                        var error='';
                        var template = /^[A-Za-z0-9](([A-Za-z0-9]+)*)+$/;
                        if (trim($("#fio").val())=='') error += 'Не заполнено поле "Имя"<br/>';
                        if ($("#email").val()!='' && !CheckEmail($("#email").val())) error += 'Поле "Е-mail" заполнено с ошибками<br/>';
                        if (trim($("#message").val())=='') error += 'Не заполнено поле "Текст"<br/>';

                        if (error!='') {
                                $("#errormsg").html(error);
                                $("#errorbox").show();
                        }
                        else {
                                $('#FeedbackForm').submit();
                        }
                        return false;
                });
                
                
                
                
                $('#ReviewFormSubmit').live("click",function() {
                        var error='';
                        var template = /^[A-Za-z0-9](([A-Za-z0-9]+)*)+$/;
                        if (trim($("#fio").val())=='') error += 'Не заполнено поле "Имя"<br/>';
                        if (trim($("#email").val())=='') error += 'Не заполнено поле "E-mail"<br/>';
                        if ($("#email").val()!='' && !CheckEmail($("#email").val())) error += 'Поле "Е-mail" заполнено с ошибками<br/>';
                        if (trim($("#phone").val())=='') error += 'Не заполнено поле "Телефон"<br/>';
                        if (trim($("#msg").val())=='') error += 'Не заполнено поле "Отзыв"<br/>';

                        if (error!='') {
                                $("#errormsg").html(error);
                                $("#errorbox").show();
                        }
                        else {
                                $('#ReviewForm').submit();
                        }
                        return false;
                });
                
                

                $('#CatalogOrderSubmit').live("click",function() {
                        var error='';
                        var template = /^[A-Za-z0-9](([A-Za-z0-9]+)*)+$/;
                        if (trim($("#fio").val())=='') error += 'Не заполнено поле "Имя"<br/>';
                        if (trim($("#phone").val())=='' && trim($("#email").val())=='') error += 'Не указаны контактные данные<br/>';
                        if ($("#CatalogEmail").val()!='' && !CheckEmail($("#CatalogEmail").val())) error += 'Поле "Е-mail" заполнено с ошибками<br/>';

                        if (error!='') {
                                $("#errormsg").html(error);
                                $("#errorbox").show();
                        }
                        else {
                                $('#CatalogOrderForm').submit();
                        }
                        return false;
                });

                $('#showcontentdiv').click(function(){
                        $('#contentdiv').toggle();
                        return false;
                })

                $('#sendresume').live("click",function() {
                        var error='';
                        var template = /^[A-Za-z0-9](([A-Za-z0-9]+)*)+$/;

                        if (trim($("#fio").val())=='') error += 'Не заполнено поле "Имя"<br/>';

                        if (trim($("#email1").val())=='') error += 'Не заполнено поле "Е-mail"<br/>';
                        if ($("#email1").val()!='' && !CheckEmail($("#email1").val())) error += 'Поле "Е-mail" заполнено с ошибками<br/>';
                        if (trim($("#phone").val())=='') error += 'Не заполнено поле "Телефон"<br/>';

                        if (error!='') {
                                $("#errormsg").html(error);
                                $("#errorbox").show();
                        }
                        else {
                                $('#resumeform').submit();
                        }
                        return false;
                });
                function jcarousel(){
			
                        var $jc = $('#jcarousel');
                        var $p = $jc.parent();
                        var w = $p.width();
                        var l = $('li',$jc).length;
                        var i=0;
                        var $prev = $('#prev');
                        var $next = $('#next');
                        $jc.width(l*292);
                        var res = $jc.width() - w;
				
                        if(res>0){
                                $next.css('visibility','');
                                $next.click(function(){
                                        if((i*292)<res){
                                                i++
                                                $jc.animate({
                                                        'marginLeft':'-='+292
                                                },500);
                                        }
                                        if(i>0){
                                                $prev.css('visibility','');
                                        }
                                        if((i*292)>res){
                                                $next.css('visibility','hidden');
                                        }
                                        return false;
                                });
                                $prev.click(function(){
                                        if(i>0){
                                                i--
                                                $jc.animate({
                                                        'marginLeft':'+='+292
                                                },500);
                                        }
                                        if(i==0){
                                                $prev.css('visibility','hidden');
                                        }
						
                                        if((i*292)<res){
                                                $next.css('visibility','');
                                        }
                                        return false;
                                });
                        }
                }
                if($('#jcarousel').length) jcarousel();
				if(!$('.b-photolist-image').parents('.index-photo').length){
					//window.innerWidth
				$(window).resize(function(){
					if($('body').width()<1025){
						var b_img = $('.b-photolist-image');
						b_img.css({
							/*'height':(window.innerHeight-$('.b-nav').height()-$('.b-header').height()-75)+'px',*/
							'height':'auto',
							'width':($('body').width()-80)+'px'
						});
						function adj_height(){
							if (b_img.height()>0 && b_img.closest('table').height()>0){
								if (b_img.height()<b_img.closest('table').height()){
									b_img.closest('table').height(b_img.height());
								}
							}else{
								setTimeout(adj_height,100);
							}
						}
						adj_height();
					}else{
						//window.innerHeight
						if($(window).height()<1200){
							$('.b-photolist-image').css({
								'height':($(window).height()-$('.b-nav').height()-$('.b-header').height()-75)+'px',
								'width':'auto'
							})
						}
					}
					//$('.b-photolist-item-in').wrapInner('<table cellpadding="0" cellspacing="0" style="margin:auto;height:'+($('body').height()-$('.b-nav').height()-$('.b-header').height()-75)+'px"><tr><td style="vertical-align:middle;"></td></tr></table>');
				});
				if($('body').width()){
					
					/*if(window.innerHeight<1200){
						
						$('.b-photolist-image').css({
							'height':(window.innerHeight-$('.b-nav').height()-$('.b-header').height()-75)+'px',
							'width':'auto'
						})
					}*/
					if($('body').width()<1025){
						var b_img = $('.b-photolist-image');
						b_img.css({
							/*'height':(window.innerHeight-$('.b-nav').height()-$('.b-header').height()-75)+'px',*/
							'height':'auto',
							'width':($('body').width()-80)+'px'
						});
						function adj_height(){
							if (b_img.height()>0 && b_img.closest('table').height()>0){
								if (b_img.height()<b_img.closest('table').height()){
									b_img.closest('table').height(b_img.height());
								}
							}else{
								setTimeout(adj_height,100);
							}
						}
						adj_height();
					}else{
						//window.innerHeight
						if($(window).height()<1200){
							$('.b-photolist-image').css({
								'height':($(window).height()-$('.b-nav').height()-$('.b-header').height()-75)+'px',
								'width':'auto'
							})
						}
					}
					//$('.b-photolist-item-in').wrapInner('<table cellpadding="0" cellspacing="0" style="margin:auto;height:'+($('body').height()-$('.b-nav').height()-$('.b-header').height()-75)+'px"><tr><td style="vertical-align:middle;"></td></tr></table>')
				} else if (document.documentElement && document.documentElement.clientWidth){
				
					var he = ($(window).height()-183)
					
					if(document.documentElement.clientHeight<1200){
						function heightIe(){
							countIe++
							he = ($(window).height()-183)
							if(he>0&&countIe<10){
								 
								$('.b-photolist-image').height(he)
								$('.b-photolist-image').width('auto')
							} else {
									setTimeout(heightIe,500);
							}
							
						}
						heightIe();
						//$('.b-photolist-image').css({'height':he+'px','width':'auto'})
					}
					$('.b-photolist-item-in').wrapInner('<table cellpadding="0" cellspacing="0" style="margin:auto;height:'+he+'px"><tr><td style="vertical-align:middle;"></td></tr></table>')
				
				}
						
				}
				
				//alert($('body').length)
				
        })
		var countIe=0
jQuery(function(){
  $(".auto-expand").each(function(){
    $(this).find("h2").wrap("<div class='ae-title'></div>").before("&rsaquo; ").click(function(){
      $(this).closest(".auto-expand").find(".opened").removeClass("opened");
      if ($(this).parent().hasClass("opened")) {
        $(this).parent().removeClass("opened").next('.ae-content:visible').slideUp(200);
      }
      else {
        $(this).parent().addClass("opened");
        $(this).parent().siblings('.ae-content:visible').slideUp(300);
        $(this).parent().next('.ae-content:hidden').slideDown(300);
      }
    });
    $(this).find(".content").addClass('ae-content').hide();
  });
});

