/*
 * jQuery rgHelpModule for www.imisp.ru
 *
 */
 
jQuery.fn.rgHelpModule = function(){
    
	return this.each(function() {
		
		var openForm = false;
		var operator1 = $(this).find('.operator1-block');
		var operator2 = $(this).find('.operator2-block');
		var operators = $(this).find('.operator1-block, .operator2-block');
		var hid = document.getElementById('operator');
		
		operators.hover(function(){
			if(!openForm) $(this).addClass('hover');
		},function(){
			if(!openForm) $(this).removeClass('hover');
		});
        
		operators.click(function(){
			if(!$(this).hasClass('none-hover')){
				if(openForm){
					castling();
				}else{
					if($(this).css('z-index')=='1'){
						castling(function(){$.nyroModalSettings({width: 710, height: 390});});
					}else{
						hid.value=1;
						$.nyroModalSettings({width: 710, height: 390});
						operator1.addClass('none-hover');
						operator2.addClass('none-active');
					}
				}
				$(this).removeClass('hover');
				openForm = true;
				
			}
		});
		
		function castling(func){
			if(operator1.css('left')=='355px'){
				hid.value=1;
				operator1.css('z-index','2').removeClass('none-active').addClass('none-hover');
				operator2.css('z-index','1').removeClass('none-hover').addClass('none-active');
				operator1.animate({left:'0px'},500);
				operator2.animate({left:'355px'},500,func);
				
			}else{
				hid.value=2;
				operator1.css('z-index','1').removeClass('none-hover').addClass('none-active');
				operator2.css('z-index','2').removeClass('none-active').addClass('none-hover');
				operator1.animate({left:'355px'},500);
				operator2.animate({left:'0px'},500,func);
			}
		};
		
	});
	
	

};
