if (window.Site)
Site.Plugins.Graphics = {
	blocked: false,
	/** конструктор */
	construct: function()
	{
		Site.startAll(this);
	},
	/** подсказки */
	textNotice: function()
	{
		var jNotice = $('<div class="notice"><p>'+gettext('Для просмотра данного раздела Вам необходимо <a href="/accounts/login/">авторизироваться</a> в&nbsp;системе.')+'</p>	</div>').appendTo($(document.body));
		var jNoticeShow = false;
		$('.need-login').mouseover(function(e) {
			if(!jNoticeShow) {jNotice
			.css('top', e.pageY - 10 + 'px')
			.css('left', e.pageX - (jNotice.outerWidth() / 1.37) + 'px')
			.css('display', 'block');
			jNoticeShow = true;
			}
		}).mouseleave(function(e) {
			if(!jNoticeShow) {
				jNotice.css('display', 'none');
			}
		});
		$('.notice').mouseleave(function(e) {
			if(jNoticeShow) {
				jNotice.css('display', 'none');
				jNoticeShow = false;
			}
		});
	},
	/** Cлайдеры  */
	Slider: {
		construct: function()
		{
			var _this = this;
			$("div[class*='slider']").each(function(i) {
				var engine = $(this).attr('className').replace(/.*slider-([^ ]*).*/, '$1');
				if (engine == $(this).attr('className')) {
					engine = 'simple';
				}
				engine = engine.substr(0, 1).toUpperCase() + engine.substr(1);
				if (!_this.Engines[engine]) {
					engine = 'Simple';
				}
				_this.Engines[engine].el.push($(this));
				
				this.engine = engine;			
				this.slider = $(this).find('ul:first');
				this.width = this.slider.find('li:first').width() + parseInt(this.slider.find('li:first').css('padding-left')) + parseInt(this.slider.find('li:first').css('padding-right'));
				this.maxWidth = - this.width * (this.slider.children().length - 1);
				this.height = this.slider.height();
				this.elementHeight = this.slider.find('li:first').height() + parseInt(this.slider.find('li:first').css('padding-top')) + parseInt(this.slider.find('li:first').css('padding-bottom'));
				this.maxHeight = this.elementHeight * (this.slider.children().length - 1);
				
				var el = $(this);
				$(this).find('button[name=next]:first, button[name=prev]:first').click(function() {
					_this.Engines[el.attr('engine')].animate($(this).attr('name') == 'next', el);
				});
			});
			Site.startAll(_this.Engines);			
		},
		Engines: {
			/* простой слайдер с дисаблящимеся кнопками */
			Simple: {
				el: [],
				construct: function()
				{
					
				},
				animate: function(plus, el)
				{
					if (el._blocked) {
						return false;
					}
					el._blocked = true;
					var _this = this;
					
					var left = parseInt(el.attr('slider').css('left')) + (plus ? - el.attr('width') : el.attr('width'));
					if (left < el.attr('maxWidth')) {
						left = 0;
					}
					if (left > 0) {
						left = el.attr('maxWidth');
					}
					
					el.attr('slider').animate({ opacity: 0 }, 200, 'linear', function() {
						$(this).css('left', left);
						$(this).animate({ opacity: 1 }, 200, 'linear', function() {
							//ie6/7 fix
							if ($.browser.msie) {
								$(this).css('filter', '');
							}							
							el._blocked = false;
						});
					});
					return true;
				}
			},
            /* пропали/появились */
    		Fade: {
    			el: [],
    			construct: function()
    			{
    				var _this = this;
    				$.each(this.el, function(i) {
    					var el = $(this);
    					el.get(0).buttons = $('<span>').insertAfter($(this).find('button[name=prev]:first'));
    					for (var i = 0; i < el.attr('slider').children().length; i++) {
    						var oButton = $('<button' + (i == 0 ? ' class="current"' : '') + '>' + (i + 1) + '</button>').appendTo(el.attr('buttons'));			
    						oButton.click(function() {
    							if ($(this).hasClass('current')) {
    								return false;
    							}
    							_this.animate(false, el, el.attr('buttons').find('button').index(this));
    						});
    					}
    				});
    			},
    			animate: function(plus, el, index)
    			{
    				if (this._blocked) {
    					return false;
    				}
    				el._blocked = true;
    				var _this = this;
    				
    				if (index == undefined) {
    					var left = parseInt(el.attr('slider').css('left')) + (plus ? - el.attr('width') : el.attr('width'));
    					if (left < el.attr('maxWidth')) {
    						left = 0;
    					}
    					if (left > 0) {
    						left = el.attr('maxWidth');
    					}
    					var index = left / -el.attr('width');
    				} else {
    					var left = index * -el.attr('width');
    				}				
    				
    				el.attr('buttons')
    				.find('button').removeClass('current')
    				.eq(index).addClass('current');
    				
    				el.attr('slider').animate({ opacity: 0 }, 300, 'linear', function() {
    					$(this).css('left', left);
    					$(this).animate({ opacity: 1 }, 300, 'linear', function() {
    						//ie6/7 fix
    						if (Site.Browser.engine == 'msie' && Site.Browser.version < 9) {
    							$(this).css('filter', '');
    						}							
    						el._blocked = false;
    					});
    				});
    				return true;
    			}
    		}
   			/* --- */
		}
	},
	Tabs: {
		construct: function()
		{
			$('.tabs').each(function() {
				var $tabs = $(this).children('div');
				var $a = $(this).find('.tab-switch a');
				$a.click(function() {
					if ($(this).hasClass('current')) {
						return false;
					}
					var index = $a.index(this);
					var $tab = $tabs.eq(index);
					if (!$tab.length) {
						return false;
					}
					$tabs.css('display', 'none');
						$tab.css('display', 'block');
						$a.removeClass('current');
						$(this).addClass('current');
					return false;
				});
			});
		}
	}
}

