jQuery(document).ready(function () {
	base_url = press.baseurl;
	locked = press.locked;
	
	if (!locked) {
		jQuery('.clip').click(function(){
				jQuery('#clip-loader').fadeIn();
				jQuery('#clipping').load(base_url + 'press_ajax.php?clip='+jQuery(this).attr('id') , function() {
					jQuery('#clip-loader').fadeOut();
				});

		});
	}
	else {
		jQuery('.clip_title').hide();
		/*
			jQuery('.clip').click(function(){
				alert(jQuery(this).attr('id'));
				var id = jQuery(this).attr('id');
				id = id.substr(id.indexOf('_')+1);
				jQuery('#ppp').load(base_url + 'press_locked_ajax.php?id=' + id);
				
			});
		*/
		
		jQuery('.clip').hover(function (){
			jQuery('.clip_title').hide();
			var id = jQuery(this).attr('id');
			id = id.substr(id.indexOf('_')+1);
			jQuery('#cliptitle_'+id).show();
		});
		
		jQuery('.clip').mouseleave(function (){
			jQuery('.clip_title').hide();			
		});
		
		
		
		
		
	}
	/* Navegação clips */
	if(!locked)
		clips = {
				inicio: 1,
				fim: 4,
				total: jQuery('.clip').size()
		}
	else 
		clips = {
				inicio: 1,
				fim: 3,
				total: jQuery('.clip').size()
		}
	function clips_navigate_forward() {
		if (clips.fim < clips.total) {
			clips.inicio ++;
			clips.fim ++;
			clips_update()
		}
	}
	
	function clips_navigate_backward() {
		if (clips.inicio > 1) {
			clips.inicio --;
			clips.fim --;
			clips_update()
		}
	}
	
	function clips_update() {
		jQuery('.clip').hide();

		var i = 1;
		jQuery('.clip').each(function () {
			if (i >= clips.inicio && i <= clips.fim)
				jQuery(this).show();
			i++;
		});
		
		jQuery('.clips-arrows').show();
		
		if (clips.fim >= clips.total) {
			jQuery('#clips-right').hide();
		}
		
		if (clips.inicio == 1) {
			jQuery('#clips-left').hide();
		}
	}
	
	jQuery('#clips-right').click(function() {
		clips_navigate_forward();
	});
	
	jQuery('#clips-left').click(function() {
		clips_navigate_backward();
	});
	
	clips_update();
	
	
	
	
});
