pornstar = {};
var ratingText;

pornstar.sel = function (id,num,style)
{
    ratingText = $('ratingtext').innerHTML;
    for(var i=1;i<=5;i++) {
        var el = document.getElementById('s' + i + 'g' + id);
        if(el) {
            el.storedClassName = el.className;
            el.className = 'porn' + style + 'star porn' + style + 's_empty';
        }
    }

    for(var i=1;i<=num;i++) {
        var el = document.getElementById('s' + i + 'g' + id);
        if(el) {
            el.className = 'porn' + style + 'star porn' + style + 's_selected';
        }
    }

    switch(num) {
	case 1:
	$('ratingtext').innerHTML = "Awful";
	break;
	case 2:
	$('ratingtext').innerHTML = "Bad";
	break;
	case 3:
	$('ratingtext').innerHTML = "OK";
	break;
	case 4:
	$('ratingtext').innerHTML = "Good";
	break;
	case 5:
	$('ratingtext').innerHTML = "Amazing!";
	break;
    }
    $('ratingtext').setStyle('color', '#FFF');

}

pornstar.restore = function (id,num)
{
    for(var i=1;i<=5;i++) {
        var el = document.getElementById('s' + i + 'g' + id);
        if(el && el.storedClassName) {
            el.className = el.storedClassName;
        }
    }
    
    $('ratingtext').innerHTML = ratingText;
    $('ratingtext').setStyle('color', '#6e6e6e');
}

pornstar.disable = function (id,num)
{
    for(var i=1;i<=num;i++) {
        var el = document.getElementById('s' + i + 'g' + id);
        if(el) {
            if(el.storedClassName) el.className = el.storedClassName;
            el.onmouseout = function(){};
            el.onmouseover = function(){};
            el.onclick = function(){};
        }
    }
}

pornstar.vote = function (id,num,count)
{
    var xhr = null;
    if (window.ActiveXObject) {
        try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
        catch (e) { try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
        catch (e) { xhr = null; }}
    }else if (document.implementation && document.implementation.createDocument) {
        xhr = new XMLHttpRequest(); 
    }
    if(xhr == null) return;
    xhr.open('GET', 'http://www.porn2.com/cgi-bin/vote.cgi?' + id + '-' + num + '-' + count,  false);
    try {xhr.send(null);} catch(e) {}

    if(xhr.readyState  == 4 && xhr.status == 200) {
	var ratingcount = $('ratingcount');
	$('ratingcount').innerHTML = parseInt(ratingcount.innerHTML) + 1
        $('ratingtext').setStyle('color', '#6e6e6e');
	for(var i=1;i<=num;i++) {
        var el = document.getElementById('s' + i + 'g' + id);
        if(el) {
        el.onmouseout = function(){};
        el.onmouseover = function(){};
        el.onclick = function(){};
        pornstar.sel = function(){};
        pornstar.restore = function(){};
        pornstar.vote = function(){};
        }
	}
    }
}
