function mycarousel_initCallback(carousel) {

    $('#mycarousel li img').bind('click', function() {
        carousel.stopAuto();
        carousel.scroll($.jcarousel.intval($(this).parent().attr('jcarouselindex')) - 1);
        carousel.startAuto(10);
        return false;
    });

};

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
    var firstItem = carousel.first;
    var middleItem = carousel.first + 1;
    var lastItem = carousel.first + 2;

    $("#mycarousel li img")
				    .not("#mycarousel li[jcarouselindex='" + firstItem + "'] img")
				    .not("#mycarousel li[jcarouselindex='" + lastItem + "'] img")
				    .each(function() {
				        $(this).css('opacity', '0.80');
				    });

    //selected item
    $("#mycarousel li[jcarouselindex='" + middleItem + "'] img")
				    .animate({
				        marginTop: '-22px',
				        opacity: '1.00',
				        width: '135',
				        height: '102',
				        borderWidth: "5px"
				    }, 500)
				    .parent().addClass('selected');

    var selectedText = $("#mycarousel li[jcarouselindex='" + middleItem + "'] img").attr('class');

    if (state == "init") {
        $("#carouselBG li").hide();
        $("#carouselBG li." + selectedText).show();
    }
    else {

        var bg = $("#carouselBG li." + selectedText).css("background-color");

        $("#carouselWrap").css({ 'background-color': bg });

        $("#carouselBG li")
        .not("#carouselBG li." + selectedText)
        .fadeOut(1000);

        $("#carouselBG li." + selectedText)
        .fadeIn(1000);
    }

    //first item
    $("#mycarousel li[jcarouselindex='" + firstItem + "'] img")
				    .animate({
				        marginTop: '0px',
				        opacity: '0.80',
				        width: '117',
				        height: '88',
				        borderWidth: "2px"
				    }, 300)
				    .parent().removeClass('selected');

    $("#mycarousel li[jcarouselindex='" + lastItem + "'] img")
				    .animate({
				        marginTop: '-22px',
				        opacity: '0.80',
				        width: '117',
				        height: '88',
				        borderWidth: "2px"
				    }, 300)
				    .parent().removeClass('selected');
}

function selectChange(clickID) {
    if ($("ul.popup > li." + clickID).is(":visible")) {
        $(".select").removeClass("opacity").removeClass("selected");
        $("ul.popup > li." + clickID).fadeOut()
    }
    else {
        $(".select").addClass("opacity").removeClass("selected");
        $("ul.popup > li").fadeOut()
        $("#" + clickID).removeClass("opacity").addClass("selected");
        $("ul.popup > li." + clickID).fadeIn()
    }
}

function close_popup() {
    $("#overlay").fadeOut();

    $("ul.popup > li").fadeOut()
}

$(document).ready(function() {

    $('a').each(function() {
        var href = $(this).attr('href');
        if (href && (href.match(/youtube\.com\/watch/i) || href.match(/vimeo\.com/i) || href.indexOf('.flv') != -1 || href.indexOf('.mov') != -1)) {
            $(this).attr('rel', 'prettyPhoto');
        }
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'light_rounded' });
});