$.fn.pause = function(milli,type) {
	milli = milli || 1000;
	type = type || "fx";
	return this.queue(type,function(){
		var self = this;
		setTimeout(function(){
			$.dequeue(self);
		},milli);
	});
};

$.fn.clearQueue = $.fn.unpause = function(type) {
	return this.each(function(){
		type = type || "fx";
		if(this.queue && this.queue[type]) {
			this.queue[type].length = 0;
		}
	});
};
	
$(document).ready(function(){

	// TRABAJO
	theRotator();

	// portfolio
	var trabajos = $(".toolscroll").scrollable({easing: 'swing', speed: 1000
	//,
	//onSeek: function(){alert("hola")}
	}).navigator("#navegador")
	//.autoscroll({interval: 5000});

	$("span.it").toggle(
		function () {
			$(this).html("Descripci&oacute;n");
			var id = $(this).attr('rel');  
			txt = "#" + id + " .desc";
			it = "#" + id + " .desc-it";
			$(txt).fadeOut("slow", function(){
				$(it).fadeIn("slow")
			})
		},
		function () {
			$(this).html("Datos t&eacute;cnicos");
			var id = $(this).attr('rel');  
			txt = "#" + id + " .desc";
			it = "#" + id + " .desc-it";
			$(it).fadeOut("slow", function(){
				$(txt).fadeIn("slow")
			})
		
		
		}
	);

	// ARTE DIGITAL
	// portfolio
//	var portfolio = $("#main").scrollable({vertical: true, items: '.adpage'}).navigator("#main_navi");

//	var horizontal = $(".scrollable").scrollable({ items: '.items2' }).navigator(".navii");
	

	//BLOG
	

	
//	$(".comentar").slideToggle('fast')
	

    var $sidebar   = $("#banners"),
        $window    = $(window),
        offset     = $sidebar.offset(),
        topPadding = -100;

    $window.scroll(function() {
        if ($window.scrollTop() > offset.top) {
            $sidebar.stop().animate({
                marginTop: $window.scrollTop() - offset.top + topPadding
            });
        } else {
            $sidebar.stop().animate({
                marginTop: 0
            });
        }
    });

	posts = 10


});

jQuery.fn.anchorAnimate = function(settings) {
 	settings = jQuery.extend({
		speed : 800
	}, settings);	
	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = "body"
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
//				window.location.hash = elementClick
			});
//		  	return false;
		})
	})
}

function theRotator() {
	//Set the opacity of all images to 0
	$('div#quehago ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#quehago ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
	
}

function rotate() {	
	//Get the first image
	var current = ($('div#quehago ul li.show')?  $('div#quehago ul li.show') : $('div#quehago ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#quehago ul li:first') :current.next()) : $('div#quehago ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};
