$(document).ready(function() {
    $('.ajaxLink').click(function() {
        return false;
    });

    $('.ajaxLink').hover(function(e) {
            //start function when any link is clicked
        var activeItem = $(this).attr("title");
        var buttonID = $(this).attr("id").split(activeItem);
        switch (buttonID[0]) {
            case "image":
            case "imageDetailsButton":
                ajaxAction = "showImageDetails";
            break;
            default:
                return;
        }

        var tooltipoffsets = [20, 30]; //additional x and y offset from mouse cursor for tooltips

        var x = (e.pageX+tooltipoffsets[0]);
        var y = (e.pageY+tooltipoffsets[1]);
		var tipw = $(".press_search_resultDetails").outerWidth();
        var tiph = $(".press_search_resultDetails").outerHeight();

        $.ajax({
            type: "POST",
            url: "index.php",
            data: "eID=press_search&pageID="+pageID+"&action="+ajaxAction+"&activeItem="+activeItem,
            success: function(html){
                $(".press_search_resultDetails").html(html);

                tipw = $(".press_search_resultDetails").outerWidth();
                tiph = $(".press_search_resultDetails").outerHeight();
        		x = (x+tipw>$(document).scrollLeft()+$(window).width())? x-tipw-(tooltipoffsets[0]*3) : x;
        		y = (y+tiph>$(document).scrollTop()+$(window).height())? $(document).scrollTop()+$(window).height()-tiph-tooltipoffsets[1] : y;

                $('.press_search_resultDetails').css({
                    width: '320px',
                    left: x + 'px',
                    top: y + 'px'
                });

                $(".press_search_resultDetails").show();

                $(".active").removeClass("active");
                $("#image"+activeItem).addClass("active");
                // set image from fileadmin/templates_pressportal/img/btn_info_active.gif back to fileadmin/templates_pressportal/img/btn_info_inactive.gif
                $("a[id^='detailsButton'] > img").attr("src", "fileadmin/templates_pressportal/img/btn_info_inactive.gif");
                $("#detailsButton"+activeItem+" > img").attr("src", "fileadmin/templates_pressportal/img/btn_info_active.gif");
            }
        }); //close $.ajax(
        return false;
    },
    function(e) {
        $('.press_search_resultDetails').hide();
    }); //close hover

    if ( $('.slideshow').length ) {
        $('.slideshow').cycle({
    		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            speed: 300,
            timeout: 1000,
            delay: -1000
    	});
        $('.slideshow').cycle('pause');

        $('.slideshow').mouseenter(function(){
            $(this).cycle('resume');
        });
        $('.slideshow').mouseleave(function(){
            $(this).cycle('pause');
        });
    }

});