function clxRateWidget(v){
	this.c = document.getElementById('clxReferrerRate');
	if(this.c == null)
		return false;
	this.options = {
		name: 'uns',
		backgroundColor: '#6578A0',
		linkColor: '#D0D9EA',
		textColor: '#FFF',
		lang: 'de',
		fir_nr: 0,
		city: ''	
	}
	i = this;
	this.head = document.getElementsByTagName("head")[0];
	this.options = this.mergeDefaults(v);
	this.options.siteUrl = this.c.href.substr(0,this.c.href.indexOf('/',7));
	this.options.siteName = this.options.siteUrl.replace('http://','');
	this.options.name = this.c.innerHTML;
	this.c.innerHTML = '';
	this.start(i);	
}
var clxRW = clxRateWidget.prototype = {
	start:function(i){	
		this.injectCss();
		this.applyConfig();
		this.getTxt();
	},
	mergeDefaults: function(c) {
		c.merge = function(k, dV) {
			if(typeof(k) == 'undefined') c[x] = dV;
		}
		for (var x in this.options) {
			c.merge(c[x], this.options[x])
		}
		return c;
	},
	getTxt: function() {
		js = document.createElement('script');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', 'http://webmastertools.cylex.de/reviews/rate.' + this.options.lang + '.js');
		this.head.appendChild(js);
		js.onreadystatechange = function () {
			if (js.readyState == 'complete' || js.readyState == 'loaded') {
				i.writeTxt();				
			}
		}
		js.onload = function () {
			i.writeTxt();
		}
	},
	writeTxt: function() {
		if(this.wR == true)
			return;
		this.wR = true;		
		this.dN1 = document.createElement('div');		
		this.dN1.id = "clxRateWidget";		
		stars = '';
		for(x=1;x<6;x++) 
			stars += '<li><a href="#" onclick="i.vote('+x+'); return false;" title="'+clxRateLang.rateIt.replace(/{star}/,x)+'" class="stars'+x+'">'+x+'</a></li>';
		if(this.options.size == 'small')
			this.dN1.innerHTML = '<span></span><div class="clxRateUs"><ul class="clxRatingStars">'+stars+'</ul><a class="clxRatingBtn" href="'+this.options.siteUrl+'/reviews/postreview.aspx?fir_nr='+this.options.fir_nr+'">'+clxRateLang.rateUs+'</a></div>';
		else
			this.dN1.innerHTML = '<span>'+clxRateLang.satisfied+'</span><div class="clxRateUs"><ul class="clxRatingStars">'+stars+'</ul><a class="clxRatingBtn" href="'+this.options.siteUrl+'/reviews/postreview.aspx?fir_nr='+this.options.fir_nr+'">'+clxRateLang.rateUs+'</a></div><span>'+clxRateLang.visitUs.replace(/{name}/, '<a href="'+this.c.href+'">'+this.options.name+'</a>').replace(/{city}/, this.options.city).replace(/{sitename}/, '<a href="'+this.options.siteUrl+'">'+this.options.siteName+'</a>')+'</span>';
		this.c.parentNode.appendChild(this.dN1);
	},
	injectCss: function() {
		this.clxCssNode = document.createElement('link');
		this.clxCssNode.type = 'text/css';
		this.clxCssNode.rel = 'stylesheet';
		this.clxCssNode.href = 'http://webmastertools.cylex.de/reviews/rateWidget.css';
		this.head.appendChild(this.clxCssNode);
	},
	applyConfig: function() {
		style = 'div#clxRateWidget {background-color:' + this.options.backgroundColor + '; }\n' +
            'div#clxRateWidget a { color:' + this.options.linkColor + '; }\n' +
            'div#clxRateWidget span { color:' + this.options.textColor + '; }\n' +
			'div.clxRateUs{ border-color:' + this.options.linkColor + '; }\n' +
            'div#clxRateWidget a.clxRatingBtn { color: '+ this.options.backgroundColor +';}\n';
		clxCssNode2 = document.createElement('style');
		clxCssNode2.type = 'text/css';
		clxCssNode2.title = 'CylexReviewWidget';
		if (clxCssNode2.styleSheet) {
			//IE only
			clxCssNode2.styleSheet.cssText = style;    
		} else {
			//W3C
			var clxCssNode2Content = document.createTextNode(style);
			clxCssNode2.appendChild(clxCssNode2Content);
		}
		this.head.appendChild(clxCssNode2);
	},
	vote: function(v) {
		window.open(this.options.siteUrl+'/reviews/postreview.aspx?fir_nr='+this.options.fir_nr+'&anon=1&stars='+v, "clxRatingPopup", "width=400,height=500,resizable=yes");
	}
}