function clxReviewWidget(v){
	this.c = document.getElementById('clxReferrerLink');
	if(this.c == null)
		return false;
	this.c.innerHTML = '';
	this.options = {
		headline: 'CYLEX Bewertungen',
		borderColor: '#3a4663',
		backgroundColor: '#FFF',
		textColor2: '#666',
		textColor: '#000',
		showUsername: true,
		showAvatar: true,
		showStars: true,
		showAskReview: true,
		lkz: 'd',
		fir_nr: 0,
		city: '',
		interval: 5000,
		speed: 500,
		more_rev_txt: 'More Reviews',
		domain: '',
		language: ''
	}
	i = this;
	this.item = -1;
	this.clx_review_text = '';
	this.head = document.getElementsByTagName("head")[0];
	this.options = this.mergeDefaults(v);
	this.start();	
}

clxReviewWidget.prototype = {
	start:function(i){		
		this.injectCss();
		this.injectCss1();
		this.applyConfig();
		this.getReviews();
	},
	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;
	},
	getReviews: function() {
	    //add review widget
		js = document.createElement('script');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', 'http://webmastertools.'+this.options.domain+'/reviews/rate.' + this.options.language + '.js');
		this.head.appendChild(js);		
	    //--
		js = document.createElement('script');
		js.setAttribute('type', 'text/javascript');
		if(this.options.fir_nr>0)
		    js.setAttribute('src', 'http://webmastertools.'+this.options.domain+'/reviews/reviewsinfo.aspx?lkz=' + this.options.lkz + '&fir_nr=' + this.options.fir_nr);
		else if(this.options.city != '')
		    js.setAttribute('src', 'http://webmastertools.'+this.options.domain+'/reviews/reviewsinfo.aspx?lkz=' + this.options.lkz + '&city=' + this.options.city);
		else
		    js.setAttribute('src', 'http://webmastertools.'+this.options.domain+'/reviews/reviewsinfo.aspx');
		this.head.appendChild(js);
		
		js.onreadystatechange = function () {
			if (js.readyState == 'complete' || js.readyState == 'loaded') {
				i.clxWriteReviews();
			}
		}
		js.onload = function () {
			i.clxWriteReviews();
		}
	}, 
	next: function(){	
		this.item++;
		if(this.item >= this.dN.length)
			this.item = 0;
		this.cH = this.dN[this.item].offsetHeight;
		this.cT = parseInt(this.options.speed/this.cH);
		this.slide(0);
		aktiv = window.setInterval("i.slide(i.x)", i.cT);		
	}, 
	slide: function(x) {
		this.x = x;
		if(x<this.cH) {
			this.x = this.x+2;
			this.dN[this.item].style.marginTop=- x+ 'px';
		} else {
			i.dN2.appendChild(this.dN[this.item]);
			this.dN[this.item].style.marginTop=0;
			window.clearInterval(aktiv);
			window.setTimeout("i.next(i.item)", i.options.interval);		
		}		
	},
	clxWriteReviews: function() {
		if(this.wR == true)
			return;
		this.wR = true;
		this.dN2 = document.createElement('div');
		this.dN2.id = "clxReviews";
		this.dN = [];
		
		for(j = 0; j < clx_reviews.review.length; ++j) {
			this.clx_review_text += '<h3 class="clx_stars'+(this.options.showStars ? clx_reviews.review[j].stars : '')+'">' + clx_reviews.review[j].title + '</h3><p>';
			if(this.options.showAvatar == true)
				this.clx_review_text += '<img class="clx_avatar" src="'+(clx_reviews.review[j].avatar.indexOf('gravatar.com') == -1 ? clx_lang.baseUrl : '') +clx_reviews.review[j].avatar+'" />';
			this.clx_review_text += clx_reviews.review[j].text + '</p>';
			this.clx_review_text += '<p class="clx_meta">'+clx_lang.tags+': ' + clx_reviews.review[j].tags+'</p>';
			if(this.options.showUsername == true)
				this.clx_review_text += '<p class="clx_meta">'+clx_lang.from+' ' + clx_reviews.review[j].user + ' '+clx_lang.dateTime.replace(/{date}/, clx_reviews.review[j].date).replace(/{time}/, clx_reviews.review[j].time)+'</p>';
			this.dN[j] = document.createElement('div');
			this.dN[j].innerHTML = this.clx_review_text;
			this.dN2.appendChild(this.dN[j]);
			this.clx_review_text = '';
		}
		
		this.dN1 = document.createElement('div');
		if(this.options.showAskReview == true)
		{
		    //add review widget
		    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>';
		    this.dN1.innerHTML = '<div id="clxRateWidget"><span>'+clxRateLang.satisfied+'</span><a href="'+clx_lang.baseUrl+'reviews/chooseAnonimus.aspx?redirect=%2freviews%2fpostreview.aspx%3ffir_nr%3d'+this.options.fir_nr+'">'+clxRateLang.rateUs+'</a><ul class="clxRatingStars">'+stars+'</ul></div><div style="clear:both"></div>';
		    //--
		}
		else
		    this.dN1.innerHTML = '';
		this.dN1.innerHTML = this.dN1.innerHTML + '<h2>'+this.options.headline+'</h2>';
		this.dN1.id = "clxReviewWidget";
		this.dN1.appendChild(this.dN2);
		f = document.createElement('div');
		f.id = 'clx_foot';
		f.innerHTML = '<a href="' + this.c.href + '" id="clx_rev_url">' + this.options.more_rev_txt + '</a><a href="' + clx_lang.baseUrl + '"><img src="http://webmastertools.'+this.options.domain+'/reviews/images/logo.png" alt="CYLEX" height="19" /></a>';
		this.dN1.appendChild(f);
		this.c.parentNode.appendChild(this.dN1);
		window.setTimeout("i.next(i.item)", i.options.interval);

	},
	injectCss: function() {
		this.clxCssNode = document.createElement('link');
		this.clxCssNode.type = 'text/css';
		this.clxCssNode.rel = 'stylesheet';
		this.clxCssNode.href = 'http://webmastertools.'+this.options.domain+'/reviews/rateWidgetMerged.css';
		this.head.appendChild(this.clxCssNode);
	},
	injectCss1: function() {
		this.clxCssNode = document.createElement('link');
		this.clxCssNode.type = 'text/css';
		this.clxCssNode.rel = 'stylesheet';
		this.clxCssNode.href = 'http://webmastertools.'+this.options.domain+'/reviews/reviewWidget.css';
		this.head.appendChild(this.clxCssNode);
	},
	applyConfig: function() {
		px = isNaN(this.options.width)?'':'px'
		css = 'div#clxReviewWidget {width:' + this.options.width + 'px; border-color:' + this.options.borderColor + '; }\n' +
		'div#clxReviewWidget h2 {color:' + this.options.backgroundColor + '; background-color:' + this.options.borderColor + ';}\n' +
		'div#clxReviewWidget div#clxReviews {background-color:' + this.options.backgroundColor + '; height: ' + this.options.height + 'px;}\n' +
		'div#clxReviewWidget div#clxReviews div {border-color:' + this.options.borderColor + ';}\n' +
		'div#clxReviewWidget div#clxReviews div h3 {color:' + this.options.borderColor + ';}\n' +
		'div#clxReviewWidget div#clxReviews div p.clx_meta {color:' + this.options.textColor2 + ';}\n' +
		'div#clxReviewWidget div#clxReviews img.clx_avatar {border-color:' + this.options.borderColor + ';}\n' +
		'div#clxReviewWidget div#clx_foot {border-color:' + this.options.borderColor + '; background-color:' + this.options.borderColor + ';}\n' +
		'div#clxReviewWidget div#clx_foot a#clx_rev_url {color:' + this.options.backgroundColor + ';}\n' +
		'div#clxReviewWidget div#clxReviews p {color:' + this.options.textColor + ';}\n' +		
        'div#clxReviewWidget div#clxRateWidget span { color:' + this.options.borderColor + '; }\n' +
		'div#clxReviewWidget div#clxRateWidget a { color:' + this.options.borderColor + '; }\n';

		clxCssNode2 = document.createElement('style');
		clxCssNode2.type = 'text/css';
		clxCssNode2.title = 'CylexReviewWidget';
		if (clxCssNode2.styleSheet) {
			//IE only
			clxCssNode2.styleSheet.cssText = css;        
		} else {
			//W3C
			var clxCssNode2Content = document.createTextNode(css);
			clxCssNode2.appendChild(clxCssNode2Content);
		}
		this.head.appendChild(clxCssNode2);	
	},
	vote: function(v) {
	    var openedWindow;
		openedWindow = window.open(clx_lang.baseUrl+'reviews/chooseAnonimus.aspx?redirect=%2freviews%2fpostreview.aspx%3ffir_nr%3d'+this.options.fir_nr+'&anon=1&stars='+v, "clxRatingPopup", "width=430,height=530,resizable=yes");
	}
}
