function shuffle_t_shirts()
{
	cloneshirt = $(".sr_shirts:last").clone(true);
	$(".sr_shirts:first").before(cloneshirt);
	$(".sr_shirts:last").fadeOut(2000,function(){
		$(this).remove();
		setTimeout("shuffle_t_shirts()",2000);
	});
}
function shuffle_band_ad()
{
	cloneshirt = $(".band_ad_img:last").clone(true);
	$(".band_ad_img:first").before(cloneshirt);
	$(".band_ad_img:last").fadeOut(2000,function(){
		$(this).remove();
		setTimeout("shuffle_band_ad()",4000);
	});
}


function restoreStars(prefix) {
	$("#"+prefix+"ratings-widget").fadeIn(1000);
}
function RedStar(mystar)
{
$(mystar).attr({src: "/images/RedStar.png"});
}
function RedStarBefore(mystar)
{
$(mystar).prevAll().attr({src: "/images/RedStar.png"});
}
function GreyStar(mystar)
{
$(mystar).attr({src: "/images/GreyStar.png"});
}
function GreyStarAfter(mystar)
{
$(mystar).nextAll().attr({src: "/images/GreyStar.png"});
}
function WhiteStar(mystar)
{
$(mystar).attr({src: "/images/WhiteStar.png"});
}
function HalfStar(mystar)
{
$(mystar).attr({src: "/images/HalfStar.png"});
}
function ShowRating(prefix,rating)
{
	$("#"+prefix+"rating-stars").children().each(function(){GreyStar(this);});
	$("#"+prefix+"star-1").each(function(){
		if(rating > 0.5){WhiteStar(this);}else{ HalfStar(this);}
	});
	if(rating > 1){
	$("#"+prefix+"star-2").each(function(){
		if(rating > 1.5){WhiteStar(this);}else{ HalfStar(this);}
	});
	}
	if(rating > 2){
	$("#"+prefix+"star-3").each(function(){
		if(rating > 2.5){WhiteStar(this);}else{ HalfStar(this);}
	});
	}
	if(rating > 3){
	$("#"+prefix+"star-4").each(function(){
		if(rating > 3.5){WhiteStar(this);}else{ HalfStar(this);}
	});
	}
	if(rating > 4){
	$("#"+prefix+"star-5").each(function(){
		if(rating > 4.5){WhiteStar(this);}else{ HalfStar(this);}
	});
	}
}
function ResetRating(prefix,rating,bid)
{

$.ajax({
	   type: "POST",
	   url: "http://"+window.location.hostname+"/index.php/rating",
	   data: "rating="+rating+"&band_id="+bid,
	   async: true,
	   success: function(msg){
		   msgarr =msg.split(" ");
		   $("#"+prefix+"rateCount").html(msgarr[1]);
		   $("#"+prefix+"unsigned-band-rating").attr("rating",Number(msgarr[0]));
	   	   ShowRating(prefix,Number($("#"+prefix+"unsigned-band-rating").attr("rating")));
	   }
	});

}


function SetupRatingHandlers(prefix)
{
var bandrating;

$("#"+prefix+"unsigned-band-rating").each(function(){
 	bandrating= $(this).attr("rating");
	ShowRating(prefix,bandrating);
});

//initialize the rater for the band
urating = 0;
uband_id = $("#"+prefix+"unsigned-band-rating").attr("uband");

ResetRating(prefix,urating,uband_id);


}//SetupRatingHandlers


function SetupChoiceHandlers()
{
unsigned_band_menu=false;

$("#OtherUnsignedButton").mouseover(function(){
	  $(this).css({
			backgroundColor:"#e3e3e3",
			color:"red",
			cursor:"pointer",
			borderStyle:"inset",
			borderColor:"white"});
});
$("#OtherUnsignedButton").mouseout(function(){
	  $(this).css({
			backgroundColor:"#e3e3e3",
			color:"black",
			borderStyle:"outset",
			borderColor:"white"});
});
$("#OtherUnsignedButton").click(function(){
	window.location.href = "http://"+window.location.hostname+"/index.php/ouband/1";
});

} //end document SetupChoiceHandlers

$(document).ready(function(){

$("#scrollTrigger").each(function() {
		$(document).scrollTo("#commentPos",{axis:'y'});
});
	
$(".star-image").mouseover(function(){
		RedStarBefore(this);
		GreyStarAfter(this);
		RedStar(this);
});
$(".star-image").mouseout(function(){
	prefix = $(this).parent().attr("prefixid");

 	bandrating= $("#"+prefix+"unsigned-band-rating").attr("rating");
	ShowRating(prefix,bandrating);
});

$(".star-image").click(function(e){
	prefix = $(this).parent().attr("prefixid");
	urating = $(this).attr("starnum");
	uband_id = $("#"+prefix+"unsigned-band-rating").attr("uband");

	ResetRating(prefix,urating,uband_id);

	$("#"+prefix+"rating-ack").html("<p style=margin-bottom:10px;>Thanks for rating this band a "+urating+"</p><p style=line-height:0;margin-top:5px;text-decoration:blink;color:red><strong>ROCK ON!</strong></p>").css({position:"absolute",width:"310px",height:"70px",fontFamily:"Helvetica", fontSize:"20px",fontColor:"white",textAlign:"center",marginTop:"5px"}).fadeIn(1000).fadeOut(3000);

	$("#"+prefix+"ratings-widget").fadeOut(1000);

	$("#"+prefix+"ratings-widget").fadeIn(3000);

	return false;

});  //end click


$(".ratings-container").each(function(){
		prefix = $(this).find("span").attr("prefixid");
		SetupRatingHandlers(prefix);
	});
	SetupChoiceHandlers();
	shuffle_t_shirts();
	shuffle_band_ad();
	
/*$("div").each(function(){
	idattr = $(this).attr("id");
	clattr = $(this).attr("class");
	wattr = $(this).css("width");
	$(this).css({borderColor:"red",borderStyle:"solid",borderWidth:"1px"});
	$(this).append("<li class='divinfo' style='position:relative;left:0px;top:0px'>"+idattr+"   "+wattr+"   "+clattr+"</li>");
	
});*/

}); //end document ready func


