
//rotating thumb functions
var changing_thumbs = new Array();
function changeThumb(index, i, num_thumbs, path)
{
    if (changing_thumbs[index])
    {
		hidden_image_id = (i + 1) % num_thumbs;
        document.getElementById(index).src = path + "/" + i + ".jpg";
        $('#hidden_image').attr( { src: path + "/" + hidden_image_id + ".jpg" } );
        
        i = i % num_thumbs;
        i++;
        setTimeout("changeThumb('" + index + "'," + i + ", " + num_thumbs + ", '" + path + "')", 600);
    }
}    
function startThumbChange(index, num_thumbs, start_thumb, path)
{    
    changing_thumbs[index] = true;
    changeThumb(index, start_thumb, num_thumbs, path);
}
function endThumbChange(index, start_thumb, path)
{
    changing_thumbs[index] = false;
    document.getElementById(index).src = path + "/"+start_thumb+".jpg";
}
function addToMyShelf(video_id)
{
	//$('#divStatus').show();
	$.post("/contents/shelf/"+video_id);
	$('#item-'+video_id).effect("highlight", {}, 3000);
	$('#divStatus').effect("highlight", {}, 2000);
	$('#divStatus').html('<p>Movie added to your shelf...</p>');
   /*	$('#divStatus').effect("highlight", {}, 3000); */
	$('#divStatus').fadeOut(3000);
//	new Effect.Highlight('divStatus', {delay: .1, duration: 3, startColor:'#fff', endColor:'#f00'});
	//$.cookie('myShelf', video_id);
	return false;
    
}
function removeFromMyShelf(video_id)
{
	$('#divStatus').show();
	$.post("/contents/removeShelf/"+video_id);

	$('#divStatus').html('<p>Movie removed from your shelf...</p>');
   /*	$('#divStatus').effect("highlight", {}, 3000); */
	$('#divStatus').effect("highlight", {}, 2000);
	$('#divStatus').fadeOut(3000);
	$('#item-'+video_id).fadeOut(2000);
	
//	new Effect.Highlight('divStatus', {delay: .1, duration: 3, startColor:'#fff', endColor:'#f00'});
	//$.cookie('myShelf', video_id);
    return false;
}
function setWatchingPhoto(photo)
{
	photo.fadeIn(1000);
}
function getWatchingNow()
{
	$.getJSON("/ContentsWatchings/index/sort:created/direction:desc/data.json",
	        function(data){
			  if(data.watching) {
				$("#watchingnow").append("&nbsp;");
			  	$.each(data.watching, function(i,item){
					//alert(item.ContentsComment.id);
					$("#watchingnow").append('&nbsp;&nbsp;<a href="/watch/'+item.id+'"><img id="watchingphoto'+item.id+'" style="display:none" src="http://static.pornoshelf.com/'+item.thumb+'" width="72"></a>');
					/*$("#watchingnow"+item.id).hide();*/
					$("#watchingphoto"+item.id).fadeIn(1000);
					/*$("#watchingnow").append("<span>Posted by "+item.username+" "+item.date+"</span>")*/
	            	//$("<img/>").attr("src", item.media.m).appendTo("#images");
	          	});
          	  }
			});
}
function getComments(content_id, startPage, addedComment)
{
	
	$.getJSON("/ContentsComments/index/page:"+startPage+"/content_id:"+content_id+"/sort:created/direction:desc/data.json",
	        function(data){
			  if(addedComment) {
				$("#popup-data").empty();	
			  }
			  if(data.comments) {
			  	$.each(data.comments, function(i,item){
					//alert(item.ContentsComment.id);
				
					$("#popup-data").append("<li>"+item.comment+"</li>");
					$("#popup-data").append("<span>Posted by "+item.username+" "+item.date+"</span>")
	            	//$("<img/>").attr("src", item.media.m).appendTo("#images");
	          	});
          	  }
	          if(data.paging.nextPage) {
				startPage = data.paging.page+1;
				$("#showPaginationLink").show();
				$("#showPaginationLink").attr({onClick: "getComments("+content_id+", "+startPage+",false); return false;"});
			    /*$("#popup-data").append('<a href="#" onClick="getComments('+content_id+', '+data.paging.nextPage+')"></a>');*/
			  } else {
				$("#showPaginationLink").hide();
			  }
			});

}