$(document).ready(function() {
// get current rating
getRating();
// get rating function
function getRating(){
$("ul.star-rating").each(function(){
id = parseFloat($(this).attr("id").match(/\d+\.?\d*/gi)[0]); //find out the linkid 
$.ajax({
type: "POST",
url: "../../lib/rating.php",
data: "do=getrate&id="+id,
cache: false,
async: false,
success: function(result) {
// apply star rating to element
$(".star-rating#song"+id+" #current-rating").css({ width: "" + result + "%" });
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});
}

// link handler
$('#ratelinks li a').click(function(){
id = parseFloat($(this).parent().parent().parent().attr("id").match(/\d+\.?\d*/gi)[0]); //find out the linkid 
$.ajax({
type: "POST",
url: "../../lib/rating.php",
data: "rating="+$(this).text()+"&do=rate&id="+id,
cache: false,
async: false,
success: function(result) {
// remove #ratelinks element to prevent another rate
$("#ratelinks").remove();
$("#rating strong").text("Thank you");
// get rating after click
getRating();
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});



$('#video a').click(function(){
if ($(this).attr("id")!="") {
videoid = parseFloat($(this).attr("id").match(/\d+\.?\d*/gi)[0]); //find out the linkid 	
$.ajax({
type: "POST",
url: "../../lib/reportvideo.php",
data: "id="+videoid,
cache: false,
async: false,
success: function(result) {
$('#video span').html("<strong>Thank you!</strong>");
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
return false;
});



$('a#savetofavorites').click(function(){
if ($(this).attr("name")!="") {
$.ajax({
type: "POST",
url: "../../lib/savefavoritesong.php",
data: "id="+$(this).attr("name"),
cache: false,
async: false,
success: function(result) {
$('a#savetofavorites').text("Saved");
$('a#savetofavorites').attr("name", "");
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
return false;
});









$('#submit_comment').click(function(){
var text = $('textarea#commenttext').val();
var name = $('input#uname').val();
var songid = $('input#sname').val();

if(text=="") {
alert("Please enter some words :)");
return false;
}

if (text!="" && name!="" && songid!="") {
$.ajax({
type: "POST",
url: "../../lib/addcomment.php",
data: "text="+text+"&name="+name+"&songid="+songid,
cache: false,
async: false,
success: function(result) {
$('#writecomment').html("<strong>Thank you!</strong>");
$('.comment.hidden span.text').text(text);
$('.comment.hidden').removeClass("hidden");
$('.comment.new').hide();
$('.comment.new').fadeIn("slow");
$('.response_hide').hide();
},
error: function(result) {
alert("Some error occured, please try again later!");
}
});
}
return false;
});






if ($.browser.msie && $.browser.version.substr(0,1)==6) {} else{
columnposition = $("#songinfo").position();
scrolltop = $(window).scrollTop();


$(window).scroll(function () {
scrolltop = $(window).scrollTop();
if (scrolltop >= 105) {$("#songinfo").css("top", 0+"px");}
else {$("#songinfo").css("top", 105-scrolltop+"px");}
});

if (scrolltop >= 105) {$("#songinfo").css("top", 0+"px");}
}


});