// FUNCIONES PRINCIPALES Y EXTENCIONES JQUERY

function loading_open(no, text, buttons){
	if(no)$('#cfx-load-l').css({display:'none'});
	if(text)$('#cfx-load-t').css({display:'block'}).html(text);
	if(buttons)$('#cfx-load-bt').css({display:'block'}).html(buttons);
	$('#cfx-load-c').css({display:'none'}).fadeTo('fast',1, function(){$(this).center(); }).center();
	
	
	$('#cfx-load-b').fadeIn('slow')
	$('#cfx-load-b').height( ($('#body').height() < $(window).height()?$(window).height() : $('#body').height() ) ) ;
}
function loading_close(n){
	if(n == 'forse'){
		$('#cfx-load-l').css({'display':'block'});
		$('#cfx-load-t').html('');	
		$('#cfx-load-bt').html('');
		$('#cfx-load-c').center();
	}else
	$('#cfx-load-c').fadeOut('fast',function(){
		if(!n){
			$('#cfx-load-l').css({'display':'block'});
			$('#cfx-load-t').html('');	
			$('#cfx-load-bt').html('');
		}
		$(this).center();
	});
	$('#cfx-load-b').fadeOut('slow');
}


// ---- [END] FUNCIONES PRINCIPALES

// EXTENCIONES JQUERY


(function(){
	$.fn.carruselh = function(options) {
		var defaults={
			por:10
		}
		var ul=null;
		var leng=0;
		var w_li=0;
		var w_ul=0;
		var w_con=0;
		var settings = $.extend({}, defaults, options);

		return this.each(function(){
			ul= 	$(this).find('ul');
			leng=	ul.find('li').length;
			w_li=	ul.find('li').first().width();
			w_con= 	$(this).find('.cont').width();
			
			if(w_li<=0)w_li=64;
			w_ul= 	w_li * leng;
			ul.width(w_ul);
			ul.find('li').each(function(){
				$(this).hover(
				function(){$(this).fadeTo(300, 1 ); },
				function(){$(this).fadeTo(300, 0.7 );});
				
			});
			$(this).hover(
				function(){$(this).find('li').fadeTo(200, 0.7 ); },
				function(){$(this).find('li').fadeTo(200, 1 );});
			
			$(this).find('.next').click(function(){
				 var marg=parseInt(ul.css('margin-left').replace(/px/g, ''));
				 var pos = (marg + (w_li*settings.por));
				 if(pos > 0) pos=0;
				 ul.stop().animate({ 'margin-left' : (pos) + 'px'});
				
			});
			$(this).find('.prev').click(function(){
				 var marg=parseInt(ul.css('margin-left').replace(/px/g, ''));
				 var pos = (marg - (w_li*settings.por));
				 if(pos < -( w_ul - w_con )) pos = -( w_ul - w_con ) ;
				 ul.stop().animate({ 'margin-left' : pos + 'px'});
				
			});
			
		});
	}
})(jQuery);

$(document).ready(function(){						 					
    $('#cfx-load-c').center();
	$('#cfx-load-b').click(function(){ loading_close(true); });
    $(window).bind('resize', function() {
        $('#cfx-load-c').center({transition:300});
		$('body').height(function(){
			return $('html').height() - ($('.bodyhead').height() + 25) ;
			
		});
		
    });
	 
});

