var imagechecker = {
	
	globalImgSrc:'https://www.swimovate.de/images/product_variants/',
	
	origImgSrc:null,
	newImgSrc:null,
	
	origTbSrc:null,
	newTbSrc:null,
	
	imgPrfx:null,	// belongs to the variants text
	
	_filename:function(inp) {
		var ret = inp;
		var inpPt;
		if(inpPt = inp.split('/')){
			ret = inpPt[(inpPt.length-1)];
		}
		return ret;
	},
	
	_img:function(src) {
		var img = new Image();
		img.src = src;
		return img;
	},
	
	bigCheck:function(elem) {
		if(this.imgPrfx = elem.options[elem.selectedIndex].text.replace(/\W/, '_')) {
			if(this.origImgSrc==null)
				this.origImgSrc = this._filename($('a.thickbox.imagechecker').attr('href'));
			if(this.origTbSrc==null)
				this.origTbSrc = this._filename($('a.thickbox.imagechecker img#image').attr('src'));
			this.newImgSrc = this.imgPrfx+'-'+this.origImgSrc;
			this.newTbSrc = this.imgPrfx+'-'+this.origTbSrc;
			$('a.thickbox.imagechecker').attr({href:this.globalImgSrc+this.newImgSrc});
			$('a.thickbox.imagechecker img#image').attr({src:this._img(this.globalImgSrc+this.newTbSrc).src});
		}
	},
	
	smallCheck:function(elem) {
		if(this.imgPrfx = elem.options[elem.selectedIndex].text.replace(/\W/, '_')) {
			if(this.origImgSrc==null)
				this.origImgSrc = this._filename($('img.imagechecker').attr('src'));
			this.newImgSrc = this.imgPrfx+'-'+this.origImgSrc;
			$('img.imagechecker').attr({src:this._img(this.globalImgSrc+this.newImgSrc).src});
		}
	},
	
	cartCheck:function(){
		
		$('table.imagechecker tr.productrow').each(function(i, item){
			
			var imagePrefix = null;
			var origImgSrc = $(item).find('img.imagechecker').attr('src');
			
			if(imagePrefix = $(item).find("span.Farbe").html().replace(/\W/, '_')) {
				$(item).find('img.imagechecker').attr({src:imagechecker._img(imagechecker.globalImgSrc+imagePrefix+'-'+imagechecker._filename(origImgSrc)).src});
			}
		});
		
	}
	
};