/*
 * ----------------------------------------------------
 * Mootools extensions
 * ----------------------------------------------------
 * by Limarc /Alexander Lobashev/
 * (c) 2007-2008 by Limarc, Lim-on Media
 * Web: http://www.lobashev.org
 *      http://www.limon-media.org
 * ----------------------------------------------------
 * Index: mootools-ext.js
 * ----------------------------------------------------
 */


 window.addEvent('domready', function()
 {
     //var QT = new Quicktabs();
     var QT = new Qtabs('quick-info');
     
     var Menu = new DropMenu('navmenu-h');
     
     //
     // F.A.Q.
     //
     $('faq-form').fade('out');
     $('sigur').addEvent('click',  function (event)
     {
	     //alert(event.target.getProperty('id'));
             
             if ($('faq-form').getStyle('display') == 'block')
             {
                     $('faq-form').fade('out');
                     //$('faq-form').setStyle('display', 'none');
             }
     });
     
     $('faq-question').addEvent('click',  function (event)
     {
	     event.stop();
             
             $('faq-form').fade('in');
             $('faq-form').setStyle('display', 'block');
     });
     
     $('faq-form').addEvent('click',  function (event) { event.stop(); } );
     $('faq-submit').addEvent('click',  function () { _sendQuestion(); return false; } );
     $('faq-send').addEvent('submit',  function () { _sendQuestion(); return false; } );
	 
     function _sendQuestion ()
     {
             var req = new Request(
             {
		 url: '/publication/faq/send/',
		 method: 'post',
		 onSuccess: function (answer)
		 {
                         if (answer == 'complete')
                         {
                                 $$('.content-form').set('html', "<p id='send-error' style='color: #ff8757; padding-top: 15px;'>Спасибо. Ваш вопрос отправлен!</p><p> Окно закроется автоматически...</p>");
                                 
                                 (function()
                                 {
                                         $('faq-form').fade('out');
                                         $('faq-form').setStyle('display', 'none');
                                         
                                 }).delay(3000);
                                 //$$('.category-contacts').set('html', '');
                         }
                         
                             if (answer == 'full_field')
                             {
                                     $('send-error').set('html', "&mdash; Необходимо заполнить требуемые поля");
                             }                                         
			 }
		 }).send($('faq-send').toQueryString());
             }                  
     });

 
 /*
  * > Tabs
  * > by limarc 
  * > v1.1.0
  *
  */
 var Qtabs = new Class
 ({
	
	 options:
         {
		 activateClass: 	'active',
                 //activateClassOther: 	'active-other',
		 activateOnLoad:	'company'
         },
	
	 initialize: function(element, options)
	 {
		 //
                 // Set option...
                 //			
		 if (options)
                 {
                         this.setOptions(options);
                 }
                 
		 this.el = $(element);
		 this.contid = element;                 
                 
                 this.titles = $$('#' + this.contid + ' ul#quick-tabs li');
                 this.panels = $$('#' + this.contid + ' .qtabs-block');
                 
		 this.titles.each(function(item)
                 {
                         if (item.getProperty('class') != 'none')
			 {
                                 $$('#show-' + item.getProperty('id')).fade('out');
                                 $$('#show-' + item.getProperty('id')).setStyle('display', 'none');
                                 
                                 //
                                 // Clicked...
                                 //
                                 item.addEvent('click', function()
                                 {
                                         document.location.href = item.getChildren('a');
                                         
                                 }.bind(this));
                                
                                 //
                                 // Mouse over...
                                 //                        
                                 item.addEvent('mouseover', function()
                                 {
                                         if (item != this.activeTitle)
                                         {
                                                 item.addClass(this.options.activateClass);
                                                 this.activate(item);
                                         }
                                 }.bind(this));
                                
                                 //
                                 // Mouse out...
                                 //                                
                                 /*item.addEvent('mouseout', function()
                                 {
                                         if (item != this.activeTitle)
                                         {
                                                 item.removeClass(this.options.activateClass);
                                         }
                                 }.bind(this));*/
                         }
                         
                 }.bind(this));
                 
                 if (this.options.activateOnLoad != 'none')
		 {
			 var activeTab = $(this.options.activateOnLoad);
                         
                         this.activate(activeTab);
		 }                 
	 },
	
	 activate: function(tab)
         {
                 /*if ($type(tab) == 'string') 
		 {
			 tab = $$('#' + this.contid + ' ul li').filter('[title=' + tab + ']')[0];
		 }*/
		
		 if($type(tab) == 'element')
		 {
			 var newTab = tab.getProperty('id');
                         var newTabBlock = $$('#show-' + newTab);
                         var myFx = new Fx.Tween(newTabBlock);
                         
			 //
                         // De-activated last tab...
                         //
                         if (this.activeTitle)
                         {
                                 //alert(this.activeTitle.getProperty('id'));
                                 this.activeTitle.removeClass(this.options.activateClass);
                                 
                                 $$('#show-' + this.activeTitle.getProperty('id')).fade('out');
                                 $$('#show-' + this.activeTitle.getProperty('id')).setStyle('display', 'none');
                                 //myFx.start('display', 'none', 'block');
                         }

			 //
                         // Activated new tab...
                         //                         
                         tab.addClass('active');
                         
			 //
                         // Show block new tab...
                         //

                         //Immediately sets the background color of the element to red:
                         //myFx.start('display', 'none', 'block');
                         //myFx.set('display', 'block');
                         
                         newTabBlock.fade('in');
                         newTabBlock.setStyle('display', 'block');
                         
			 //
                         // Save new tab...
                         //                           
                         this.activeTitle = tab;
		 }
	 },        
        
	 Implements : [Events]
 });
  

