$(document).ready(function(){
	
	// -------------------------------
	// ----- TOGGLE ITEM CONTENT -----
	// -------------------------------

	$('.itemReadMore').click(function() { 
            $(this).children().toggle();
	    var contentItem = $(this).parents('.contentItem');
            toggleBody(contentItem);
        });

        function toggleBody(contentItem){
            contentItem.find('.itemLong').slideToggle();
        }

        // ---------------------------------
	// ----- TOGGLE ITEM LONG BODY -----
	// ---------------------------------

	$('.itemReactBtn').click(function() {
            $(this).children().toggle();
            var contentItem = $(this).parents('.contentItem');
            toggleComments(contentItem);
        });

        function toggleComments(contentItem) {
            contentItem.find('.itemComments').slideToggle();
        }


        //------------------------------
        // --- Follow links
        // -----------------------------

        $('.clickableItem').find('.itemLink').find('a').each(function ()
        {
            var link = $(this).attr('href');
            $(this).parents('.clickableItem').click(function ()
            {
                document.location = link;
            });
        });

        $('.clickableItem').find('a.follow').each(function ()
        {
            var link = $(this).attr('href');
            $(this).parents('.clickableItem').click(function ()
            {;
                document.location = link;
            });
        });

        $('.clickableItem').click(function() {
            console.log('click')
            document.location = $(this).find('a.follow').attr('href');
        });

	// -----------------------------
	// ----- IMAGE CYCLE BOXES -----
	// -----------------------------
	
	// requires: jquery.cycle.all.js
	/*
	$('#advertisementPortlet').cycle({
            fx:    'fade',
            random:	1,
            speed:  2500
	});*/
	
	// --------------------------
	// ----- NEWS HEADLINES -----
	// --------------------------
        
        // put headlines in random order (shuffle):
        // requires: jquery.shuffle.js
//        $('#newsHeadlines').children().shuffle();

	// requires: jquery.cycle.all.js
/*	$('#newsHeadlines').cycle({ 
		fx:     'scrollUp', 
		random:  1
	});
*/
        /* ---------------------- */
	/* ----- PAGE INDEX ----- */
	/* ---------------------- */
        if($('#pageToc').size() != 0){
            $('#pageToc').generateToc({index:'#pageToc', content:'#projectContent', start:2});
        }

	// ---------------------------
	// ----- SORTABLE TABLES -----
	// ---------------------------

        // requires: jquery.datatables.min.js
  //      $('.dataTable').dataTable({"bPaginate": false});
        
        /*
        if($('#membersTable').size() != 0){
            $('#membersTable').dataTable({"bPaginate": false});
        }
        */
/*
        $('img').tooltip({
        bodyHandler: function() {
         return $(this).attr("alt");
        },
        showURL: false
        });*/
});
