$(function(){

     // SLIDESHOW
	
	$("#slideshow .control ul li:first-child").width(
			($("#slideshow .control").width() - 24) - ((($("#slideshow .control ul").children().size() - 1)*15) - 6)
	);
	
	if($('div.gallery ul li').size() == 1) {
		$("#slideshow .gallery").jCarouselLite({
	        visible: 1,
	        beforeStart: function (a) {
	        	$('#slideshow .control ul li:first-child').fadeOut('fast');
	        	$('#slideshow .control ul li a').removeClass('active');
	        },
	        afterEnd: function(a) {
	        	$('#slideshow .control ul li:first-child').html('<p><span>'+$(a[0]).children('img').attr("title")+'</span> '+$(a[0]).find('img').attr("alt")+'</p>').fadeIn(500);
	        	$('#slideshow .control ul li a.' + $(a[0]).attr('class')).addClass('active');
	        },
	        btnGo:
	            ['.control .1', '.control .2', '.control .3', '.control .4', '.control .5', '.control .6',
	            '.control .7', '.control .8', '.control .9', '.control .10', '.control .11', '.control .12']
	    });
	}
	else {
		$("#slideshow .gallery").jCarouselLite({
	        visible: 1,
	        auto: 10000,
	        speed: 2000,
	        beforeStart: function (a) {
	        	$('#slideshow .control ul li:first-child').fadeOut('fast');
	        	$('#slideshow .control ul li a').removeClass('active');
	        },
	        afterEnd: function(a) {
	        	$('#slideshow .control ul li:first-child').html('<p><span>'+$(a[0]).children('img').attr("title")+'</span> '+$(a[0]).find('img').attr("alt")+'</p>').fadeIn(500);
	        	$('#slideshow .control ul li a.' + $(a[0]).attr('class')).addClass('active');
	        },
	        btnGo:
	            ['.control .1', '.control .2', '.control .3', '.control .4', '.control .5', '.control .6',
	            '.control .7', '.control .8', '.control .9', '.control .10', '.control .11', '.control .12']
	    });
	}
	
        $(".ngg-galleryoverview").jCarouselLite({
	        circular: false,
        	visible: 6,
	        btnNext: ".navigation .next",
        	btnPrev: ".navigation .previous"
	    });

	$(".control .1").click();
	
	// MAIN MENU DROPDOWN
	
	$('nav ul li').hover(
		function () {
			var total = $('nav > ul > li').size(), right = 0;
			if($('nav > ul').size() == 1){
				for (var i = parseInt($(this).index(), 10)+1; i < total; i++) {
					right += $('nav > ul > li').eq(i).width();
				}			
				$(this).find('ul').css('right', right + 'px').fadeIn(200);
			}
			else {
				if(document.getElementById('menu-private_en')){
					for (var i = parseInt($(this).index(), 10)+1+$('#menu-private_en > li').size(); i < total; i++) {
						right += $('nav > ul > li').eq(i).width();
					}
				}
				else {
					for (var i = parseInt($(this).index(), 10)+1+$('#menu-private > li').size(); i < total; i++) {
						right += $('nav > ul > li').eq(i).width();
					}
				}
				$(this).find('ul').css('right', right + 'px').fadeIn(200);
			}
		  }, 
		  function () {
			  $(this).find('ul').fadeOut(200);
		  }
	);
	
	$('nav ul#menu-private li').hover(
		function () {
			var total = $('nav > ul#menu-private > li').size(), right = 0;
			for (var i = parseInt($(this).index(), 10)+1; i < total; i++) {
				right += $('nav > ul > li').eq(i).width();
			}
			$(this).find('ul').css('right', right + 'px').fadeIn(200);
			 $(this).find('ul').fadeIn(200);
		  }, 
		  function () {
			  $(this).find('ul').fadeOut(200);
		  }
	);
	
	// SUB-NAV BOX
	
	$('.sub-nav ul.user li a').click(function() {
		var the_width = $(this).width(), 
			child_width = $(this).parent().find(".form-box").width(), 
			width = parseInt((child_width - the_width)/2);
		
		$(this).parent().siblings().find('.form-box').hide();		
	    $(this).parent().find('.form-box').css('left', (width*-1) + 'px').toggleFade('slow');
	});

	// TWITTER
	
	$(".tweet").tweet({
		join_text : "auto",
		username : "mdiversos",
		avatar_size : 32,
		count : 4,
		auto_join_text_default : "",
		auto_join_text_ed : "",
		auto_join_text_ing : "",
		auto_join_text_reply : "",
		auto_join_text_url : "",
		loading_text : "..."
	});
	
	// NEWS SLIDER
	
	$(".slider").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        vertical: true,
        visible: 3
    });
	
	
});

