function show( id ) {
	(function($) {
		if($( '#sub_menu' + id ).css( 'display' ) == 'none' ) {
			$( '#sub_menu' + id).show();
		}
		else {
			$( '#sub_menu' + id).hide();
		}
	})(jQuery);
}

// Shadow

(function($) {
	
	$.fn.shadowEnable  = function() { return $(this).find("+ .fx-shadow").show().end();   };
	$.fn.shadowDisable = function() { return $(this).find("+ .fx-shadow").hide().end();   };
	$.fn.shadowDestroy = function() { return $(this).find("+ .fx-shadow").remove().end(); };
	
	$.fn.shadow = function(options) {
		options = $.extend({
			offset:  1,
			opacity: 0.2,
			color:   "#000",
			monitor: false
		}, options || {});
		options.offset -= 1;
		
		return this.each(function() {
			
			// Remove an existing shadow if it exists
			var $element = $(this).shadowDestroy(),
			
			// Create a shadow element
			$shadow = $("<div class='fx-shadow' style='position: relative;'></div>").hide().insertAfter($element);
			
			// Figure the base height and width
			baseWidth  = $element.outerWidth(),
			baseHeight = $element.outerHeight(),
			
			// Get the offset
			position = $element.position(),
			
			// Get z-index
			zIndex = parseInt($element.css("zIndex")) || 0;
			
			// Append smooth corners
			$('<div class="fx-shadow-color fx-shadow-layer-1"></div>').css({ position: 'absolute', opacity: options.opacity - 0.05,  left: options.offset,     top: options.offset,     width: baseWidth + 1, height: baseHeight + 1 }).appendTo($shadow);
			$('<div class="fx-shadow-color fx-shadow-layer-2"></div>').css({ position: 'absolute', opacity: options.opacity - 0.10,  left: options.offset + 2, top: options.offset + 2, width: baseWidth,     height: baseHeight - 3 }).appendTo($shadow);
			$('<div class="fx-shadow-color fx-shadow-layer-3"></div>').css({ position: 'absolute', opacity: options.opacity - 0.10,  left: options.offset + 2, top: options.offset + 2, width: baseWidth - 3, height: baseHeight     }).appendTo($shadow);
			$('<div class="fx-shadow-color fx-shadow-layer-4"></div>').css({ position: 'absolute', opacity: options.opacity,         left: options.offset + 1, top: options.offset + 1, width: baseWidth - 1, height: baseHeight - 1 }).appendTo($shadow);
			
			// Add color
			$("div.fx-shadow-color", $shadow).css("background-color", options.color);
			
			// Set zIndex +1 and make sure position is at least relative
			// Attention: the zIndex will get one higher!
			$element
				.css({
					zIndex: zIndex + 1,
					position: ($element.css("position") == "static" ? "relative" : "")
				});
			
			// Copy the original z-index and position to the clone
			// alert(shadow); If you insert this alert, opera will time correctly!!
			$shadow.css({
				position:     "absolute",
				zIndex:       zIndex,
				top:          position.top+"px",
				left:         position.left+"px",
				width:        baseWidth,
				height:       baseHeight,
				marginLeft:   $element.css("marginLeft"),
				marginRight:  $element.css("marginRight"),
				marginBottom: $element.css("marginBottom"),
				marginTop:    $element.css("marginTop")
			}).fadeIn();
			
			
			if ( options.monitor ) {
				function rearrangeShadow() {
					var $element = $(this), $shadow = $element.next();
					// $shadow.css( $element.position() );
					$shadow.css({
						top:  parseInt($element.css("top"))  +"px",
						left: parseInt($element.css("left")) +"px"
					})
					$(">*", $shadow).css({ height: this.offsetHeight+"px", width: this.offsetWidth+"px" });
				}
			
				// Attempt to use DOMAttrModified event
				$element.bind("DOMAttrModified", rearrangeShadow);
			
				// Use expressions if they exist (IE)
				if( $shadow[0].style.setExpression ) {
					$shadow[0].style.setExpression("top" , "parseInt(this.previousSibling.currentStyle.top ) + 'px'");
					$shadow[0].style.setExpression("left", "parseInt(this.previousSibling.currentStyle.left) + 'px'");
				}
			}

		});
	};
	
})(jQuery);

/* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * $LastChangedDate: 2007-12-20 15:43:48 +0100 (Do, 20 Dez 2007) $
 * $Rev: 4257 $
 *
 * Version: @VERSION
 *
 * Requires: jQuery 1.2+
 */

(function($){
	
$.dimensions = {
	version: '@VERSION'
};

// Create innerHeight, innerWidth, outerHeight and outerWidth methods
$.each( [ 'Height', 'Width' ], function(i, name){
	
	// innerHeight and innerWidth
	$.fn[ 'inner' + name ] = function() {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		return this.is(':visible') ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
	};
	
	// outerHeight and outerWidth
	$.fn[ 'outer' + name ] = function(options) {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		options = $.extend({ margin: false }, options || {});
		
		var val = this.is(':visible') ? 
				this[0]['offset' + name] : 
				num( this, name.toLowerCase() )
					+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
					+ num(this, 'padding' + torl) + num(this, 'padding' + borr);
		
		return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
	};
});

// Create scrollLeft and scrollTop methods
$.each( ['Left', 'Top'], function(i, name) {
	$.fn[ 'scroll' + name ] = function(val) {
		if (!this[0]) return;
		
		return val != undefined ?
		
			// Set the scroll offset
			this.each(function() {
				this == window || this == document ?
					window.scrollTo( 
						name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
						name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
					) :
					this[ 'scroll' + name ] = val;
			}) :
			
			// Return the scroll offset
			this[0] == window || this[0] == document ?
				self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
					$.boxModel && document.documentElement[ 'scroll' + name ] ||
					document.body[ 'scroll' + name ] :
				this[0][ 'scroll' + name ];
	};
});

$.fn.extend({
	position: function() {
		var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
		
		if (elem) {
			// Get *real* offsetParent
			offsetParent = this.offsetParent();
			
			// Get correct offsets
			offset       = this.offset();
			parentOffset = offsetParent.offset();
			
			// Subtract element margins
			offset.top  -= num(elem, 'marginTop');
			offset.left -= num(elem, 'marginLeft');
			
			// Add offsetParent borders
			parentOffset.top  += num(offsetParent, 'borderTopWidth');
			parentOffset.left += num(offsetParent, 'borderLeftWidth');
			
			// Subtract the two offsets
			results = {
				top:  offset.top  - parentOffset.top,
				left: offset.left - parentOffset.left
			};
		}
		
		return results;
	},
	
	offsetParent: function() {
		var offsetParent = this[0].offsetParent;
		while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
			offsetParent = offsetParent.offsetParent;
		return $(offsetParent);
	}
});

function num(el, prop) {
	return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
};

})(jQuery);

;(function($) {
	$(document).ready(function() {$('a.tozoom').fancyzoom({Speed:1000})});
})(jQuery);


// getPageScroll() by quirksmode.com
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	return new Array(xScroll,yScroll) 
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
	var windowHeight
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	return windowHeight
}

;(function($) {
	$(document).ready(function() {
		$("#yandexmaps-closeimg").click(function() {
			$('#window-yandexmaps').hide();
			$('#in-yandexmaps').html('');
			$('#yandexmaps-closeimg').hide();
			return false;
		});
		$("a").click(function () {
			if( $(this).attr("href") == "#adminreport" ) {
				$('#adminreport').css({
					top:	getPageScroll()[1] + (getPageHeight() / 4),
					left:	$(window).width() / 2 - ($('#adminreport').width() / 2)
				}).show();
				top -= 70;
				$('#adminreport').show();
				$("#warn_id").val( $(this).attr("id").substr(5) );
				return false;
			}
			if( $(this).attr("href") == "#closeadminreport" ) {
				$('#adminreport').hide();
				return false;
			}
			
			if( $(this).attr("href") == "#yandexmaps" ) {
				top_pos = getPageScroll()[1] + (getPageHeight() / 4);
				left_pos = $(window).width() / 2 - ($('#window-yandexmaps').width() / 2);
				
				top_pos -= 70;
				
				$('#window-yandexmaps').css({top:top_pos,left:left_pos}).show();
				
				$('#yandexmaps-closeimg').css({left:(left_pos + 620), top:(top_pos + 3)}).show();
				
				map = new YMaps.Map($('#in-yandexmaps')[0]);
		
				geocoder = new YMaps.Geocoder($(this).attr('rel'), {results: 1, boundedBy: map.getBounds()});
				YMaps.Events.observe(geocoder, geocoder.Events.Load, function () {
				if (this.length()) {
					geoResult = this.get(0);
					map.addControl(new YMaps.Zoom());
					map.addControl(new YMaps.ScaleLine());
					
					map.addOverlay(geoResult);
					map.setBounds(geoResult.getBounds());
					map.zoomBy(200)
				}
				else {
					map.destructor();
						$('#in-yandexmaps').html('<div class="mapText">Ошибка загрузки карты</div>');
					}
				});
				return false;
			}
		});
		
		$("#warn_submit").click(function () {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)([a-z.0-9]{2,15})+$/;
	
			if( $("#warn_complaint").val().length < 10 ) {
				alert('Жалоба должна состоять не мение из 10 символов');
				return;
			}
			else if( $("#warn_name").val().length < 3 ) {
				alert('Поле имя должно состоять не мение из 3 букв');
				return;
			}
			else if( !filter.test( $("#warn_email").val() ) ) {
				alert( 'Неправильный адрес электронной почты' );
				return;
			}
			
			$( "#warn_submit" ).hide();
			$( "#warn_close" ).hide();
			$( "#warn_load" ).show();
			$.post( '/?control=board&option=warn', { id: $("#warn_id").val(), name: $("#warn_name").val(), email: $("#warn_email").val(), complaint: $("#warn_complaint").val() }, function() {
				alert( 'Жалоба отправленна' );
				
				$("#warn_id").val('');
				$("#warn_name").val('');
				$("#warn_email").val('');
				$("#warn_complaint").val('');
				
				$( '#adminreport' ).hide();
				$( "#warn_submit" ).show();
				$( "#warn_close" ).show();
				$( "#warn_load" ).hide();
				return;
			});
		});
	});
})(jQuery);
