// JavaScript Document

window.addEvent('domready', function() {
	
	
	//store titles and text
	$$('.tipsData').each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
	});
	
	//create the tooltips
	var tipz = new Tips('.tipsData',{
		className: 'tipsData',
		fixed: true,
		hideDelay: 50,
		showDelay: 50
	});
	tipz.addEvents({  
        'show': function(tip) {  
            tip.fade('in');  
        },  
        'hide': function(tip) {  
            tip.fade('out');  
        }  
    });
	
	/****
		RATING
	*****/
	
	
	$$('.rate').each(function(element,i){
	
	element.addEvent('click', function(){
		var myStyles = ['nostar', 'onestar', 'twostar', 'threestar', 'fourstar', 'fivestar'];
		myStyles.each(function(myStyle){
			if(element.getParent().hasClass(myStyle)){
				element.getParent().removeClass(myStyle)
			}
		});		
		
		myStyles.each(function(myStyle, index){

			var id = element.getParent().id.split('_')[1];
		
			if('rate'+id+'_'+index === element.id){

				var voto = element.id.split(id+'_')[1];
				
				ajaxCall("/modulo_opcoes_votar_noticias_"+id+".html?votos="+voto, 'voteTarget'+id, true);
				
				element.getParent().toggleClass(myStyle);
				
			}
		});		
	});
});
if($('box4')){
	var nS4 = new noobSlide({
				box: $('box4'),
				items: $$('#box4 div'),
				size: 460,
				autoPlay: true,
				handles: $$('#handles4 a'),
				onWalk: function(currentItem,currentHandle){
					this.handles.removeClass('active');
					currentHandle.addClass('active');
				}
			});	
};
if($('wrap')){
	// Let's define some variables first
	var wrapper = $('wrap'); // The outer wrapper
	var carousel = $('carousel'); // The inner wrapper
	var items = $$('#carousel li'); // The different elements, this is an array
	var item_width = 450; // The full width of a single item (incl. borders, padding, etc ... if there is any)
	var max_margin = items.length * item_width - item_width;
	
	// Set up the animation
	var animation = new Fx.Tween(carousel, {duration: 500});
	
	// The function to browse forward
	function next_item(pos){
		if(pos == -max_margin){
			animation.start('left', 0);
		} else { 
			var newposition = pos - item_width;
			animation.start('left', newposition);
		}
	}
	
	// The function to browse backward
	function previous_item(pos){
		if(pos == 0){
			animation.start('left', -max_margin);
		} else { 
			var newposition = pos + item_width;
			animation.start('left', newposition);
		}
	}
	
	// Set up the 'next' and 'previous' buttons
	$('next').addEvent('click', function(){
		var position = parseInt(carousel.getStyle('left'));
		next_item(position);
	});
	
	$('previous').addEvent('click', function(){
		var position = parseInt(carousel.getStyle('left'));
		previous_item(position);
	});
}

});