

function sendAjax(pn) {
var ajax = new Request({
        url: '/multipicturegallery?nocache=' + $time() + $random(0, 100),
        method: 'get',
        onFailure: function(xhr) { },
        onComplete: function(responseText) {
                $('multipictureProfileWrapper').set('html',responseText);
                //window.fireEvent('c_php_domready');
                loadMultiPicture();
        }
});
    if(!$defined(pn)) pn = 1;
    ajax.send({data: 'pageNumber=' + pn});
}

function sendAjaxAndIncreaseCounter()
{
    if (!$defined(window.pn)) {
        window.pn = 2;
    } else {
        window.pn++;
    }
    sendAjax(window.pn);
}

function loadMultiPicture(){
        var mosaicImages = $$('.multiPictureTooltip');
        mosaicImages.each(function(image) {
            var myTips = new Tips({
                className: 'tip-container',
                text: 'rel',
                showDelay: 0,
                onShow: function(tooltip) {
                    if (image.getProperty('class').contains('health', ' ')) {
                        tooltip.setStyle('color', '#678901');
                    } else if (image.getProperty('class').contains('sustainability', ' ')) {
                        tooltip.setStyle('color', '#008cc8');
                    } else {
                        tooltip.setStyle('color', '#230091');
                    }
                    var hoehe = tooltip.getStyle('height');
                    hoehe = parseInt(hoehe.replace(/px/, ''));
                    hoehe = 20 + hoehe;
                    hoehe = -1*hoehe;
                    this.options.offsets = {'x':-40, 'y': hoehe };
                    tooltip.fade('show');
                    },
                onHide: function(tooltip) {
                    tooltip.fade('hide')
                }
                });

            myTips.attach(image);

            });

    $$('.pagerLinks').each(function(link) {
        link.addEvent('click', function(e){
            e.stop();
            pn = $get('pageNumber', link);
            sendAjax(pn);
        });
    });

    if(!$defined(window.pn)) {
        sendAjaxAndIncreaseCounter.periodical(30 * 1000);
    }
}

function $get(key,url){
    if(arguments.length < 2) url =location.href;
    if(arguments.length > 0 && key != ""){
        if(key == "#"){
            var regex = new RegExp("[#]([^$]*)");
        } else if(key == "?"){
            var regex = new RegExp("[?]([^#$]*)");
        } else {
            var regex = new RegExp("[?&]"+key+"=([^&#]*)");
        }
        var results = regex.exec(url);
        return (results == null )? "" : results[1];
    } else {
        url = url.split("?");
        var results = {};
            if(url.length > 1){
                url = url[1].split("#");
                if(url.length > 1) results["hash"] = url[1];
                url[0].split("&").each(function(item,index){
                    item = item.split("=");
                    results[item[0]] = item[1];
                });
            }
        return results;
    }
}


