$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();		
		

	$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: 					9000,
		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 .description').each(function (index, value) {
				if (index == currentSlide) {
					$j('#slider .descriptions .description').hide();
					$j(this).show();
				}
			});
		},
		slideshowEnd: 				function(){} //Triggers after all slides have been shown
	});
	$j('#slider .slides .nivo-controlNav a:first').addClass('active');

//OTHER CALLS
	$j('.tabs,.sidebar-tabs').tabs()
	$j('.accordion').accordion({autoHeight: false, active:-1, collapsible: true });
	$j("#content .accordion .ui-accordion-content p:last-child").addClass("no-padding-bottom");	
	$j("#content .tabs .ui-tabs-panel p:last-child").addClass("no-padding-bottom");	
	$j("#table-of-content ul li:even").addClass("alternative");
	
//ADD TOOLTIPS TO FRONT PAGE NEWS BOTTOM POSTS AND TO CONTENT
	$j('#bottom-posts a[title]').tooltip({ 'effect':'slide', 'offset':[-6, 70],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});
	$j('#sharing a[title]').tooltip({ 'effect':'slide', 'offset':[-20,100],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});	
	$j('#related a[title]').tooltip({ 'effect':'slide', 'offset':[-2,70],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});	
	$j('#content a.gototooltip[title]').tooltip({ 'effect':'slide', 'offset':[-6, 70],'layout': '<div><div class="content"></div><span class="arrow"></div>'});	
	$j('#content a.tooltip-title[title]').tooltip({ 'effect':'slide', 'offset':[90, 70],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});		
	$j('#tour a.tour-page-title[title]').tooltip({ 'effect':'slide', 'offset':[-6, 110],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});		
	$j('#front-page-presentation-row-5 a.move-to-tooltip[title]').tooltip({ 'effect':'slide', 'offset':[-6, 110],'layout': '<div><div class="content"></div><span class="arrow"></span></div>'});		
});

