$$('div.loader-overlay span').destroy();
$$('div.loader-indicator').setStyle('display', 'block');

$$('div.loader-overlay').set('tween', {
	fps: 100,
	duration: 400,
	transition: Fx.Transitions.Quint.easeInOut,
	property: 'opacity',
	onComplete: function(item){
		item.destroy();
	}
});

$$('div.loader-indicator').set('tween', {
	fps: 100,
	duration: 400,
	transition: Fx.Transitions.Quint.easeInOut,
	property: 'opacity',
	onComplete: function(item){
		$$('div.loader-indicator').setStyles({'display': 'none', 'opacity': 1});
	}
});

window.addEvents({
	'load': function(){
		$$('div.loader-overlay').tween(1, 0);
		$$('div.loader-indicator').tween(1, 0);
	},
	'unload': function(){
		$$('div.loader-indicator').setStyle('display', 'block');
	}
});

new Fx.SmoothScroll({duration: 400}, window);

$$('a:not(.anchor)').addEvent('click', function(){
	$$('div.loader-indicator').setStyle('display', 'block');
});

(function(){
	var height = $('language-list').getSize()['y'];
	
	var status = 0;

	$('language-selection').set('tween', {property: 'height', duration: 300, transition: Fx.Transitions.Sine.easeInOut, onComplete: function(){
		if(status == 0){
			$('language-selection').setStyles({'visibility': 'hidden'});
			$('language').removeClass('selected');
		}
	}});
	$('language').addEvent('click', function(){
		if(status == 0){
			this.addClass('selected');
			$('language-selection').setStyles({'visibility': 'visible', 'height': 0}).tween(height);
			status = 1;
		} else if(status == 1){
			$('language-selection').tween(0);
			status = 0;
		}
	});
	
})();

// Add to favourites
$$('a.anchor.add-to-favourites').addEvent('click', function(event){
   event.preventDefault();
   
   var title = document.title;
   var url = location.href;

   // Gecko
   if((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')){
       window.sidebar.addPanel(title, url, '');
       return false; 

   // IE
   } else if((Browser.ie7 || Browser.ie8) && typeof window.external == 'object'){
       if(Browser.ie8) window.external.AddToFavoritesBar(url, title);                   
       else window.external.AddFavorite(url, title);
       return false;

   // No bookmarks support
   } else if((Browser.safari || Browser.chrome || Browser.opera) && !Browser.mobile){
       var str;

       // Mac or windows
       if(navigator.userAgent.toLowerCase().indexOf('mac') != -1){
           if(Browser.opera) str = 'Command+Shift+D';
           else str = 'Command+D';
       } else str = 'Ctrl+D';

       alert(LANGUAGE.press + str + LANGUAGE.to_bookmark);
   } else alert(LANGUAGE.bookmark_manualy);

   return false;
});


// Fix footer margin
(function(){
   var paddingSize = Number.from(window.getSize()['y'] - $('container').getSize()['y']);
   var fixFooterMargin = function(paddingSize){
       
       if(paddingSize > 0){
           $('footer').setStyle('padding-bottom', paddingSize - $('foot-wrap').getSize()['y']-1);

           paddingSize = Number.from(window.getSize()['y'] - $('container').getSize()['y']);

           if(paddingSize > 0)
               $('footer').setStyle('padding-bottom', Number.from($('container').getStyle('padding-bottom')) + paddingSize - $('foot-wrap').getSize()['y']-1);
       }
   };
   
   fixFooterMargin(paddingSize);
   
   window.addEvent('resize', function(){
       paddingSize = Number.from(window.getSize()['y'] - $('container').getSize()['y']);
       if(paddingSize > 0){
           fixFooterMargin(paddingSize);
       }
   });
}());
