// JavaScript Document
function thankForVote(response,id)
{
   
	if (response)
	{
		//alert(response.responseText);
		//alert(_b);
		id.innerHTML=response.responseText;
	}
}
var ScrollBar =
{
   input_id : null,
   div_id 	: null,
   width	: null,
  
   create : function(id, input, fromID,ownerid, inputvalue,width,url)
   {
	  width = width?width:100;
	  var leftWidth  = 11;
	  var rightWidth = 33;
	  var thumbWidth = 31;
	  var submitWidth = 60;
	  var barWidth = width -  rightWidth - submitWidth;// - thumbWidth ;
      ScrollBar.input_id   = input;
      //ScrollBar.div_id	 = div;
	  this.ownerid = ownerid ;
	  barposition = parseInt(inputvalue/100*barWidth);
	  
	  
      var oInput = document.createElement("INPUT");
	  oInput.setAttribute("type","text");
	  oInput.readOnly = true;
	  oInput.setAttribute("name",input);
	  oInput.setAttribute("id",input);
	  oInput.setAttribute("value",inputvalue);
	  oInput.setAttribute("size",3);
	  //oInput.setAttribute("class","scoreLabel");

      oInput.className    = "scoreLabel";
      oInput.style.color  = "white";
      oInput.style.cursor = "pointer";
      //
      var otDiv = document.createElement("DIV");
      otDiv.style.position = "absolute";
      otDiv.style.left = 0;
       //otDiv.className = "outer-container";
      var itDiv = document.createElement("DIV");
      itDiv.className = "input_container";
    // itDiv.style.left = barWidth + thumbWidth  + "px";
	  
      var oDiv = document.createElement("DIV");
      oDiv.className = "scroll-container";
      oDiv.style.position = "relative";
	  oDiv.style.width = width + "px";
	  
//	  var barLeft = document.createElement("DIV");
//		   barLeft.className = 'borderBg';
//		   barLeft.style.left = 0;
//		   barLeft.style.top = 0;
		   
	  var barMidlle = document.createElement("DIV");
	  	  // barMidlle.style.background = 'url(Template/skinDefault/images/b.png)';
		   barMidlle.className = 'borderBg';
		   barMidlle.style.left = '0px';
	 // var  midwidth = width -leftWidth - rightWidth - submitWidth ;
     var  midwidth = width - 10 - submitWidth ;	  
		   barMidlle.style.width = midwidth + "px";
		   barMidlle.style.top   = "9px";

		  // barMidlle.style.height = "31px";
		   
	  var barRight = document.createElement("DIV");
	  	  barRight.style.background = 'url(Template/skinDefault/images/br.png)';
		  barRight.className = 'borderBg';
		  barRight.style.left = midwidth + leftWidth +'px';
		  barRight.style.height = "31px";
		  barRight.style.width  = "33px";

	   //  oDiv.appendChild(barLeft);
		 oDiv.appendChild(barMidlle);
	  //   oDiv.appendChild(barRight);
		 
      var cDiv =  document.createElement("DIV");
      //cDiv.id = ownerid;
      cDiv.className = "thumb";
      cDiv.style.position = "relative";
      itDiv.style.left = cDiv.offsetLeft -3 + "px";
      cDiv.appendChild(itDiv);
      
	  var barpost = barposition;
	  barpost = (barpost<0)?0:barpost;
	  cDiv.style.left = barpost + "px";
	  attachDrag(cDiv, "x", midwidth-15, 0,ScrollBar.doChanges);
	  //set 
      var sDiv = document.createElement("DIV");
	  sDiv.className = "bar_submit"; 
	  sDiv.style.left = width - submitWidth + "px";
	  
	  var coverDiv = document.createElement("DIV");
	  coverDiv.className = "scroller_cover";
	  coverDiv.style.width = barposition  + "px";
	  
	  sDiv.onclick = function()
	  {
		 var pscore = $F(input);
		 if(pscore==0){
			alert("Your vote was not counted, you need to vote between 1-100, try again!");
	   }else{
			 
			if (fromID != "" || fromID>0 || fromID != null)
			 {
				 if (ownerid != fromID)
				 {
					var urls = url+"&pscore="+$F(input);
					
					var myAjax  = new Ajax.Request(urls,{method:'post',onComplete:function(response){
			thankForVote(response,id)
				}
		})
				 }else
				 {
				   alert("You could not vote for yourself!");
				 }
			 }else
			 {
				 alert("You must login first!");
			 }
		  }
		  }

      itDiv.appendChild(oInput);
	  
      oDiv.appendChild(cDiv);
      oDiv.appendChild(coverDiv); 
	  
      otDiv.appendChild(oDiv);
	  otDiv.appendChild(sDiv);
	 // otDiv.appendChild(itDiv);
	 
      oDiv.onmousedown = function (e)
      {			
         var e = FixE(e);
         var xPost,obj;
         if(typeof e.srcElement != 'undefined')// IE
         {
            if(e.srcElement.className == "thumb")
            {
               xPost = ScrollBar.el(input);
			   xPost_Real = (xPost > barWidth) ? barWidth : parseInt(xPost/100 * barWidth);
			   obj = e.srcElement;
            }
            else
            {
               xPost = e.layerX;
			   if(e.srcElement.className != "scroll-container")
			   {
				   xPost = xPost + 7 ;
				   obj = e.srcElement.parentNode.childNodes[2];
			   }else
			   {
				   obj = e.srcElement.childNodes[3];
				  
			   }
		       xPost	   -= parseInt(thumbWidth/2);
			   xPost_Real	= (xPost > barWidth) ? barWidth : xPost;
			   xPost 		=  parseInt(xPost_Real/barWidth * 100);
			   xPost_Real   = xPost/100 * barWidth; //	  			   
            }
         }
         else// Firefox
         {
            if(e.target.className == "thumb")
            {
               xPost = ScrollBar.el(input);
			   xPost_Real = (xPost > barWidth) ? barWidth : parseInt(xPost/100 * barWidth);
			   obj = e.target;
            }
            else
            {
               xPost 		= e.layerX;
			   if(e.target.className != "scroll-container")
			   {
				   xPost = xPost + 7 ;
				   obj = e.target.parentNode.childNodes[2];
			   }else
			   {
				   obj = e.target.childNodes[2];
			   }
				   xPost		-= parseInt(thumbWidth/2);
				   xPost_Real	= (xPost > barWidth) ? barWidth : xPost;
				   xPost 		=  parseInt(xPost_Real/barWidth * 100);
				   xPost_Real   = xPost/100 * barWidth;  
           	}
         }		 
         //xPost = 
		 xPost = xPost<0? 0 :xPost;
		 xPost_Real = xPost_Real<0? 0 :xPost_Real;
      	 document.getElementById(input).value = xPost;
      	 
       //  obj.style.left = xPost_Real + "px";
           obj.style.width = xPost_Real + "px";
		   obj.parentNode.childNodes[1].style.left = xPost_Real + "px";
      }
		 id.appendChild(otDiv);
   } ,
   el : function (id)
   {
      return document.getElementById(id).value;
   },
   doChanges: function(obj,_x,maxX)
   {
      var par = obj.parentNode.childNodes;
      for(var i=0;i<par.length;i++)
      {
        var it = par[i];
        if(it.className =="scroller_cover")
        {
            it.style.width = _x+"px";
        }
         if(it.className == "thumb")
        {
            it.childNodes[0].childNodes[0].value = parseInt((_x/maxX)*100); 
        }
      }
      var pp = obj.parentNode.parentNode.childNodes;
   },
   createCenterBar : function(obj,parNode){
        var line_div = document.createElement("div");
        line_div.className = "c_bar_bg";
        var bar = document.createElement("div");
        bar.className = "c_bar";
        if (parNode.angle!=null && typeof(parNode.angle)!='undefind'){
            bar.style.left = parNode.angle*100/180+100+"px";
        }else{
           bar.style.left = "100px";
        }
      // alert(parNode.or_width+","+parNode.or_height);
        attachDrag(bar, "x", 200, 0, function(o, _x, _y){
            roate(parNode.firstChild.firstChild, (_x-100)*180/100, parNode.or_width, parNode.or_height, true);
        }, function(o){
             var angle = (o.offsetLeft-100)*180/100;
             parNode.angle = angle;
             saveObjPosition(parNode);
        });
        obj.appendChild(bar);
        obj.appendChild(line_div);
   }
}
;
