/**/

(function(jQuery){
jQuery.fn.fadeSequence = function(fadeTime, duraTion) {
	duraTion = typeof(duraTion) == 'undefined' ? 0 : duraTion;
	fadeTime = typeof(fadeTime) == 'undefined' ? 500 : fadeTime;
    var toGo = jQuery(this).size() * (fadeTime+duraTion);
    var i=0; //Counter
    return jQuery(this).each(function() {
    	jQuery(this).delay(i++*(fadeTime+duraTion));
    	toGo -= (fadeTime+duraTion);
    	if(jQuery(this).css('display') == 'none') {jQuery(this).fadeIn(fadeTime);}
        else {jQuery(this).animate({'opacity' : 1}, fadeTime);}
        jQuery(this).delay(toGo+duraTion);
    });
};

})(jQuery);

$(document).ready(function() {
	
	$(".listopera").animate({opacity: '0.0'}, 0);
	$('.gridload').show();
	
	$(window).scroll(function(){
	var x = $('#wrap').height();
	var y = $(window).scrollTop();
	if( y > (x*.125) ){$('.backtotop').show();} else {$('.backtotop').hide();}
	});
	
	function scrollWin(){$('html, body').animate( {scrollTop: $("#wrap").offset().top}, 500);}
	$('.backtotop').click(function(){scrollWin(); }).stop();
	$('.title_left, .title_right').stop().animate({opacity: '0.0'}, 0);
	$('.nav_item').each(function() {$(this).stop().animate({ opacity: 0.0 }, 0).hover(function() {$(this).stop().animate({ opacity: 1.0 }, 200);},function() {$(this).stop().animate({ opacity: '0.0' }, 200);});});
	$('.nav_backward').hover(function(){$('.title_right').stop().animate({opacity: '1.0'}, 200);}, function(){$('.title_right').stop().animate({ opacity: '0.0' }, 200);});
	$('.nav_forward').hover(function(){$('.title_left').stop().animate({opacity: '1.0'}, 200);}, function(){$('.title_left').stop().animate({ opacity: '0.0' }, 200);});
	$('.next p, .prev p').animate({opacity: '0.0'}, 0);
	$('.next').hover(function(){$('.next p').animate({opacity: '1.0'}, 200);}, function(){$('.next p').animate({opacity: '0.0'}, 200);});
	$('.prev').hover(function(){$('.prev p').animate({opacity: '1.0'}, 200);}, function(){$('.prev p').animate({opacity: '0.0'}, 200);});	
	
	var tabContent = $(".babel").hide(),
	tabs = $("ul.tabs li");

	tabs.first().addClass("tabactive").show();
	tabContent.first().show();

	tabs.click(function() {
	var $this = $(this),
	activeTab = $this.find('a').attr('href');

	if(!$this.hasClass('tabactive')){
	$this.addClass('tabactive').siblings().removeClass('tabactive');
	tabContent.hide().filter(activeTab).show();
	}

	return false;
	});

});

$(window).load(function() {
	
	$('#intro').nivoSlider({ effect:'fade', controlNav:true, slices:1, animSpeed:600, pauseTime:5000, startSlide:0, directionNav:false, keyboardNav:true, pauseOnHover:true  }).find('a.nivo-prevNav').text(' ').end().find('a.nivo-nextNav').text(' ');
	$('#gridcontent').masonry({singleMOde: true, itemSelector: '.listopera'});
	$('.listopera').fadeSequence(300, 0);
	$('.gridload').hide();
});

