jQuery(document).ready(function() {
    if (jQuery('.ajaxLink').length) {
        jQuery('.ajaxLink').click(function() {
            return false;
        });

        jQuery('.ajaxLink').hover(function(e) {
                //start function when any link is clicked
            var activeItem = jQuery(this).attr("title");
            var buttonID = jQuery(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 = jQuery(".press_search_resultDetails").outerWidth();
            var tiph = jQuery(".press_search_resultDetails").outerHeight();

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

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

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

                    jQuery(".press_search_resultDetails").show();

                    jQuery(".active").removeClass("active");
                    jQuery("#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
                    jQuery("a[id^='detailsButton'] > img").attr("src", "fileadmin/templates_pressportal/img/btn_info_inactive.gif");
                    jQuery("#detailsButton"+activeItem+" > img").attr("src", "fileadmin/templates_pressportal/img/btn_info_active.gif");
                }
            }); //close jQuery.ajax(
            return false;
        },
        function(e) {
            jQuery('.press_search_resultDetails').hide();
        }); //close hover
    }

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

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

});
