window.addEvent('domready', function(event){
	var start = Cookie.read('fontsize') || '12';
	var noticia = $('noticia');
	var contentArea = $('ContentArea');
	
	if(noticia){
		noticia.setStyle('font-size',start + 'px');
		var noticiaH1 = $('noticia').getElements("h1");
	}
	if(noticiaH1)
		noticiaH1.setStyle('font-size',(start+4) + 'px');
	if(contentArea)
		contentArea.setStyle('font-size',start + 'px');
		
	if($('FontSizeSlider')){
		var slider = new Slider($('FontSizeSlider'),$('FontSizeSlider').getElement('#sliderthumb'), {
			range: [12, 20],
			onChange: function(){
				Cookie.write('fontsize',this.step);	
				if(noticia)
					noticia.setStyle('font-size', this.step + 'px'); 
				if(noticiaH1)
					noticiaH1.setStyle('font-size', (this.step+4) + 'px');
				if(contentArea)
					contentArea.setStyle('font-size', this.step + 'px');
			}
		}).set(14);
	}
	/**
	 * Star Rating	
	 */
	if($('mstar0') && $('mstarval0'))
	new MOORating(
			$('mstar0'),
			$('mstarval0'),
			{
				onUpdate:function(id, rating){
				$('currentRating').set('text', '');
					$('currentRating').set('html', "<img src='"+Constants.pathDomain+"/images/ajax-loader-small.gif' />");
					var req = new Request.HTML({
						url:Constants.pathDomain+"leafs/rating",
						update : $('currentRating'),
						onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
							if($('currentRating')){
								$('currentRating').set('text', '');
								$('currentRating').set('html', responseHTML);
								//$('currentRating').adopt(responseHTML);
								new MOORating(
										$('mstar1'),
										$('mstarval1'),
										{
											isFractional:true,
											valueOnly:true
										}
									);
							}
						},
						onFailure: function() {
						}
					});//.post("leaf="+$('leafid').value+"&value="+rating);
					req.send("leaf="+$('leafid').value+"&value="+rating);
				},
				valueOnly:false
			}
		);
	
	
		//Video Component
		if($('video-gallery')){
			new noobSlide({
				box: $('video-gallery'),
				items: $$('#video-gallery div'),
				size:110,
				show: 2,
				autoPlay: true,
				addButtons: {
					previous: $('videos-prev'),
					next: $('videos-next')
				}
			});
		}
		
		
		//Top News Module
		var container = $('topTabs')
	   var topViewTabs = new SimpleTabs(container, {
	        selector: 'h1' // every element with class .header is removed and added as tab
	    });
		
		if($('track1')){
			var slider = new Slider($('track1'),$('track1').getElement('#handle1'), {
				range: [1, 30],
				onComplete: function(){
					var step = this.step;
					$('rango').set('text', step+" days"); 
					 new Request.HTML({
										url: Constants.pathDomain+"leafs/topViews/0-"+step,
										onComplete: function(responseTree, responseElements, responseHTML) {
						 					var container = $('topViewsHolder');
						 					if(container){
						 						container.empty();
						 						container.adopt(responseTree);
						 					}
						 						
										}
					 				  }).send();
					
				},
				onChange:function(pos){
					$('rango').set('text', pos+" days");
				}

			}).set(30);
		}
		/**
		 * Mail catching
		 */
			var sendByMail = $('sendByMail');
			if( sendByMail && ( !$defined(sendByMail.flag) || sendByMail.flag != true )){
				sendByMail.addEvent('click', function(e){
					sendByMail.flag = true;
					var at_send = $('at_send');
					if(at_send){
						if(!$defined(window.at_send_flag) || window.at_send_flag != true){
							window.at_send_flag= true;
									at_send.addEvent('click', function(e){
									new Request.JSON(
													{ 
														url:Constants.pathDomain+"email/save" 
													}
											).get({'email': $('at_to').value});
									new Request.JSON(
											{ 
												url:Constants.pathDomain+"email/save"
											}
									).get({'email': $('at_from').value});
								
							});
						}
					}
				});
			}
		
	
	
});