var uRat = {
imgs : new Array(),
sImg : new Array(),
countImgs : null,
Box : null,
itemID : null,
boxId : null,
usrId : null,
dS : 0,
dA : 1,
initialize : false,
xmlhttp : false,

init : function(elmCount, arImg, mBoxId, mBoxVId, itemId, usrId, orgRat)
{
if(!mBoxId || !elmCount || !arImg || !itemId || !usrId){return false;}

this.sImg = arImg;
this.countImgs = elmCount;
this.itemID = itemId;
this.boxId = mBoxId;
this.boxVId = mBoxVId;
this.usrId = usrId;
this.orgRat = orgRat;

Funcs.preloadImgs(arImg);
this.Box = Funcs.gEBI(mBoxId);
this.VBox = Funcs.gEBI(mBoxVId);
this.mkBox();

this.initialize = true;
},
mkBox : function()
{
var txt = Funcs.cTxt("Hodnocení");
Funcs.appC(this.Box,txt);

for(i=0; i<this.countImgs; i++){
var img = Funcs.cElm("img");
if (i >= this.orgRat) {
img.src = this.sImg[this.dS];
} else {
img.src = this.sImg[this.dA];
}
img.alt = i+1;
img.onclick = function(){uRat.ratingVote(this);}
img.onmouseover = function(){uRat.ratingSwitch(this,1);}
img.onmouseout = function(){uRat.clearArray();}
img.style.cursor = "pointer";
this.imgs[i] = img;
Funcs.appC(this.VBox,img);
}
},

showVote : function(arr, count)
{
if (count && document.getElementById('rating_info')) {
document.getElementById('rating_info').innerHTML = 'Hlas uložen.';
}
Funcs.rmChilds(this.Box);
Funcs.rmChilds(this.VBox);

var txt = Funcs.cTxt("Hodoncení");
Funcs.appC(this.Box,txt);

for(i=0; i<this.countImgs; i++){
var img = Funcs.cElm("img");
img.src = arr[i] ? this.sImg[this.dA] : this.sImg[this.dS];
img.alt = "";
Funcs.appC(this.VBox,img);
}
},
ratingSwitch : function(elm, status)
{
var pos = elm.alt;
if(!this.initialize || status >= this.sImg.lenght){return false;}

ps = (pos > this.imgs.length ? this.imgs.length : pos);

for(i=0; i<ps; i++){
this.imgs[i].src = this.sImg[status];
}

if(i < this.imgs.length){
this.unselect(i,false);
}
return true;
},
clearArray : function()
{
if(!this.initialize){return false;}

this.unselect(this.orgRat,false,0);
return true;
},

unselect : function(elm,type, pos)
{
if (!pos) {
pos = type ? elm.alt -1 : elm;
}
for(i=0; i<this.countImgs; i++){
if (pos <= i) {
this.imgs[i].src = this.sImg[this.dS];
} else {
this.imgs[i].src = this.sImg[this.dA];
}
}
return true;
},

ratingVote : function(elm)
{
if(!this.initialize){return false;}

var url = "/"
var content = "scripts/user_rating.php?rate="+elm.alt+"&item="+this.itemID+"&user="+this.usrId;
xmlhttp.request(url,content,false,this.boxId);
}
}
