$(function(){
	// code
	$("li.sub a").click(function() {
		$(this).next("ul").toggle("fast");
	});
	//$(".menu2 > ul").hide().fadeIn(700);
	$("#homepage img").hover(function(){
		$(this).fadeTo("fast", 0.5);
	},function(){
		$(this).fadeTo("fast", 1);
	});
	$("#mycarousel li img").click(function() {
		var url = $(this).attr("src");
		$("div#highphoto").html("<img src='"+url+"' />");
	});
	
	$('#mycarousel').jcarousel({
        auto: 5,
        scroll: 10,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
		buttonNextHTML: null,
        buttonPrevHTML: null

    });
	
	$('#mycarousel2').jcarousel({
        auto: 5,
        scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
		buttonNextHTML: "<div class='next'>&rsaquo;</div>",
        buttonPrevHTML: "<div class='prev'>&lsaquo;</div>"

    });
	
	$('#mycarousel3').jcarousel({
        auto: 5,
        scroll: 1,
        wrap: 'last',
        initCallback: mycarousel_initCallback,
		buttonNextHTML: "<div class='next'>&rsaquo;</div>",
        buttonPrevHTML: "<div class='prev'>&lsaquo;</div>"

    });
	
	if ($('#mycarousel2').children().size() < 2) {
		$('#mycarousel2 div.jcarousel-next').hide();
	}
	
    setInterval( "slideSwitch()", 5000 );
	
	$("a.group").fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300,
		'overlayShow': false,
		'imageScale' : false,
		'centerOnScroll' : false
	});
});

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();
    });
	jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};


function slideSwitch() {
    var $active = $('#slideshow div.active');

    if ( $active.length == 0 ) $active = $('#slideshow div:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow div:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}


$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};


