
/**
 * Needed for the BackLink on static Article-Pages (zurück zur Auswahl)
 * Leads back to static category-page
 */
var inwerkTools = {};

inwerkTools.toCategoryStatic = function (
    category_static_url, shopkuerzel, articles_per_page
    ) {
    if (!articles_per_page) {
        articles_per_page = 20;
    }

    document.location.href = '../inwerk_' + shopkuerzel.toLowerCase() + '/' +
    category_static_url.replace('--nummer--', Math.ceil(
        parseInt($('art_pos').innerHTML, 10) / articles_per_page)) +
    '#jump_' + $('Artikelnummer').innerHTML;
};

inwerkTools.toArticle = function (
    article_id, category_id, statisch, shopkuerzel, tmp_param
    ) {
    if (statisch == '') {
        document.location.href = '../shop_set/set.php' +
        '?id_artikel='   + article_id +
        '&id_kategorie=' + category_id +
        tmp_param;
    }
    else {
        if (statisch == '2') {
            document.location.href =
            './inwerk_' + shopkuerzel.toLowerCase() +
            '/' + category_id +
            '-' + shopkuerzel.toLowerCase() +
            article_id + '.htm';
            return;
        }

        document.location.href =
        './' + category_id +
        '-' + shopkuerzel.toLowerCase() +
        article_id + '.htm';
    }
};

/**
 * @param id_article (integer)
 */
inwerkTools.setArticleStatistics = function(id_article) {
    new Ajax.Request(
        '../php/ajax_requests/setArticleStatistics.php', {
            'parameters': {
                'id_artikel': id_article
            }
        }
        );
};

Event.observe(window, 'load', function() {
    new Ajax.Updater(
        'searchStatisticsWrapper',
        '../php/ajax_requests/getSearchStatistics.php'
        );

    new Ajax.Updater(
        'articleStatisticsWrapper',
        '../php/ajax_requests/getArticleStatistics.php'
        );
});


inwerkTools.extendSearchStatistic = function () {
    new Ajax.Updater(
        'searchStatisticsWrapper',
        '../php/ajax_requests/getSearchStatistics.php',
        {
            'parameters': {
                'switch_mode': 'extend'
            }
        }
    );
};

inwerkTools.collapseSearchStatistic = function () {
    new Ajax.Updater(
        'searchStatisticsWrapper',
        '../php/ajax_requests/getSearchStatistics.php',
        {
            'parameters': {
                'switch_mode': 'collapse'
            }
        }
    );
};

inwerkTools.extendArticleStatistic = function () {
    new Ajax.Updater(
        'articleStatisticsWrapper',
        '../php/ajax_requests/getArticleStatistics.php',
        {
            'parameters': {
                'switch_mode': 'extend'
            }
        }
    );
};

inwerkTools.collapseArticleStatistic = function () {
    new Ajax.Updater(
        'articleStatisticsWrapper',
        '../php/ajax_requests/getArticleStatistics.php',
        {
            'parameters': {
                'switch_mode': 'collapse'
            }
        }
    );
};


inwerkTools.expiredSessionAlreadyShown = false;
inwerkTools.showSessionExpireInfo = function () {
    if ( !inwerkTools.expiredSessionAlreadyShown ) {
        var info_left = 250,
        info_top  = 50,
        info_shadow = 10,
        ww = window.getInnerWidth() / 2 - info_left,
        wh = window.getInnerHeight() / 2 - info_top;
        $("sessionExpiredShadow").style.left = ( ww + info_shadow ) + "px";
        $("sessionExpiredShadow").style.top = ( wh + info_shadow ) + "px";
        $("sessionExpired").style.left = ( ww ) + "px";
        $("sessionExpired").style.top = ( wh ) + "px";

        $("sessionExpiredShadow").style.display = "block";
        $("sessionExpired").style.display = "block";
    }
    inwerkTools.expiredSessionAlreadyShown = true;
};


window.showPleaseWait = function (which) {
    if (which != undefined && which.tagName == 'A' && (
        which.getAttribute('href').match(/^javascript/)
        || (which.getAttribute('target') != null
            && which.getAttribute('target').match(/^(\_blank|\_new)$/)
            )
        )
    ) {
        return false;
    }

    var pos_y    = window.pageYOffset,
    height_y = window.innerHeight,
    width_y  = window.innerWidth,
    ie_bool  = false;

    if (pos_y == undefined) {
        pos_y    = document.documentElement.scrollTop;
        height_y = document.documentElement.clientHeight;
        width_y  = document.documentElement.clientWidth;
        ie_bool = true;
    }
    if (pos_y == undefined) {
        pos_y    = document.body.scrollTop;
        height_y = document.body.clientHeight;
        width_y  = document.body.clientWidth;
        ie_bool = true;
    }

    var tmp_top  = (pos_y + Math.round(height_y / 2) - 45) + 'px',
    tmp_left = (Math.round(width_y / 2) - 45) + 'px';

    var tmp_obj;
    if (ie_bool) {
        tmp_obj = document.all.bitteWarten.style;
        tmp_obj.setAttribute( 'top', tmp_top, false );
        tmp_obj.setAttribute( 'left', tmp_left, false );
        tmp_obj.setAttribute( 'visibility', 'visible', false );
    } else {
        tmp_obj = document.getElementById('bitteWarten').style;
        tmp_obj.top  = tmp_top;
        tmp_obj.left = tmp_left;
        tmp_obj.visibility = 'visible';
    }

    return true;
};


window.target_url = '';
function toOtherMarketPopup(str_url) {
    if (
        !document.getElementById('warenkorbInhaltsAnzeige')
        || document.getElementById('warenkorbInhaltsAnzeige').innerHTML == '0'
        ) {
        document.location.href = str_url;
    }
    else {
        $('toOtherMarket').style.display = 'block';
        window.target_url = str_url;
    }
}

function showFlashVideoInContainer(path2flv, path2poster, id_of_container) {
    var flashvars = {
        'videopath': path2flv,
        'posterpath': path2poster,
        'skinpath': '../swf/inwerkskin.swf'
    };
    swfobject.embedSWF(
        '../swf/videoplayer.swf', id_of_container, '320', '276', '8.0.0',
        false, flashvars
    );
}
