// Pagination Teaser Klasse
function PaginationTeaser(id) {
    this.id = id;
	this.count			= 0;
	this.current		= 0;
	this.teaserList		= {};
	this.clicks			= 0;
	this.container		= false;
	this.counter		= false;
	this.teaserHeader   = false;
    this.teaserText     = false;
    this.teaserLink     = false;
    this.teaserBild     = false;
	this.ivw            = false;
	this.leftivw        = false;
    this.jsp            = "";
    this.teaserType     = "";
}

PaginationTeaser.prototype.nextTest = function() {
    alert(this.id);
    return false;
};

PaginationTeaser.prototype.get = function(sDocumentKey) {
    // Fr Reiterteaser: Teaser mit bergebenem sDocumentKey laden
    if(this.test()) {
        this.loadTeaser(sDocumentKey);
        return false;
    }else{
        return false;
    }
};

PaginationTeaser.prototype.next = function() {
    if(this.test()) {
        if(this.teaserList.length) {
            var newCurrent;
       		if(this.current < this.count-1){
            	newCurrent = this.current+1;
            } else {
            	newCurrent = 0;
            }
            this.loadTeaser(this.teaserList[newCurrent]);
            this.current = newCurrent;
        }
        return false;
    } else {
        return true;
    }
};

PaginationTeaser.prototype.previous = function() {
	if(this.test()) {
		if(this.teaserList.length) {
		 	var newCurrent;
		 	if(this.current == 0){
		 		newCurrent = this.count-1;
				if(newCurrent < 0 ) newCurrent = 0;
		 	} else {
		 		newCurrent = this.current-1;
		 	}
		 	this.loadTeaser(this.teaserList[newCurrent]);
		 	this.current = newCurrent;
		}
        return false;
    } else {
        return true;
    }
};

PaginationTeaser.prototype.loadTeaser = function(sDocumentKey) {
    var sRequest = "paginationTeaser.jsp?documentKey="+sDocumentKey;
    var self = this;
	$.ajax({
	    url: sRequest,
	    type: 'GET',
	    dataType: 'xml',
	    success: function(xml){ 
	    	$(xml).find('titel').each(function(){ self.teaserHeader.innerHTML = $(this).text(); });
			$(xml).find('text').each(function(){ self.teaserText.innerHTML = $(this).text(); });
			$(xml).find('link').each(function(){ self.teaserLink.innerHTML = $(this).text(); });
            $(xml).find('bild').each(function(){ self.teaserBild.innerHTML = $(this).text(); });
          	self.counter.innerHTML = self.current+1;
            // fr Reiterteaser: aktiven Reiter dunkel einf?en
            if(self.teaserType=="Reiter"){
            $('div.pagReiter_'+self.id).each(function(){ this.className = 'rtnavcard pagReiter_'+self.id; });
            $('#pagReiter_'+self.id+'_'+sDocumentKey)[0].className='rtnavcard_active pagReiter_'+self.id;
            } 
            if(self.teaserType=="Reiter_alternativ"){
            $('div.pagReiter_'+self.id).each(function(){ this.className = 'rtnavcard_alt pagReiter_'+self.id; });
            $('#pagReiter_'+self.id+'_'+sDocumentKey)[0].className='rtnavcard_active_alt pagReiter_'+self.id;
            }          	                     	
			self.loadPixelImg();    
	    }
	});
};

PaginationTeaser.prototype.test = function() {
		if(document.getElementById && document.getElementById != 'undefined') {
            if(!this.container || !this.counter) {
                this.container = $('#paginationTeaser_'+this.id+' div.teasercontentstart')[0];
                //this.counter = $('#paginationTeaser_'+this.id+' span.currentTeaser')[0];
                this.teaserHeader = $('#paginationTeaser_'+this.id+' span.klickteaserHeader')[0];
                this.teaserText = $('#paginationTeaser_'+this.id+' span.klickteaserText')[0];
                this.teaserLink = $('#paginationTeaser_'+this.id+' span.klickteaserLink')[0];
                this.teaserBild = $('#paginationTeaser_'+this.id+' div.klickteaserBild')[0];
			}
			if(this.container && this.teaserHeader && this.teaserText
                && this.teaserLink && this.teaserBild && this.container.innerHTML) {
                    return true;
			}
		}
		return false;
};

PaginationTeaser.prototype.loadPixelImg = function() {
    var image = new Image();
    image.src = "http://ardboers.ivwbox.de/cgi-bin/ivw/CP/"+this.leftivw+"; "+this.ivw+"?r=" + escape(document.referrer);
};
