jQuery(document).ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/

	function() {
	}
);

Liferay.Portlet.ready(

	/*
	This function gets loaded after each and every portlet on the page.

	portletId: the current portlet's id
	jQueryObj: the jQuery wrapped object of the current portlet
	*/

	function(portletId, jQueryObj) {

        // MODIFY search form action
        if( portletId === '3' ) {

            var modifySearch = function() {
                var $searchForm = jQuery(jQueryObj).find('form');
                var action = jQuery($searchForm).attr('action');

                var startIndex = action.lastIndexOf('/') + 1;
                var endIndex = action.indexOf('?', startIndex);
                action = [
                    action.substring(0, startIndex),
                    'search',
                    action.substring(endIndex)
                ].join('');

                jQuery($searchForm).attr('action', action);
            };

            if( jQuery.browser.msie ) {
                jQuery(document).ready(function() {
                    modifySearch();
                });
            }
            else {
                modifySearch();
            }
            
        }
	}
);

jQuery(document).last(

	/*
	This function gets loaded when everything, including the portlets, is on
	the page.
	*/

	function() {
//        // SETS blogger menu hover effect that cannot be done just by css
//        jQuery("#blogger .blogger-menu")
//            .mouseout( function() {
//                jQuery(this).removeAttr("hover");
//            })
//            .find("a")
//            .mouseover( function() {
//                var link = jQuery(this).attr("link");
//                jQuery(this).parent(".blogger-menu")
//                    .attr("hover", link);
//            })
//            .click( function() {
//                var link = jQuery(this).attr("link");
//                var category = jQuery(this).attr("category");
//                jQuery(this).parent(".blogger-menu")
//                    .attr("sel", link);
//            });

        // SETS date view --> this could be active but why bother
//        var date = new Date();
//        jQuery("#blogger #date")
//            .find(".day").text(date.getDate())
//            .end()
//            .find(".month").text(date.toLocaleFormat("%b"));
	}
);
    
if( window.g2 === undefined ) {
    g2 = {};
}

if( window.g2.SlideShow === undefined ) {

    g2.SlideShow = function(slideShow) {
        this.$slideShow = jQuery(slideShow);
    }

    g2.SlideShow.prototype.switchSlide = function() {

        var $active = jQuery(this.$slideShow).find('.slide.active');

        if ( $active.length == 0 )
            $active = jQuery(this.$slideShow).find('.slide:last');

        var $next =  $active.next('.slide').length ? $active.next()
            : jQuery(this.$slideShow).find('.slide:first');

        $active.addClass('last-active');

        $next.css({opacity: 0.0})
            .addClass('active')
            .animate({opacity: 1.0}, 1000, function() {
                $active.removeClass('active last-active');
            });
    }
}

