/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    $('#execphp-6 .control a').bind('click', function() {
        //carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        var index = jQuery('#execphp-6 .control a').index(this) + 1;
        carousel.scroll(index);
        jQuery('#execphp-6 .control a').removeClass('active');
        jQuery('#execphp-6 .control a:eq('+eval(index-1)+')').addClass('active');
        return false;
    });

    $('#execphp-6 .next').bind('click', function() {
        carousel.next();
        return false;
    });

    $('#execphp-6 .prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};


function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    jQuery('#execphp-6 .control a').removeClass('active');
    jQuery('#execphp-6 .control a:eq('+eval(idx-1)+')').addClass('active');
};

$(document).ready(function() { 

	$('#nav a').hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	// Blogroll	expand-o contract-o
	// Thanks http://adipalaz.awardspace.com/experiments/jquery/accordion2.html	
	$('#execphp-5').find('ul.blogroll').hide();
	$('#execphp-5 .expand h5').click(function() {
	    $(this).parent().toggleClass('open').siblings().removeClass('open').end()
	    .find('ul').slideToggle(400).end()
	    .siblings('li').find('ul:visible').slideToggle(800);
	    return false;
	});

	$('#blogroll h5').hover(function(){
		$(this).addClass("hovering");
	}, function(){
		$(this).removeClass("hovering");
	});
	
	//---- Archive ----
	$('#execphp-4').find('li.collapsing ul').hide();
	$('#execphp-4 li.collapsing').children('a').click(function() {
	    $(this).parent().toggleClass('open').siblings().removeClass('open').end()
	    .find('ul').slideToggle(400).end()
	    .siblings('li').find('ul:visible').slideToggle(800);
	    return false;
	});
			
	//---- Slideshow ----
	$("#execphp-6 .control a:first").addClass("active");
	
    $("#slideshow").jcarousel({
        scroll: 1,
        initCallback: mycarousel_initCallback,
        itemVisibleInCallback: {
            onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
        },
        wrap: 'last'
    });
    
    
    //---- Post Slideshow ----
    $(".post #carousel").jcarousel({
    	scroll: 1,
        wrap: 'last'
    });
    
    $(".post #slidecontainer .slide:not(:first)").hide();
    
    // Hide prev/next if less than 3 slides
    if ($('.post #carousel li').size() <= 3) {
    	$('.post #slidecontainer .jcarousel-prev, .post #slidecontainer .jcarousel-next').hide();
    }
    
    // Add thumbnail overlay to first thumb
    $('.post #carousel li:first').append('<span class="overlay"></span>');
    
    // Load big photo on click
    $(".post #carousel a").click(function(){
    	var target = $(this).attr('href');
    	$(".post #slidecontainer .slide:visible").fadeOut("fast");
    	$(".post #slidecontainer "+target).fadeIn("fast");
    	
    	$('.post #carousel li .overlay').remove();
    	$(this).parent().append('<span class="overlay"></span>');
    
    	return false;
    });
    
    //---- Search ----
    var $searchinput = $("#searchform #s");
    
    $searchinput.focus(function(){
    	$(this).addClass("active");
    });
    $searchinput.blur(function(){
    	if ($(this).val()=="") {
	    	$(this).removeClass("active");
	    }
    });    

    if ($searchinput.val() != "") {
    	$searchinput.addClass("active");
    }
    
    // Fix transparent png's on ie6
	if ($.browser.msie && $.browser.version == 6) {
	    $('#nav').supersleight();
	}

    // Remove trailing hr in post lists
    $('#main-container hr:last').remove();
    
    //fix carousel width in Safari
    $('ul#carousel').attr("style","width:99999px");
}); 

