this.log = this.console && console.log && function(){ console.log.apply( console, arguments ); } || function(){};

/*** ----------------- **** ----------------- ****
**** HTML5 tags Enable **** (c) http://vj.vg/ ****
**** ----------------- **** ----------------- ***/
(
	function( document ){
		if( !/*@cc_on!@*/0 )
			return;
		'abbr article aside audio canvas datalist details eventsource figure footer header hgroup mark menu meter nav output progress section time video'.replace(
			/\w+/g,
			function( tag ){
				document.createElement( tag );
			}
		);
	}
)( document );

// Gallery Plugin
(
	function( $ ){
		$.fn.vlGallery = function( o, path ){
			var
				options = $.extend( {}, $.fn.vlGallery.options, o || {} ),
				style = options.style || {},
				overlay, box, img, process, _body,
				doc = $( document ),
				w = $( window ),
				plugin = $.fn.vlGallery,
				resize = plugin.resize,
				click = function(){
					var
						$this = $( this ),
						data = $this.data( 'vlGallery' ),
						options = data.options;
					if( !overlay ){
						overlay = $(
								'<div id="' + options.overlay + '" style="position:absolute;top:0;left:0;z-index:1000001;display:none;' + ( style.overlay || '' ) + '"></div>'
								+ '<div id="' + options.box + '" style="position:absolute;top:0;left:0;z-index:1000002;display:none;' + ( style.box || '' ) + '">'
									+ '<div style="' + ( style.process || '' ) + '">Загзузка...</div>'
									+ '<img src="" border="0" style="display:none;">'
								+ '</div>'
							)
							.appendTo( _body = $( 'body' ) )
							.eq( 0 );
						box = overlay.next();
						process = box.children( ':eq(0)' );
						img = box
							.children( ':eq(1)' )
							.hide()
							.load(
								function(){
									process.hide();
									img.show();
									resize();
								}
							);
						overlay.add( box )
						.click(
							function(){
								overlay.add( box )
								.fadeOut(
									options.time || 500,
									function(){
										process.show();
										img.hide();											
									}
								);
							}
						);
						plugin.resize = resize = function(){
							overlay
							.width( 0 )
							.height( 0 );
							var
								width = w.width(),
								height = w.height();
							if( img.is( ':visible' ) ){
								if( img.width() > ( width * 0.84 ) ){
									img.width( width * 0.84 );
								}
								else if( img.height() > ( height * 0.84 ) ){
									img.height( height * 0.84 );
								}
							}
							width = w.width(),
							height = w.height();
							overlay
							.width( width )
							.height( doc.height() );
							box
							.css(
								{
									top: w.scrollTop() + ( w.height() / 2 ) - ( box.height() / 2 ),
									left: w.scrollLeft() + ( width / 2 ) - ( box.width() / 2 )
								}
							);
						};
						w.resize( resize );
					}
					img
					.attr( 'src', '' )
					.removeAttr( 'width' )
					.removeAttr( 'height' )
					.css(
						{
							width: 'auto',
							height: 'auto'
						}
					)
					.attr( 'src', data.path );
					overlay
					.fadeTo(
						options.time || 500,
						options.opacity || 0.8,
						function(){
							box.fadeIn( 250 );
							plugin.resize();
						}
					);
					plugin.resize();
					return false;
				};
			this.each(
				function(){
					var
						$this = $( this ),
						path = path || $this.is( 'img' ) ? $this.attr( 'src' ) : $this.is( 'a' ) ? $this.attr( 'href' ) : $this.find( 'img:eq(0)' ).attr( 'src' ),
						data = $this.data( 'vlGallery' );
					if( data ){
						data.path = path;
					}
					else{
						$this
						.data(
							'vlGallery',
							{
								options: options,
								path: path
							}
						)
						.click( click );
					}
				}
			);
		};
		$.fn.vlGallery.options = {
			overlay: 'overlay',
			box: 'vlg-box',
			opacity: 0.8,
			time: 500,
			style: {
				overlay: 'background-color:#0A0A0A',
				box: 'cursor:pointer;padding:8px;border-radius:5px;-moz-border-radius:5px;-webkit-border-radius:5px;background-color:rgba( 255, 255, 255, 0.75 );-background:#FFF;box-shadow:0 0 15px #FFF;-moz-box-shadow:0 0 15px 0 #FFF;-webkit-box-shadow:0 0 15px #FFF',
				process: 'color:#000;margin:10px'
			}
		};
		$(
			function(){
				$( 'a[rel="vlGallery"], img.vlGallery' ).vlGallery();
			}
		);
	}
)( jQuery );

/*** ----------------- **** ----------------- ****
****  JavaScript Code  **** (c) http://vj.vg/ ****
**** ----------------- **** ----------------- ***/
(
	function( $ ){		
		$(
			function(){
				$( '.gallery-block a.gallery' )
				.each(
					function(){
						var $this = $( this );
						if( $this.height() < 125 )
							$this.height( 125 );
					}
				);
				
				var url = location.pathname.replace( /\/?$/, '' );
				$( 'menu a' )
				.css( 'opacity', 0.7 )
				.hover(
					function(){
						$( this )
						.stop( true )
						.fadeTo( 400, 1 );
					},
					function(){
						$( this )
						.stop( true )
						.fadeTo( 400, 0.7 );
					}
				)
				.filter( '[href="' + url + '"]' )
				.css( 'opacity', 1 )
				.unbind( 'mouseover mouseout' );
				
				$( 'head' )
				.append( '<!--[if IE 6]><style type="text/css">#content{padding-right:0}</style><![endif]-->' );
				
				$( '#contactForm' )
				.find( 'input:not(:submit), textarea' )
				.focus(
					function(){
						if(	this.value == this.defaultValue )
							this.value = '';
					}
				)
				.blur(
					function(){
						if(	this.value == '' )
							this.value = this.defaultValue;
					}
				);
				
				if( $( 'body' ).height() < $( window ).height() )
					$( '#content' ).height( $( '#content' ).height() + ( $( window ).height() - $( 'body' ).height() ) );
				
				
				$( '.resize img' )
				.each(
					function(){
						var
							$this = $( this ),
							src = $this.attr( 'src' ),
							width, height,
							parent = $this.parent(),
							innerWidth = parent.innerWidth(),
							innerHeight = parent.innerHeight();
							load = function(){
								$this.show();
								if( innerWidth >= innerHeight ){
									$this.width( innerWidth );
								}
								else{
									$this.height( innerHeight );
								}						
								width = $this.width();
								height = $this.height();
								if( height != 0 && width != 0 ){
									if( height < innerHeight ){
										$this.css( 'top', ( innerHeight - height ) / 2 );
									}
									else if( width < innerWidth ){
										$this.css( 'left', ( innerWidth - width ) / 2 );
									}
									$this
									.hide()
									.fadeIn( 1000 );
								}
							};
							!top.opera ? this.complete ? load() : $this.load( load ) : $this.load( load ) && load();
					}
				);
				
				$( '#printVersion' )
				.click(
					function(){
						var
							html = '<html>'
								+ '<head>'
									+ '<title>Контакты</title>'
									+ '<style type="text/css">body{font-family:Tahoma, Geneva, sans-serif;font-size:14px;color:#111;}a{color:#000;text-decoration:none;}a:focus{outline:none;}body h1{font-size:14px;}</style>'
									+ '<style type="text/css" media="print">.noPrint{display:none;}.content{font-size:14px;}</style>'
								+ '</head>'
								+ '<body>'
									+ '<p><h2 style="font-weight:normal;">Контакты</h2></p>'
									+ '<p class="content">' + $( '#content > article.content:eq(0)' ).html().replace( /^\s*|\s*$/g, '' ) + '</p>'
									+ '<p><img src="/assets/images/map.jpg" border="0" width="570"></p>'
									+ '<p style="text-align:right;padding:3px;padding-left:15px;" class="noPrint"><a href="#" onclick="self.print(); return false;" style="display:inline-block;background:#AAA;border:1px #555 solid;padding:3px;padding-left:15px;padding-right:15px;margin-right:5px;">Печать</a></p>'
								+ '</body>'
							+ '</html>',
							wPrint = window.open( '','new','width=595,height=400,left=100,top=100,scrollbars=1' );
						wPrint.document.writeln( html );
						wPrint.document.close();
						return false;
					}
				);
				
				$( '#contactForm' )
				.submit(
					function(){
						var ret = true;
						$( 'input:text, textarea' )
						.each(
							function(){
								if( ret ){
									if( this.value.length < 2 ){
										ret = false;
										alert( 'Заполните поле "' + $( this ).prev().text().replace( ':', '' ) + '"!' );
										this.focus();
									}
								}
							}
						);
						return ret;
					}
				);
				
			}
		);		
	}
)( jQuery );
