/*
mee
*/

$(document).ready(function(){

// menu	   
$('.topMenu ul li').hover(
	function() {
		$(this).not('.current').children('a').children('img').stop().fadeTo(300, 0)
	}, function() {
		$(this).not('.current').children('a').children('img').stop().fadeTo(300, 1)
	});
// menu em construção
$('.topMenu ul li').hover(
	function() {
		$(this).not('.current').children('img').stop().fadeTo(300, 0)
	}, function() {
		$(this).not('.current').children('img').stop().fadeTo(300, 1)
	});
	
// footer - social media   
$('.footer .social img').hover(
	function() {
		$(this).stop(true, true).animate({
			top : 3
		}, 100)
	}, function() {
		$(this).stop(true, true).animate({
			top : 6
		}, 100)
	});
	
// home
$('.homeFoto1, .homeFoto2').hover(
	function() {
		$(this).stop().fadeTo(100, .5)
	}, function() {
		$(this).stop().fadeTo(100, 1)
	});
	
// fotos e videos
$('.content#fotos img').hover(
	function() {
		$(this).stop().fadeTo(100, .5)
	}, function() {
		$(this).stop().fadeTo(100, 1)
	});
	
$('#photogal li:nth-child(4n)').addClass("last");

if(window.location.hash) {
  $('#photogal li').not('.taina').hide();
}


$('a.fancybox').fancybox({
	'overlayOpacity' : .8,
	'overlayColor' : '#000000',
	'titlePosition' : 'over',
	'transitionIn' : 'elastic',
	'transitionOut' : 'elastic',
	'speedIn' : 300,
	'speedOut' : 300
});

//image automatic rotator based on http://www.sohtanaka.com/web-design/automatic-image-slider-w-css-jquery/

//Hide banner images
$(".banner a").hide();

//Show the paging and activate its first link and show banner's first image
$('.paging').show();
$('.paging a:first').addClass('active');
$('.banner a:first').show('active');

//Paging and Transition Function
rotate = function(){
    var triggerID = $active.attr('rel'); //Get number of image
	var nextImg = $('.' + triggerID); //Determines the next banner

    $('.paging a').removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Transition
    //$('.banner a').fadeOut(); //Hide...
	$('.banner a:visible').fadeOut(500, function () {
		nextImg.fadeIn(500);
	});
	//nextImg.show(); //...and show

}; 

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer
        $active = $('.paging a.active').next(); //Move to the next paging
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 6000); //Timer speed in milliseconds
};

rotateSwitch(); //Run function on launch

//On Hover
$(".banner a").hover(function() {
    clearInterval(play); //Stop the rotation
}, function() {
	clearInterval(play); //Stop the rotation again
    rotateSwitch(); //Resume rotation timer
});	

//On Click
$(".paging a").click(function() {
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    //rotateSwitch(); // we don't need to resume rotation timer - it allready happens on hover function
    return false; //Prevent browser jump to link anchor
});

});
