$(document).ready(function () {
    //Desplegable
    $('.acc_container').hide(); //Hide/close all containers
    $('body.home .acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
    //On Click
    //$('.acc_trigger').click(function(){
    // Hover
    $('.acc_trigger').hover(function () {
        if ($(this).next().is(':hidden')) { //If immediate next container is closed...
            $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
            $(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
        }
        return false; //Prevent the browser jump to the link anchor
    });
    // efecto desplazamiento accordion vertical	
    $("h3.acc_trigger a").hover(function () {
        $(this).stop().animate({
            marginLeft: "10"
        }, 200);
    }, function () {
        $(this).stop().animate({
            marginLeft: "0"
        }, 200);
    });
    // efecto fade p/img logo
    $(function () {
        $(".logo a img").css("opacity", "1.0");
        $(".logo a img").hover(function () {
            $(this).stop().animate({
                opacity: 0.7
            }, "slow");
        }, function () {
            $(this).stop().animate({
                opacity: 1.0
            }, "slow");
        });
    });
    // efecto fade p/img logo
    $(function () {
        $(".category .logo a img").css("opacity", "0.5");
        $(".category .logo a img").hover(function () {
            $(this).stop().animate({
                opacity: 1.0
            }, "slow");
        }, function () {
            $(this).stop().animate({
                opacity: 0.5
            }, "slow");
        });
    });
    // efecto fade p/img logos social
    $(function () {
        $("#menu ul li a img").css("opacity", "0.5");
        $("#menu ul li a img").hover(function () {
            $(this).stop().animate({
                opacity: 1.0
            }, "slow");
        }, function () {
            $(this).stop().animate({
                opacity: 0.5
            }, "slow");
        });
    });
    // colorbox
    $('.imgpost a').colorbox();

    // simple gallery
    $(function () {
        $(".image").click(function () {
            var image = $(this).attr("rel");
            var title = $(this).attr("title");
            var description = $(this).attr("content");
            $('#gallery').hide();
            $('#gallery').fadeIn('slow');
            $('#image').html('<img src="' + image + '"/>');
            $('#title').html(title);
            $('#description').html(description);
            return false;
        });
    });
    //* gallery: http://tutorialzine.com/2009/11/beautiful-apple-gallery-slideshow/ *//
    $(document).ready(function () {
        /* This code is executed after the DOM has been completely loaded */
        var totWidth = 0;
        var positions = new Array();
        $('#slides .slide').each(function (i) { /* Traverse through all the slides and store their accumulative widths in totWidth */
            positions[i] = totWidth;
            totWidth += $(this).width(); /* The positions array contains each slide's commulutative offset from the left part of the container */
            if (!$(this).width()) {
                alert("Please, fill in width & height for all your images!");
                return false;
            }
        });
        $('#slides').width(totWidth); /* Change the cotnainer div's width to the exact width of all the slides combined */
        $('#menu ul li a').click(function (e, keepScroll) { /* On a thumbnail click */
            $('li.menuItem').removeClass('act').addClass('inact');
            $(this).parent().addClass('act');
            var pos = $(this).parent().prevAll('.menuItem').length;
            $('#slides').stop().animate({
                marginLeft: -positions[pos] + 'px'
            }, 450); /* Start the sliding animation */
            e.preventDefault(); /* Prevent the default action of the link */
            // Stopping the auto-advance if an icon has been clicked:
            if (!keepScroll) clearInterval(itvl);
        });
        $('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact'); /* On page load, mark the first thumbnail as active */
        /******	Enabling auto-advance. ****/
        var current = 1;
        function autoAdvance() {
            if (current == -1) return false;

            $('#menu ul li a').eq(current % $('#menu ul li a').length).trigger('click', [true]); // [true] will be passed as the keepScroll parameter of the click function on line 28
            var title = $(this).attr("title");
            $('#title').html(title);
            current++;
        }
        // The number of seconds that the slider will auto-advance in:
        var changeEvery = 5;
        var itvl = setInterval(function () {
            autoAdvance()
        }, changeEvery * 1000); /* End of customizations */
    });
});
/****************************************/
$('.btn-quick').live('click', function () {
    if (!$(this).hasClass('btn-quick-close')) {

        $('.btn-quick').addClass('btn-quick-close');
        $('#panel-int .holder').show().animate({
            height: 200
        }, function () {

        });
        $('.caption').fadeOut().addClass('disabled');
    } else {
        $('#panel-int .holder').animate({
            height: 0
        }, function () {
            $(this).hide();
            $('.btn-quick').removeClass('btn-quick-close');
        });
    }

    return false;
});
	// accordion  *******************************/
$(document).ready(function(){
	$(".contiene-form").hide();
	$(".trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
	});
	// my carousel  *******************************/
	jQuery('#mycarousel').jcarousel({
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
    // accordion para especiales *******************************/
	$(".oculto").hide();
	$(".activa").toggle(function(){
		$(this).addClass("esactivo"); 
		}, function () {
		$(this).removeClass("esactivo");
		});
	$(".activa").click(function(){
		$(this).next(".oculto").slideToggle(500);
		});
	$(".activa").hover(function(){
		$(this).css('cursor','pointer');
		});
	// custom select
	$('.select').customStyle();
});
//
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
