// jQuery SmoothScroll
$(document).ready(function() {	if(top != self) top.location.replace(self.location.href); setTextindent(); addRatingHandler(); addAmps();addSmoothScroll();
   });

var addAmps = function (){
	var c = $('.entry h2 a:contains(&)').each(function (){
		this.innerHTML = this.innerHTML.replace(/&amp;/,'<span class="amp">&amp;</span>');
		}
	);
}

var setTextindent = function (){
	var c = $("div.longtext").each(function (){
		this.innerHTML = this.innerHTML.replace(/<br\/>/,'\<br\/\>&nbsp;&nbsp;&nbsp;');
		this.innerHTML = this.innerHTML.replace(/<br>/,'\<br\/\>&nbsp;&nbsp;&nbsp;');
		}
	);
}

var addSmoothScroll = function (){

	$('a[href*=#]').click(function() {
		var duration=1500;
		var easing='swing';
		if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'') && location.hostname==this.hostname && this.hash.replace(/#/,'')){
	     	var hash=this.hash;
	      	var target=$(hash).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: target }, duration, easing, function() { location.hash=hash; });
			return false;
	   		}

		});
}

var addRatingHandler = function (){
	$('ul.star-rating a').each( function (){
		this.onclick = function(){rateThis(document.getElementById('ratingmaster').title,this.title.split(' ')[0]); return false;}
	} );
}
var removeRatingHandler = function (){
	$('ul.star-rating a').each( function (){
		this.onclick = function(){return false};
		this.onmouseover = function(){return false}
	} );
}
var rateThis = function (item,rating){
	$.ajax({
		url : "/blog/mischa/includes/pods/rate.cfm",
		type:"POST",
		data:"id="+item+"&rating="+rating,
		success: function(newrating){finishRating(newrating);}
	});
}
var finishRating = function (newrating){
	$('#ratingmessage').html('<p>Die Bewertung wurde aktualisiert.</p>');
	if(!isNaN(newrating)){
		var newStyle=newrating*20;
		document.getElementById('ratingmaster').style.width=newStyle+"%";
		$('#ratingaverage').html(newrating);
		$('#ratingaverage').attr("title",newrating);
	}
	removeRatingHandler();
}

