function printme(src) {
	link = "about:blank";
	var pw = window.open(link,"_new");
	pw.document.open();
	pw.document.write(makepage(src));
	pw.document.close();
}

function makepage(src) {
	return "<html>\n" +
	"<head>\n" +
	"<title>Распечатать</title>\n" +
	"<script>\n" +
	"function step1() {\n" +
	" setTimeout('step2()', 10);\n" +
	"}\n" +
	"function step2() {\n" +
	" window.print();\n" +
	" window.close();\n" +
	"}\n" +
	"</scr" + "ipt>\n" +
	"</head>\n" +
	"<body onLoad='step1()'>\n" +
	"<img src='" + src + "'/>\n" +
	"</body>\n" +
	"</html>\n";
}

$(document).ready(function(){

	$('.catalog .menu li').hover(function(){$(this).children('ul').show();},function(){$(this).children('ul').hide();});

	/*
	/[k] разворачивание описания
	var goal = $('.goal');
	if (goal.length > 0 && goal.height() > 284){
		goal
		.css({'height':'284px','overflow':'hidden'})
		.after('<div id="expand" style="margin-bottom:-10px; text-align:right; border-top:1px dotted #ddd; padding-top:0;"><a href="#" style="position:relative; top:-1px; text-decoration:none;-webkit-border-bottom-right-radius: 2px; -webkit-border-bottom-left-radius: 2px; -moz-border-radius-bottomright: 2px; -moz-border-radius-bottomleft: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; background-color:#ddd; padding:2px; margin-top:0; font-size:11px; line-height:11px; color:white;">Развернуть</a></div>');
		$('#expand a').click(function (){
			if ($(this).hasClass('opened')) {$('.goal').css({'height':'284px','overflow':'hidden'}); $(this).removeClass('opened').text('Развернуть');
			}
			else {
				$('.goal').css({'height':'auto','overflow':'auto'}); $(this).addClass('opened').text('Свернуть');
			}
			return false;
		});		
	}*/
	
	$('.catalog-filter a.toggle').click(function(){
		$('.catalog-filter .options').toggle();
		return false;
	});

	$('a.review-thema').click(function(){
		$('.review-show-text-'+$(this).attr('rel')).clone().appendTo('.window-wrapper .window-content');
		showWindow();
		window.scrollTo(0, document.body.scrollHeight);
		return false;
	})


	//[k] работа со вкладками
	$('.item_block').hide();
	$('#ccontrols a').each(function(){
		var a = $(this);
		if (a.hasClass('selected')){
			$('#'+((a.attr('id')).split('-'))[0]+'-block').show();
		}
		a.click(function(){
			$('.item_block').hide();
			$('#'+(($(this).attr('id')).split('-'))[0]+'-block').show('fast');
			$('#ccontrols a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		});
	}); 

	//[d] если рекоммендацию выбрали открываем выпадающий список
	//[d] и сохраняем текущие параметры
	if(window.location.href.split('?')[1]!=undefined) {
		$('.catalog-filter .options').toggle();
		if (window.location.href.split('?')[1].split('=').length>2) {
			for (var i=0;i<window.location.href.split('?')[1].split('=')[i+1].length-1;i++) {
				var valueCheck=window.location.href.split('?')[1].split('=')[i+1].split('&')[0];
				for (j=0;j<$("input#group-"+i+"").length;j++) {
					if ($("input#group-"+i+"").eq(j).val()==valueCheck) {
						$("input#group-"+i+"").eq(j).attr('checked', 'checked');
					}
				}
			}			
		}

		var valueCheck=window.location.href.split('?')[1].split('=')[window.location.href.split('?')[1].split('=').length-1].split('#')[0];
		i=window.location.href.split('?')[1].split('=').length-1;i--;
		for (j=0;j<$("input#group-"+i+"").length;j++) {
			if ($("input#group-"+i+"").eq(j).val()==valueCheck) {
				$("input#group-"+i+"").eq(j).attr('checked', 'checked');
			}
		}
		return false;		
	}
	
	// $('a.pdf').each(function(){
	// 	html='<div class="pdf">';
	// 	html+='<a href="'+$(this).attr('href')+'">Скачать паспорт</a><br><span>PDF</span>'
	// 	
	// 	$(html).appendTo('#downloads');
	// 	$(this).remove();
	// })
	// 
	// $('a.jpeg').each(function(){
	// 	html='<div class="jpg">';
	// 	html+='<a href="'+$(this).attr('href')+'">Скачать сертификат</a><br><span>JPG</span>'
	// 	
	// 	$(html).appendTo('#downloads');
	// 	$(this).remove();
	// })
	
	$('h3 a.video_player').parent().remove();
	
	// Вешаем обработчик на ссылки с нужным классом
	$( '.thumbs .overflow a' ).click(function(e) {	
		e.preventDefault();
		var link = $(this);
		if (link.hasClass('make_big')) {
			var big = $('a.big').eq(0);
			if ($('a.big').eq(0).length == 0)
				big = $('a.live').eq(0);
	
			$('*',big).remove();
			big.removeClass('live').addClass('big');
			// Цепляем к попапу картинку и ждём её загрузки
			var image = $('<img src="'+ link.attr('href') +'.big_new" alt="'+ link.attr('title') +'"/>');
			image.css('opacity',0).appendTo(big);
			image.load(function(){
				if ( $.browser.msie && ($.browser.version < 7) ){
					image.css({
						opacity:1,
						'background-image': 'url('+link.attr('href')+'.big_new)'
					})
					image.attr('src','/templates/armed/i/zoom.png');
					big.attr('href',link.attr('href')).attr('title',link.attr('title'));
				} else {
					image.animate({opacity:1},500,function() {
							image.css({
								'background-image': 'url('+link.attr('href')+'.big_new)'
							}).attr('src','/templates/armed/i/zoom.png');
							big.attr('href',link.attr('href')).attr('title',link.attr('title'));
						});				
				}
			});
			
		} else {
			var big = $('a.big').eq(0);
			if ($('a.big').eq(0).length == 0)
				big = $('a.live').eq(0);
	
			$('*',big).remove();
			big.removeClass('big').addClass('live');
			// Цепляем к попапу картинку и ждём её загрузки
			var image = $('<img src="'+ link.attr('href') +'.big_new" alt="'+ link.attr('title') +'"/>');
			image.css('opacity',0).appendTo(big);
			image.load(function(){
				if ( $.browser.msie && ($.browser.version < 7) ){
					image.css({
						opacity:1,
						'background-image': 'url('+link.attr('href')+'.big_new)'
					})
					image.attr('src','/templates/armed/i/live.png');
					big.attr('href',link.attr('href')).attr('title',link.attr('title'));
				} else {
					image.animate({opacity:1},500,function() {
							image.css({
								'background-image': 'url('+link.attr('href')+'.big_new)'
							}).attr('src','/templates/armed/i/live.png');
							big.attr('href',link.attr('href')).attr('title',link.attr('title'));
						});				
				}
			});
			
		}
	});

})


$(function() {

	// Darkbox
	
	( function ( $ ) {

		$.fn.darkbox = function (mode) {
			var mode = mode || 'multi';

			var shadowFadeInTime  = 200,
				shadowFadeOutTime = 100,

				imageFadeInTime       = 400,
				imageErrorFadeOutTime = 800,

				darkboxStateClasses =
					'darkbox-canvas-done darkbox-canvas-load darkbox-canvas-error',

				boxMargin        = 50,
				buttonPlaceClass = /mac/i.test( navigator.platform ) ?
					'darkbox-button-left' :
					'darkbox-button-right';

			function openBox ( e ) {
				e.preventDefault();
				
				var link = $( this ),
					frame = $( 'div.darkbox-frame' );
				
				$( 'div.darkbox-canvas' ).removeClass( darkboxStateClasses );
				index = $('.scroller a').index($('a.selected'));

				if (mode == 'one') window.darkbox_arrows = $('.darkbox-next, .darkbox-prev').detach();
				else if (window.darkbox_arrows != undefined)
					window.darkbox_arrows.appendTo('.darkbox-canvas');
				
				if (index < ($('.scroller a').length -1)) {
					$('.darkbox-next').show();
				} else {
					$('.darkbox-next').hide();
				}
				var x = $('.make_live').length;
				
				if (index > x) {
					$('.darkbox-prev').show();
				} else {
					$('.darkbox-prev').hide();
				}
				frame.children( 'div.darkbox-canvas' ).
						css( { width: '', marginLeft: '', height: '', marginTop: '' } ).
						children( 'img' ).
							one( 'error', handleImageLoadError ).
							css( { width: '', height: '' } ).
							attr( 'src', link.attr( 'href' ) ). // + '?_=' + ( +new Date() )
							attr( 'alt', link.attr( 'title' ) ).
							end().
						end().

					show().
					children( 'div.darkbox-shadow' ).
						animate( { opacity: 0.6 }, shadowFadeInTime );
				$( '.darkbox-title', frame ).html(link.attr( 'title' ));
			}

			function closeBox() {
				$( 'div.darkbox-shadow' ).animate(
					{ opacity: 0 },
					shadowFadeOutTime,
					function () {
						$( 'div.darkbox-frame' ).
							hide().
							children( 'div.darkbox-canvas' ).
								removeClass( darkboxStateClasses ).
								children( 'img' ).
									unbind( 'error', handleImageLoadError ).
									attr( 'src', '' );
					}
				);
			}

			function handleKey( e ) {
				if ( 27 === e.which || 32 === e.which ) {
					// If darkbox is shown
					if ( 0 === $(".darkbox-frame:hidden").length ) {
						e.preventDefault();
						closeBox();
					}
				}
			}

			function handleImageLoadError() {
				$( 'div.darkbox-canvas' ).addClass( 'darkbox-canvas-error' );
				setTimeout( closeBox, imageErrorFadeOutTime );
			}

			function handleImageLoad() {
				var img = $( this ),
					frame = img.parents( 'div.darkbox-frame' ),
					canvas = img.parents( 'div.darkbox-canvas' ),
					ratio = 1,
					img_width = img.width(), img_height = img.height(),
					frame_width = frame.width(), frame_height = frame.height();

				if ( 0 === img_width && 0 === img_height ) {
					setTimeout( function (){ img.load(); }, 10 );
					return;
				}

				if (
					( img_width > frame_width - boxMargin ) ||
					( img_height > frame_height - boxMargin )
				) {
					ratio = Math.min(
						( frame_width - boxMargin ) / img_width,
						( frame_height - boxMargin ) / img_height
					);

					img_width = Math.round( img_width * ratio );
					img_height = Math.round( img_height * ratio );

					img.css( { width: img_width, height: img_height } );
				}

				canvas.
					addClass( 'darkbox-canvas-load' ).
					animate( {
						width:      img_width,
						marginLeft: -img_width / 2,
						height:     img_height,
						marginTop:  -img_height / 2
						}, imageFadeInTime,
						function () {
							$( this ).
								removeClass( 'darkbox-canvas-load' ).
								addClass( 'darkbox-canvas-done' ).
								children( 'img' ).
									show();
						}
					);
				$( '.darkbox-title', frame ).css({width:img_width -10});
					
			}
			function imageNext(e){
				e.preventDefault();
				
				var link = $( 'a.selected' ).next(),
					frame = $( 'div.darkbox-frame' ),
					index = $('.scroller a').index(link);
				$( 'a.selected' ).removeClass('selected');
				link.addClass('selected');
				$('.bar').scrollLeft(120*(index-1));
				$( 'div.darkbox-canvas' ).removeClass( darkboxStateClasses );
				if (index < ($('.scroller a').length -1)) {
					$('.darkbox-next').show();
				} else {
					$('.darkbox-next').hide();
				}
				var x = $('.make_live').length;
				
				if (index > x) {
					$('.darkbox-prev').show();
				} else {
					$('.darkbox-prev').hide();
				}
				frame.
					children( 'div.darkbox-canvas' ).
						css( { width: '', marginLeft: '', height: '', marginTop: '' } ).
						children( 'img' ).
							one( 'error', handleImageLoadError ).
							css( { width: '', height: '' } ).
							attr( 'src', link.attr( 'href' ) ). // + '?_=' + ( +new Date() )
							attr( 'alt', link.attr( 'title' ) ).
							end().
						end().

					show().
					children( 'div.darkbox-shadow' ).
						animate( { opacity: 0.6 }, shadowFadeInTime );
				$( '.darkbox-title', frame ).html(link.attr( 'title' ));
			}
			function imagePrev(e){
				e.preventDefault();
				
				var link = $( 'a.selected' ).prev(),
					frame = $( 'div.darkbox-frame' ),
					index = $('.scroller a').index(link);
				$( 'a.selected' ).removeClass('selected');
				link.addClass('selected');
				$('.bar').scrollLeft(120*(index-1));
				$( 'div.darkbox-canvas' ).removeClass( darkboxStateClasses );
				if (index < ($('.scroller a').length -1)) {
					$('.darkbox-next').show();
				} else {
					$('.darkbox-next').hide();
				}
				var x = $('.make_live').length;
				
				if (index > x) {
					$('.darkbox-prev').show();
				} else {
					$('.darkbox-prev').hide();
				}
				frame.
					children( 'div.darkbox-canvas' ).
						css( { width: '', marginLeft: '', height: '', marginTop: '' } ).
						children( 'img' ).
							one( 'error', handleImageLoadError ).
							css( { width: '', height: '' } ).
							attr( 'src', link.attr( 'href' ) ). // + '?_=' + ( +new Date() )
							attr( 'alt', link.attr( 'title' ) ).
							end().
						end().

					show().
					children( 'div.darkbox-shadow' ).
						animate( { opacity: 0.6 }, shadowFadeInTime );
				$( '.darkbox-title', frame ).html(link.attr( 'title' ));
			}
			
			if($('.darkbox-frame').length == 0){
				$( '<div class="darkbox-frame"><div class="darkbox-shadow"></div><div class="darkbox-canvas"><img><div class="darkbox-title"></div><div class="darkbox-button" title="Закрыть"></div><div class="darkbox-next" title="Следующая"></div><div class="darkbox-prev" title="Предидущая"></div></div></div>' ).
					children( 'div.darkbox-shadow' ).
						click( closeBox ).
						end().
					find( 'div.darkbox-button' ).
						addClass( buttonPlaceClass ).
						click( closeBox ).
						end().
					find( 'img' ).
						load( handleImageLoad ).
						end().
					find( 'div.darkbox-next' ).
						click( imageNext ).
						end().
					find( 'div.darkbox-prev' ).
						click( imagePrev ).
						end().
					appendTo( 'body' ).
					end();				
			}


			$( document ).
				keypress( handleKey ).
				keydown( handleKey );
			this.live('click', openBox );

			return this;
		};
	} ( jQuery ) );
	
	$( '.thumbs .overflow a.make_big' ).darkbox();
	$( 'a.big' ).darkbox();
	$( '#downloads .make_big' ).darkbox('one');
	
	$('.pages a').click(function(evt){
		evt.preventDefault();
		if ($(this).attr('rel') == 'next') {
			var index = $('.scroller a').index($('.selected'));
			if(index < ($('.scroller a').length -1)){
				$('.bar').scrollLeft(120*(index));
				$( '.thumbs .overflow a' ).removeClass('selected');
				$( '.thumbs .overflow a' ).eq(index+1).addClass('selected');				
			} else {
				return false;
			}
		} else if($(this).attr('rel') == 'prev'){
			var index = $('.scroller a').index($('.selected'));
			if(index > 0){
				$('.bar').scrollLeft(120*(index-2));
				$( '.thumbs .overflow a' ).removeClass('selected');
				$( '.thumbs .overflow a' ).eq(index-1).addClass('selected');				
			} else {
				return false;
			}
		} else {
			$('.bar').scrollLeft(120*($(this).attr('rel')-2));
			$( '.thumbs .overflow a' ).removeClass('selected');
			$( '.thumbs .overflow a' ).eq($(this).attr('rel')-1).addClass('selected');			
		}
		var link = $('.scroller a.selected');
		if (link.hasClass('make_big')) {
			var big = $('a.big').eq(0);
			if ($('a.big').eq(0).length == 0)
				big = $('a.live').eq(0);
	
			$('*',big).remove();
			big.removeClass('live').addClass('big');
			// Цепляем к попапу картинку и ждём её загрузки
			var image = $('<img src="'+ link.attr('href') +'.big_new" alt="'+ link.attr('title') +'"/>');
			image.css('opacity',0).appendTo(big);
			image.load(function(){
				if ( $.browser.msie && ($.browser.version < 7) ){
					image.css({
						opacity:1,
						'background-image': 'url('+link.attr('href')+'.big_new)'
					})
					image.attr('src','/templates/armed/i/zoom.png');
					big.attr('href',link.attr('href')).attr('title',link.attr('title'));
				} else {
					image.animate({opacity:1},500,function() {
							image.css({
								'background-image': 'url('+link.attr('href')+'.big_new)'
							}).attr('src','/templates/armed/i/zoom.png');
							big.attr('href',link.attr('href')).attr('title',link.attr('title'));
						});				
				}
			});
			
		} else {
			var big = $('a.big').eq(0);
			if ($('a.big').eq(0).length == 0)
				big = $('a.live').eq(0);
	
			$('*',big).remove();
			big.removeClass('big').addClass('live');
			// Цепляем к попапу картинку и ждём её загрузки
			var image = $('<img src="'+ link.attr('href') +'.big_new" alt="'+ link.attr('title') +'"/>');
			image.css('opacity',0).appendTo(big);
			image.load(function(){
				if ( $.browser.msie && ($.browser.version < 7) ){
					image.css({
						opacity:1,
						'background-image': 'url('+link.attr('href')+'.big_new)'
					})
					image.attr('src','/templates/armed/i/live.png');
					big.attr('href',link.attr('href')).attr('title',link.attr('title'));
				} else {
					image.animate({opacity:1},500,function() {
							image.css({
								'background-image': 'url('+link.attr('href')+'.big_new)'
							}).attr('src','/templates/armed/i/live.png');
							big.attr('href',link.attr('href')).attr('title',link.attr('title'));
						});				
				}
			});
			
		}
		
	})
	$( '.thumbs .overflow a' ).click(function(){
		$( '.thumbs .overflow a' ).removeClass('selected');
		$( this ).addClass('selected');
		
	})
	if($('.tech table').length){
		$('.tech table').wrap('<div class="ib">')
		$('.tech table tr').each(function(){
			$('td',this).eq(0).addClass('left').html('<span>'+$('td',this).eq(0).html()+'</span>');
			$('td',this).eq(1).addClass('right').html('<span>'+$('td',this).eq(1).html()+'</span>');
		})
	}
	
	$('.bar').scroll(function(evt){
		// console.log(evt);
	});
	
});

$(function() {

	// Darkbox
	
	( function ( $ ) {

		$.fn.livebox = function () {
			var shadowFadeInTime  = 200,
				shadowFadeOutTime = 100,

				imageFadeInTime       = 400,
				imageErrorFadeOutTime = 800,

				darkboxStateClasses =
					'livebox-canvas-done livebox-canvas-load livebox-canvas-error',

				boxMargin        = 50,
				buttonPlaceClass = /mac/i.test( navigator.platform ) ?
					'livebox-button-left' :
					'livebox-button-right';

			function openBox ( e ) {
				e.preventDefault();
				
				var link = $( this ),
					frame = $( 'div.livebox-frame' ),
					sprite = $('.live-photo .sprite');
				
				$( 'div.livebox-canvas' ).removeClass( darkboxStateClasses );
				
				frame.
					children( 'div.livebox-canvas' ).
						css( { width: '', marginLeft: '', height: '', marginTop: '' } ).
						children( 'img' ).
							one( 'error', handleImageLoadError ).
							css( { width: '', height: '' } ).
							attr( 'src', $('img',sprite).eq(0).attr( 'src' ) ). // + '?_=' + ( +new Date() )
							attr( 'alt', link.attr( 'title' ) ).
							end().
						end().

					show().
					children( 'div.livebox-shadow' ).
						animate( { opacity: 0.6 }, shadowFadeInTime );
				$( '.livebox-title', frame ).html('Вы можете вращать фото мышью, зажав левую кнопку.');
			}

			function closeBox() {
				$( 'div.livebox-shadow' ).animate(
					{ opacity: 0 },
					shadowFadeOutTime,
					function () {
						$( 'div.livebox-frame' ).
							hide().
							children( 'div.livebox-canvas' ).
								removeClass( darkboxStateClasses ).
								children( 'img' ).
									unbind( 'error', handleImageLoadError ).
									attr( 'src', '' );
					}
				);
			}

			function handleKey( e ) {
				if ( 27 === e.which || 32 === e.which ) {
					// If darkbox is shown
					if ( 0 === $(".livebox-frame:hidden").length ) {
						e.preventDefault();
						closeBox();
					}
				}
			}

			function handleImageLoadError() {
				$( 'div.livebox-canvas' ).addClass( 'livebox-canvas-error' );
				setTimeout( closeBox, imageErrorFadeOutTime );
			}

			function handleImageLoad() {
				var img = $( this ),
					frame = img.parents( 'div.livebox-frame' ),
					canvas = img.parents( 'div.livebox-canvas' ),
					ratio = 1,
					img_width = img.width(), img_height = img.height(),
					frame_width = frame.width(), frame_height = frame.height();
					img.css('opacity',0);
					$('<div class="beonoGlobus"></div>').prependTo(canvas);
					var beono = canvas.children( 'div.beonoGlobus' );

				if ( 0 === img_width && 0 === img_height ) {
					setTimeout( function (){ img.load(); }, 10 );
					return;
				}

				if (
					( img_width > frame_width - boxMargin ) ||
					( img_height > frame_height - boxMargin )
				) {
					ratio = Math.min(
						( frame_width - boxMargin ) / img_width,
						( frame_height - boxMargin ) / img_height
					);

					img_width = Math.round( img_width * ratio );
					img_height = Math.round( img_height * ratio );

					img.css( { width: img_width, height: img_height } );
				}

				canvas.
					addClass( 'livebox-canvas-load' ).
					animate( {
						width:      img_width,
						marginLeft: -img_width / 2,
						height:     img_height,
						marginTop:  -img_height / 2
						}, imageFadeInTime,
						function () {
							$( this ).
								removeClass( 'livebox-canvas-load' ).
								addClass( 'livebox-canvas-done' );
						}
					);
				$( '.livebox-title', frame ).css({width:img_width -10});
				$('.live-photo .sprite').clone().width(img_width*8).height(img_height).appendTo(beono);
				$(".beonoGlobus").beonoGlobus({ framesCount: 8});
					
			}
			if($('.livebox-frame').length == 0){
				$( '<div class="livebox-frame"><div class="livebox-shadow"></div><div class="livebox-canvas"><img><div class="livebox-title"></div><div class="livebox-button" title="Закрыть"></div></div></div>' ).
					children( 'div.darkbox-shadow' ).
						click( closeBox ).
						end().
					find( 'div.livebox-button' ).
						addClass( buttonPlaceClass ).
						click( closeBox ).
						end().
					find( 'img' ).
						load( handleImageLoad ).
						end().
					appendTo( 'body' ).
					end();	
			}


			$( document ).
				keypress( handleKey ).
				keydown( handleKey );
			this.live('click', openBox );

			return this;
		};
	} ( jQuery ) );
	
	$( 'a.live' ).livebox();
	$( 'a.make_live' ).livebox();
	
});


/**
 * @author Beono | http://www.beono.ru | ibeono@gmail.com
 * @version 0.8	 | 2010.04.18
 * 
 * © License: GPLv2
 *
 */
 
var beonoGlobusIdCounter = 0;
(function($){
	
	var obBeonoGlobus = new Array();
	jQuery.fn.beonoGlobus = function(options) {	
		
	var settings = {
		rotationSpeed: 100,
		framesCount: 8,
		currentFrame: 0,
		api: false,
		length: 0,
		mouseControl: true,
		keyboardControl: true,
		mouseTurns: 2,
		debug: false,
		rotateLeftButton : false,
		rotateRightButton : false,
		rotateResetButton : false,
		fadeInTime : 0,
		onReady: function () { return true; },
		onBeforeRotateLeft: function () { return true; },
		onAfterRotateLeft: function () { return true; },
		onBeforeRotateRight: function () { return true; },
		onAfterRotateRight: function () { return true; },
		onBeforeStop: function () { return true; },
		onAfterStop: function () { return true; }
	};
	
	settings = jQuery.extend(settings, options);	
	
	this.each(function(i) {
		// Generate id for each plugin object		
		obBeonoGlobus[beonoGlobusIdCounter] = new beonoGlobus(jQuery(this), beonoGlobusIdCounter);
		beonoGlobusIdCounter++;	
	});	
	
	function beonoGlobus (linkObj, id) {

		jQuery(linkObj).attr("id", "beonoGlobus-"+id);
			
		this.id = id;
		this.linkObj = linkObj;
		this.selector = "#beonoGlobus-"+this.id;
		this.obSelector = jQuery("#beonoGlobus-"+this.id);
		this.sprites = true;
		this.mouseTurns = settings.mouseTurns;
		this.mouseControl = settings.mouseControl;
		this.keyboardControl = settings.keyboardControl;
		this.framesCount = settings.framesCount;		
		this.currentFrame = settings.currentFrame;
		this.currentDirection = null;
		this.isMouseMoving = null;
		this.isKeyPressed = null;
		this.rotationSpeed = settings.rotationSpeed;
		this.rotateAuto = "";
		this.rotationMode = "default";
		this.rotateLeftButton = settings.rotateLeftButton;
		this.rotateRightButton = settings.rotateRightButton;
		this.rotateResetButton = settings.rotateResetButton;
		this.fadeInTime = settings.fadeInTime;
		this.onReady = settings.onReady;
		this.onBeforeRotateLeft = settings.onBeforeRotateLeft;
		this.onAfterRotateLeft = settings.onAfterRotateLeft;
		this.onBeforeRotateRight = settings.onBeforeRotateRight;
		this.onAfterRotateRight = settings.onAfterRotateRight;
		this.onBeforeStop = settings.onBeforeStop;
		this.onAfterStop = settings.onAfterStop;
		
		var __instance = this;
		
		$("#beonoGlobus-"+__instance.id).addClass("loading");
		var src = $("#beonoGlobus-"+__instance.id+" .sprite").hide().attr("src");
		
		// $("#beonoGlobus-"+__instance.id+" img")
		// .removeAttr("src").attr("src", src).load(function () {		
			__instance.frameWidth = $("#beonoGlobus-"+__instance.id+" .sprite").width() / __instance.framesCount;
			$("#beonoGlobus-"+__instance.id).removeClass("loading").css({
				"height": $("#beonoGlobus-"+__instance.id+" .sprite").height() + "px",
				"width": __instance.frameWidth + "px"
			}).find(".sprite").css({
				"position": "absolute", 
				"width": __instance.framesCount * __instance.frameWidth + "px"
			}).find("img").css({
				"width": __instance.frameWidth + "px",
				"height":$("#beonoGlobus-"+__instance.id+" .sprite").height() + "px",
				"margin":0,
				"padding":0,
				"border":0,
				"display":'block',
				"float":"left"
			});
			$("#beonoGlobus-"+__instance.id+" .sprite").fadeIn(__instance.fadeInTime);
			__instance.onReady();
		// });
		
		// Events
		if (this.rotateLeftButton ) {
			jQuery(this.rotateLeftButton).bind("mousedown", function () {
				jQuery(this).addClass("active");
				__instance.rotateStop();
				__instance.rotateLeft();
				return true;
			});
			
			jQuery(this.rotateLeftButton).bind("mouseout mouseup", function () {
				jQuery(this).removeClass("active");
				if (__instance.getRotationMode() != 'auto') { 
					__instance.rotateStop();
					return true;
				}
			});
		}
		if (this.rotateRightButton) {
			jQuery(this.rotateRightButton).bind("mousedown", function () {
				jQuery(this).addClass("active");
				__instance.rotateStop();
				__instance.rotateRight();
				return true;
			});
			
			jQuery(this.rotateRightButton).bind("mouseout mouseup", function () {
				jQuery(this).removeClass("active");
				if (__instance.getRotationMode() != 'auto') { 
					__instance.rotateStop();
					return true;
				}
			});		
		}
				
		
		
		this.easyStop = function () {
		
			var i = 0;
			for (i=0;i<=5;i++)
			{
				if (__instance.getCurrentDirection() == "left") {
					setTimeout(function () { __instance.rotateLeft(); } , __instance.rotationSpeed*i);
				} else if (__instance.getCurrentDirection() == "right") {
					setTimeout(function () { __instance.rotateRight(); } , __instance.rotationSpeed*i);
				}
			}
		};
		
		var next_point = null;
		var prev_mouse_position = null;	
		
		this.mouseDownHandler = function () {
			__instance.isMouseMoving = true;
			__instance.rotateStop();
			return false;
		};
		
		this.mouseUpHandler = function () {		
			__instance.isMouseMoving = false;
			prev_mouse_position = null;
			next_point = null;
			__instance.setCurrentDirection(false);		
			return true;
		};				
			
		this.mouseMoveHandler = function (e) {
			
			
			// Если ширина очень маленькая или кнопка мыши не была нажата
			if (!__instance.isMouseMoving) {
				return true;
			}

			var current_mouse_position = e.pageX - jQuery("#beonoGlobus-"+__instance.id).offset().left;
			//var current_mouse_position = e.pageY - jQuery("#beonoGlobus-"+__instance.id).offset().top;
			
					
			// Вычисляем направление
			if (current_mouse_position > prev_mouse_position) {
				__instance.setCurrentDirection("right");
			} else if (current_mouse_position < prev_mouse_position) {
				__instance.setCurrentDirection("left");
			}

			// Вращаем
			if (current_mouse_position > next_point && __instance.getCurrentDirection() == "right" && prev_mouse_position) {
				__instance.rotateStop();
				__instance.rotateRight();
			} else if (current_mouse_position < next_point && __instance.getCurrentDirection() == "left" && prev_mouse_position) { 
				__instance.rotateStop();
				__instance.rotateLeft();
			}

			// Ширину всего контейнера делим на кол-во изображений,
			// таким образом определяя интервал переключений кадров
			if (current_mouse_position > next_point && __instance.getCurrentDirection() == "right") { 
				next_point = parseInt(current_mouse_position) + (jQuery("#beonoGlobus-"+__instance.id).width() / __instance.framesCount) / __instance.mouseTurns;
			} else if (current_mouse_position < next_point && __instance.getCurrentDirection() == "left") {
				next_point = parseInt(current_mouse_position) - (jQuery("#beonoGlobus-"+__instance.id).width() / __instance.framesCount) / __instance.mouseTurns;
			}

			prev_mouse_position = current_mouse_position;

			return false;
		};
		
		this.keyDownHandler = function(event) {
			switch (event.keyCode) {
				case 37:
					if (__instance.isKeyPressed) return false; 
					__instance.isKeyPressed = true;
					__instance.rotateStop();
					__instance.rotateLeft();
				break;
				case 39:
					if (__instance.isKeyPressed) return false; 
					__instance.isKeyPressed = true;
					__instance.rotateStop();
					__instance.rotateRight();
				break;
			}			
		};
		
		this.keyUpHandler = function(event){
			if (event.keyCode == 37 || event.keyCode == 39) {
				__instance.isKeyPressed = false;
				for (i in obBeonoGlobus) {
					if (obBeonoGlobus[i].getRotationMode() == 'default') {
						obBeonoGlobus[i].rotateStop();
					}
				}
			}
		};
		
		// Methods
		this.debug = function (value) {
			if (settings.debug) {
				$(".debug").html(value +  "<br/>");
			}
		};
		
		this.setMouseControl = function (value) {
   			this.mouseControl = value;
   			if (value) {
	   			jQuery("#beonoGlobus-"+this.id).bind("mousedown", __instance.mouseDownHandler);
	   			jQuery("html").mousemove(__instance.mouseMoveHandler);  
	   		} 			
   		}
   		
   		this.getMouseControl = function () {
   			return this.mouseControl;
   		}
   		
   		this.setKeyboardControl = function (value) {
   			this.keyboardControl = value;
   			if (value) {
	   			jQuery("html").mouseup(__instance.mouseUpHandler);
				jQuery(document).keydown(__instance.keyDownHandler);			
				jQuery(document).keyup(__instance.keyUpHandler);
			}
   		}
   		
   		this.getKeyboardControl = function () {
   			return this.keyboardControl;
   		}
   		
   		this.setRotationMode = function (value) {
   			this.rotationMode = value;
   		}
   		
   		this.getRotationMode = function () {
   			return this.rotationMode;
   		}
   		
   		this.setRotationSpeed = function (value) {
   			this.rotationSpeed = value;
   		}
   		
   		this.getRotationSpeed = function () {
   			return this.rotationSpeed;
   		}
   		
   		if(this.rotateResetButton) {
   			$(this.rotateResetButton).live("click", function () { __instance.rotateToFrame(0);});
   		}
   		
   		if(this.mouseControl) {
			this.setMouseControl(true);
		}
		
		// Обработка нажатий клавиш клавиатуры
		if(this.keyboardControl) {
			this.setKeyboardControl(true);
		}
   		
   		this.rotateToFrame = function (frameNumber) {
   			
	   		if (this.currentFrame != frameNumber && frameNumber <= this.framesCount) {

	   			if (!this.getCurrentDirection()) {
		   			if((this.framesCount / 2) > this.currentFrame) {
		   				this.setCurrentDirection("left");
		   			} else {
		   				this.setCurrentDirection("right");
		   			}
		   			
	   			} else if(this.getCurrentDirection() == "left") {
	   				this.rotateLeft(); 
	   			} else {
	   				this.rotateRight(); 
	   			}	   				   		

				setTimeout(function () { 
		   			__instance.rotateToFrame(frameNumber); 
		   		}, this.rotationSpeed/2);
	   		} else {
	   			__instance.rotateStop();
	   		}
   				   		
   		}
	
		this.rotateLeft = function () {
		
			this.onBeforeRotateLeft();

			this.setCurrentDirection("left");
			// Если автопросмотр включен и setInterval ещё не был запущен
			if ((jQuery(this.rotateLeftButton).hasClass("active") || this.isKeyPressed || this.getRotationMode() == 'auto') && !this.rotateAuto) {	
				this.rotateAuto = setInterval(function () { __instance.rotateLeft(); }, this.rotationSpeed);
			}
			
			// Если текущий кадр последний
			if (this.currentFrame+1 >= this.framesCount) {
				this.currentFrame = -1;
			}
			this.currentFrame += 1;
			$("#beonoGlobus-"+this.id+" .sprite").css("left", "-"+this.currentFrame * this.frameWidth + "px");

			this.onAfterRotateLeft();
			
		}		
	
		this.rotateRight = function () {

			this.onBeforeRotateRight();
			
			__instance.setCurrentDirection("right");
			// Если автопросмотр включен и setInterval ещё не был запущен
			if ((jQuery(this.rotateRightButton).hasClass("active") || this.isKeyPressed || this.getRotationMode() == 'auto') && !__instance.rotateAuto) {						
				this.rotateAuto = setInterval(function () { __instance.rotateRight(); }, this.rotationSpeed);
			}

			// Если текущий кадр последний
			if (this.currentFrame < 1) {
				this.currentFrame = this.framesCount;
			}
			this.currentFrame -= 1;
			$("#beonoGlobus-"+this.id+" .sprite").css("left", "-"+this.currentFrame * this.frameWidth + "px");
		
			this.onAfterRotateRight();
		}
				
		this.rotateStop = function () {
		
			__instance.onBeforeStop();
		
			if (__instance.rotateAuto) {
				window.clearInterval(__instance.rotateAuto);
				__instance.rotateAuto = false;
			}
			/*var easy = false;
			if (!easy) {
				__instance.easyStop();
			}*/
			__instance.setCurrentDirection(false);
			__instance.onAfterStop();
		}
		
		this.getCurrentDirection = function () {
			return this.currentDirection;
		}
		
		this.setCurrentDirection = function (value) {
			__instance.currentDirection = value;
		}	
	} 

	// Очищаем параметры с которыми вызван плагин
	options = false;
	
	if (settings.api == "last") {
	
	
	} else if(settings.api == true || settings.api == 'all') {
		var iter = 0;
		returnObj = new Array();
		for (i in obBeonoGlobus) {
			returnObj[iter] = obBeonoGlobus[i];
			iter++;
		}
		return returnObj;
	} else {
		return this;
	}
	 
	};
})(jQuery);

