// HOVER EFFECT    - Dem bild die Klasse 'onOver' vergeben (Hover-Bilder müssen mit '_hover' enden.)
// CLICK CHANGER   - Hauptbild ID muss 'pic' sein. Den Bildern die Klasse 'onClick' vergeben.
//                 - Für das aktive Bild die Klasse 'onCurrent' in CSS definieren.
//                 - Den Pfeilen die IDs 'arrowMinus' und 'arrowPlus' vergeben.

window.onload = init;

function init() {
    EFFECTS.init();
    setRoleAttr();
}
function myPreload(img_src) {
    var d = document;
    if (d.images) {
        if (!d.p) {
            d.p = new Array()
        }
        var key = d.p.length;
        d.p[key] = new Image;
        d.p[key].src = img_src
    }
}
function preloadImages() {
    var a = preloadImages.arguments;
    for (i = 0; i < a.length; i++) {
        if (a[i].indexOf("#") != 0) {
            myPreload(a[i])
        }
    }
}
function setRoleAttr() {
    if ($('#header')) {
        $('#header').attr('role', 'banner')
    }
    if ($('#navi')) {
        $('#navi').attr('role', 'navigation')
    }
    if ($('#col1')) {
        $('#col1').attr('role', 'complementary')
    }
    if ($('#col2')) {
        $('#col2').attr('role', 'complementary')
    }
    if ($('#col3')) {
        $('#col3').attr('role', 'main')
    }
    if ($('#footer')) {
        $('#footer').attr('role', 'contentinfo')
    }
}
var EFFECTS = {
    init: function () {
        EFFECTS.initOnOver();
        if ($('#pic')) {
            EFFECTS.initOnClick();
            EFFECTS.initArrows();
            EFFECTS.pic_src = $('#pic').attr('src')
        }
    }, initOnOver: function () {
        var data = $('img.onOver');
        for (var x = 0; x < data.length; x++) {
            var orig_src = data[x].src;
            var over_src = orig_src.replace(/.jpg/, "_hover.jpg");
            over_src = over_src.replace(/.gif/, "_hover.gif");
            over_src = over_src.replace(/.png/, "_hover.png");
            data[x].onmouseover = new Function("this.src ='" + over_src + "'");
            data[x].onmouseout = new Function("this.src ='" + orig_src + "'");
            myPreload(over_src)
        }
    }, pic_nr: 1,
    initOnClick: function () {
        var data = $('.onClick');
        for (var x = 0; x < data.length; x++) {
            var new_src = $('#pic').attr('src').replace(/01/, "0" + (x + 1));
            data[x].onclick = new Function("$('#pic').attr('src','"+ new_src+"');  EFFECTS.setCurrentImg(" + x + "); EFFECTS.pic_nr=" + (x + 1));
            myPreload(new_src)
        }
        if (data.length > 0) {
            EFFECTS.setCurrentImg(0)
        }
    }, setCurrentImg: function (x) {
        var data = $('.onClick');
        for (y = 0; y < data.length; y++) {
            data[y].parentNode.className = data[y].parentNode.className.replace("onCurrent", "")
        }
        data[x].parentNode.className += " onCurrent"
    }, initArrows: function () {
        if ($('#arrowMinus')) {
            $('#arrowMinus').onclick = new Function("EFFECTS.minusArrow();")
        }
        if ($('#arrowPlus')) {
            $('#arrowPlus').onclick = new Function("EFFECTS.plusArrow();")
        }
    }, minusArrow: function () {
        var pic_count = $('img.onClick').length;
        var minus = EFFECTS.pic_nr - 1;
        if (minus == 0) {
            minus = pic_count
        }
        var new_src = EFFECTS.pic_src.replace(/01/, "0" + minus);
        $('#pic').attr('src',new_src);
        EFFECTS.pic_nr = minus;
        EFFECTS.setCurrentImg((minus - 1))
    }, plusArrow: function () {
        var pic_count = $('img.onClick').length;
        var plus = EFFECTS.pic_nr + 1;
        if (plus == (pic_count + 1)) {
            plus = 1
        }
        var new_src = EFFECTS.pic_src.replace(/01/, "0" + plus);
        $('#pic').attr('src',new_src);
        EFFECTS.pic_nr = plus;
        EFFECTS.setCurrentImg((plus - 1))
    }
};
var url = "includes/newsbox_klicks.php?param=";

function handleHttpResponse() {
    if (http.readyState == 4) {
        results = http.responseText.split(",");
        alert(results[0])
    }
}
function cntNc(id) {
    http.open("GET", url + id, true);
    http.send(null)
}
function getHTTPObject() {
    var xmlhttp; /*@cc_on@if(@_jscript_version>=5)try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}catch(E){xmlhttp=false}}@else xmlhttp=false;@end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest()
        } catch (e) {
            xmlhttp = false
        }
    }
    return xmlhttp
}
var http = getHTTPObject();


function navH(id,img){
	var n = document.getElementById(id);
	n.src = img;
}
