if(typeof(Class) != 'undefined') {
	
	
	
	window.addEvent('domready', function() {
					
		__body = $('body');
		
		function updateClock ( ) {
			var cT = new Date ( );
			
			var cH = cT.getHours ( );
			var cM = cT.getMinutes ( );
			var cS = cT.getSeconds ( );
			cM = ( cM < 10 ? "0" : "" ) + cM;
			cS = ( cS < 10 ? "0" : "" ) + cS;
			
			$("clock").set('html', cH + ":" + cM + ":" + cS);
		}
		
		updateClock();
		setInterval(updateClock, 1000);
		
		/*
		*	FEEDBACK
		*/
		if($('contacts')) {
			$('contacts').set('action', '/ajax/feedback/');	
			$('contacts').getElements('[type=text], textarea').each(function(el){ new OverText(el); });
			new Form.Validator($('contacts'), { serial:true });
			
			new Form.Request($('contacts'), $('res'), {
				requestOptions: { 'spinnerTarget': $('contacts') },
				onSuccess: function() { $$('.hider').setStyle('display', 'none'); $$('.unhider').setStyle('display', 'block'); }
			});
			
		}
		if($('uniform')) {
			$('uniform').set('action', '/ajax/' + $('uniform').get('rel') + '/');	
			$('uniform').getElements('[type=text], textarea').each(function(el){ new OverText(el); });
			new Form.Validator($('uniform'), { serial:true });
			
			new Form.Request($('uniform'), $('res'), {
				requestOptions: { 'spinnerTarget': $('uniform') },
				onSuccess: function() { $$('#uniform .hider').setStyle('display', 'none'); $$('#uniform .unhider').setStyle('display', 'block'); }
			});
			
			$$('.sel').addEvent('click', function() {
				$$('.hidemeon').setStyle('display', 'none');
				if($(String(this.get('id')).replace('in_', ''))) $(String(this.get('id')).replace('in_', '')).setStyle('display', 'block');
			});
			
		}
		
		
		/*
		*
		*/
		var tabPane = new TabPane('tabbedcnt');
		try { tabPane.showTab(String(window.location.hash).replace('#', '') * 1 - 1); } catch(e) {}

		
		/*
		*	TOP NAV
		*/
		_th = null; _ths = null; _thm = null; _d = 300;
		
		$$('.cntmenu ul .lv1').addEvents( {
				'mouseenter':function(el) { clearTimeout(_th); clearTimeout(_ths); clearTimeout(_thm); _th = (function() { $$('.selected').removeClass('active'); $$('.hover').removeClass('hover'); this.addClass('hover'); this.getChildren('ul').setStyle('display', 'block'); }).bind(this).delay(_d); },
				'mouseleave':function(el) { clearTimeout(_th); clearTimeout(_ths); clearTimeout(_thm); _ths = (function() { $$('.selected').addClass('active'); this.removeClass('hover'); this.getChildren('ul').setStyle('display', 'none'); }).bind(this).delay(_d); }
		} );

		$$('.cntmenu ul .lv2').addEvents( {
				'mouseenter':function(el) { clearTimeout(_th); clearTimeout(_ths); }
		} );
		
		$$('.cntmenu').addEvents( {
				'mouseleave':function(el) { clearTimeout(_th); clearTimeout(_ths); clearTimeout(_thm); _thm = (function() { $$('.hover').removeClass('hover'); $$('.selected').addClass('active'); }).delay(_d);  }
		} );
					
		/*
		*	ADMIN DD MENU
		*/
		try { var tpm = new DDown_Menu('ddadmin', '#ddadmin ul'); } catch(e) {}
		try { var sb = SqueezeBox.initialize({ size: {x: 350, y: 400}, onOpen:function() { $$('html').setStyles({'overflow':'hidden'}); }, onClose:function() { $$('html').setStyles({'overflow':''}); } }); document.sb = sb; } catch (e) {}
		try { document.sb.assign($$('a.boxed'), { parse: 'rel' }); } catch(e) { }
		
		/*
		*	MISC HNDLS
		*/
		$$('.printlink').addEvent('click', function() { window.print(); return false; } );
		
		if(bp_ph = $('homepage_bigpics')) {
			
			bp_ph.addEvent('mouseover', function() { bp_paused = true; }); bp_ph.addEvent('mouseout', function() { bp_paused = false; } );
			
			bp_items = $$('#homepage_bigpics .ph');
			bp_bulitems = $$('#homepage_bigpics .phbullet');
			
			bp_paused = false;
			bp_cur = 0;
			bp_max = bp_items.length; 
			bp_items.setStyles({'opacity':0, 'visibility':'visible'});
			bp_bulitems.setStyles({'opacity':0.5, 'visibility':'visible'});
			bp_items[bp_cur].setStyle('z-index', 999);
			
			bp_items.each(function(el) { 
				if(el.get('rel')) { 
					el.addClass('clickable'); 
					el.addEvent('click', function() { 
						if(this.get('target') == '_blank') window.open(this.get('rel'));
						else window.location = this.get('rel'); 
						return false;
					}); 
				} 
			});
			
			bp_items[bp_cur].set('tween', {'duration':'long'}).fade(1);
			
			setInterval(function() {
				if(bp_paused) return;
				
				bp_items[bp_cur++].set('tween', {'duration':'long'}).fade(0).setStyle('z-index', 1);
				if(bp_cur == bp_max) bp_cur = 0;
				bp_items[bp_cur].set('tween', {'duration':'long'}).fade(1).setStyle('z-index', 999);
				
				bp_bulitems.setStyle('opacity', 0.5);
				bp_bulitems[bp_cur].setStyle('opacity', 1);
				
			}, 3500);
			
		}
		
		function fadeRB() {
			if(this.over) return;
			if(this.delay) { this.delay--; return; }
			
			cur = this.get('cur');
			this.getChildren('.pic')[cur].set('tween', {'duration':800}).fade(0);
			if((++cur) >= this.get('pmax')) cur = 0;
			this.set('cur', cur);
			this.getChildren('.pic')[cur].set('tween', {'duration':800}).fade(1);
		}
		
		if(rb_ph = $('homerightbanners')) {
			rb_items = $$('#homerightbanners .ph');

			cnt = 0;
			rb_items.each(function(el) { 
				if(el.get('rel')) { 
					el.addClass('clickable'); 
					el.addEvent('click', function() { window.location = this.get('rel'); }); 
				}
				el.set('pmax', pmax = (ppics = el.getChildren('.pic')).length);
				el.set('cur', pmax - 1); 
				ppics.set('opacity', 0); ppics[pmax - 1].set('opacity', 1);
				ppics.set('tween', {'duration':'long'});
				
				el.addEvent('mouseenter', function(e) { this.over = true; } );
				el.addEvent('mouseleave', function(e) { this.over = false; } );
				setTimeout( function() { fadeRB.apply(el); el.timer = fadeRB.periodical(3600, el); }, cnt*1200);
//				el.delay = cnt;
				
				cnt++;
			});
		}
		
		if(pr_ph = $('homepage_promo')) {
			
			pr_strip = $$('#homepage_promo .strip')[0];
			pr_items = $$('#homepage_promo .ph');
			pr_max = Math.ceil(pr_items.length / 4); 
			pr_cur = 0;
			pr_strip.tween('left', 0);
			
			pr_items.each(function(el) { 
				if(el.get('rel')) { 
					el.addClass('clickable'); 
					el.addEvent('click', function() {
						if(this.get('target') == '_blank') window.open(this.get('rel'));
						else window.location = this.get('rel'); 
						return false;
					}); 
				} 
			});
			
			$$('#homepage_promo .right').addEvent('click', function() { 
				pr_cur ++ ;
				if(pr_cur == pr_max) { pr_cur = pr_max - 1; return; }
				pr_strip.tween('left', -pr_cur * 616);
			});
			
			$$('#homepage_promo .left').addEvent('click', function() { 
				pr_cur --;
				if(pr_cur < 0) { pr_cur = 0; return; }
				pr_strip.tween('left', -pr_cur * 616);
			})
			
			
		}


	});	




	function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse) {
		var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y));

		if(!steps) {
			handle.setStyle('display', 'none');
			scrollbar.setStyle('display', 'none');
			return;
		}
		
		var slider = new Slider(scrollbar, handle, {
			steps: steps,
			mode: (horizontal?'horizontal':'vertical'),
			onChange: function(step){
				var x = (horizontal?step:0);
				var y = (horizontal?0:step);
				content.scrollTo(x,y);
			}
		}).set(0);

		if( !(ignoreMouse) ){
			$$(content, scrollbar).addEvent('mousewheel', function(e){	
				e = new Event(e).stop();
				var step = slider.step - e.wheel * 30;	
				slider.set(step);					
			});
		}
		$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
	}
				
	window.addEvent('load', function(){				
		makeScrollbar( $('partners'), $('parnters_scr'), $('parnters_hnd'), true );
	});
	
	
/*
---
description: TabPane Class 

license: MIT-style

authors: akaIDIOT

version: 0.1

requires:
  core/1.2.4:
  - Class
  - Class.Extras 
  - Element 
  - Element.Event
  - Selectors
  more/1.2.4:
  - Element.Delegation

provides: TabPane
...
*/

var TabPane = new Class({
    
    Implements: [Events, Options],

    options: {
        tabSelector: '.tab',
        contentSelector: '.content',
        activeClass: 'active'
    },

    container: null,
    showNow: false,

    initialize: function(container, options) {
        this.setOptions(options);

        this.container = document.id(container);
		if(!this.container) return;
		
        this.container.getElements(this.options.contentSelector).setStyle('display', 'none');

        this.container.addEvent('click:relay(' + this.options.tabSelector + ')', function(event, tab) {
            this.showTab(this.container.getElements(this.options.tabSelector).indexOf(tab), tab);
        }.bind(this));

        this.container.getElement(this.options.tabSelector).addClass(this.options.activeClass);
        this.container.getElement(this.options.contentSelector).setStyle('display', 'block');
    },

    showTab: function(index, tab) {
        var content = this.container.getElements(this.options.contentSelector)[index];
        if (!tab) {
            tab = this.container.getElements(this.options.tabSelector)[index];
        }

        if (content) {
            this.container.getElements(this.options.tabSelector).removeClass(this.options.activeClass);
            this.container.getElements(this.options.contentSelector).setStyle('display', 'none');
            tab.addClass(this.options.activeClass);
            content.setStyle('display', 'block');
            this.fireEvent('change', index);
        } 
    },

    closeTab: function(index) {
        var tabs     = this.container.getElements(this.options.tabSelector);
        var selected = tabs.indexOf(this.container.getElement('.' + this.options.activeClass)); // is always equals to index 
        
        tabs[index].destroy();
        this.container.getElements(this.options.contentSelector)[index].destroy();
        this.fireEvent('close', index);

        // 'intelligently' selecting a tab is sadly not possible, the tab has already been switched before this method is called 
        this.showTab(index == tabs.length - 1 ? selected - 1 : selected);
    }

});
	
}
