$j = jQuery.noConflict();
$j(document).ready(function () {
    $j('.menu li').hover(function () {
        			$j(this).find('ul:first').css({'visibility': 'visible', 'display': 'none'}).slideDown('fast');
    }, function () {
        $j(this).find('ul:first').css({visibility: "hidden"});
    });

    
    $j('p').each(function () {
        var elem = $j(this);
        if (elem.html().length == 0) {
            $j(this).remove();
        }
    });
    
    $j('li.comment').each(function () {
		var reply = $j(this).find('.reply:first');
		$j(this).remove('.reply:first');
		$j(this).find('.vcard:first').prepend(reply);
	});	
    
    $j('#commentform p').each(function () {
        var inputBox = $j(this).find('input');
		$j(this).remove('input');        
        $j(this).prepend(inputBox)
    });
 
    cancelReply = $j('#cancel-comment-reply-link');
	$j('#cancel-comment-reply-link').remove();
	$j('#respond').prepend(cancelReply);

    $j('li.comment div.first').hover(function () {
        $j(this).find('.reply:first').show();
    }, function () {
        $j(this).find('.reply:first').hide();
    });
    
    $j('#kwicks-container').kwicks({
            max: 800,
            spacing: 0,
			duration: 1000
    });
    $j('#kwicks-container li').hover(function () {
            $j('#kwicks-container li').not($j(this)).find('img').stop().fadeTo('slow', .3)
            $j('#kwicks-container li').not($j(this)).find('.kwicks-caption').stop().hide();
        },
        function (){
            $j('#kwicks-container li').not($j(this)).find('img').stop().fadeTo('slow', 1);
            $j('#kwicks-container li').not($j(this)).find('.kwicks-caption').stop().show();
    });

	// Apply fancybox on all images
	$j("a[href$='gif']").fancybox();
	$j("a[href$='jpg']").fancybox();
	$j("a[href$='png']").fancybox();		
		
	// Font replacement
	Cufon.replace('#logo .title');	
	Cufon.replace('h1');

	$j("#footer .links li:last .sep").css({'display': 'none'});

	// Slider
	$j('#slider .descriptions .description:first').show(); 
	$j('#slider .slides').nivoSlider({
		effect:						'random',
		slices:						15,
		animSpeed:					500,
		pauseTime: 					3000,
		startSlide:					0, //Set starting Slide (0 index)
		directionNav:				true, //Next & Prev
		directionNavHide:			false, //Only show on hover
		controlNav:					true, //1,2,3...
		controlNavThumbs:			false, //Use thumbnails for Control Nav
		controlNavThumbsSearch: 	'.jpg', //Replace this with...
		controlNavThumbsReplace: 	'_thumb.jpg', //...this in thumb Image src
		keyboardNav:				true, //Use left & right arrows
		pauseOnHover:				false, //Stop animation while hovering
		manualAdvance:				false, //Force manual transitions
		captionOpacity:				1.0, //Universal caption opacity
		beforeChange: 				function(){},
		afterChange: 				function(){
			currentSlide = $j('#slider .slides').data('nivo:vars').currentSlide
			$j('#slider .descriptions table').each(function (index, value) {
				if (index == currentSlide) {
					$j('#slider .descriptions table').hide();
					$j(this).show();
				}
			});
		},
		slideshowEnd: 				function(){} //Triggers after all slides have been shown
	});
	$j('#slider .slides .nivo-controlNav a:first').addClass('active');
});

