function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function disableSelection() {
	var nodes = getElementsByClass('disableSelection');
	for(i=0; i<nodes.length; i++) {
    nodes[i].onselectstart = function() {
        return false;
    };
    nodes[i].unselectable = "on";
    nodes[i].style.MozUserSelect = "none";
    nodes[i].style.cursor = "default";	
    }
}

function clearSearchField(field) {
   if (field.className == 'unEdited') {
      field.value = '';
      field.className = '';
   }
}

function doItemHover() {
   this.style.backgroundPosition='0 0';
}

function redoItemHover() {
   this.style.backgroundPosition='-200px';
}

Event.observe(window, 'load', function() {
   disableSelection();
   $$('.itemHover').each(function(item) { item.observe('mouseover', doItemHover); item.observe('mouseout', redoItemHover); });
}, false);

//$$('.itemHover').each(function(item) { item.observe('mouseover', itemHover); });

function pup(url,w,h){var winl=(screen.width-w)/2;var wint=(screen.height-h)/2;var settings ='height='+h+',';settings+='width='+w+',';settings+='top='+wint+',';settings+='left='+winl+',';settings+='scrollbars=yes,';settings+='resizable=no';window.open(url,'',settings);}

votes = [];
jQuery(document).ready(function() {
    
    if (window.location.hostname != "office.gold.lv") var prefix = '/';
    else var prefix = '/karpas/';

    
    jQuery('.voting_controls a').live('click', function(event) {
        event.preventDefault();
        if (jQuery(this).closest('div').hasClass('disabled') || jQuery(this).hasClass('chosen')) return false;
        var id = jQuery(this).closest('div').attr('id');
        var points = jQuery(this).attr('rel');
        var thisdiv = jQuery(this).closest('div')
        //console.log(jQuery(this).parent().parent().closest('div'));
        //console.log(points);
        jQuery.post(prefix+'modules/usergalleries/vote.php',{id: id, option: points}, function(data) {
            jQuery(thisdiv).addClass('disabled');
            //console.log(data);
            var points = parseInt(jQuery(thisdiv).parent().find('.voting_result2 strong').text()) + parseInt(data);
            jQuery(thisdiv).parent().find('.voting_result2 strong').text(data);
        })
        return false;
    });

    jQuery('.voting_controls2 a').live('click', function(event) {
        event.preventDefault();
        if (jQuery(this).closest('div').hasClass('disabled') || jQuery(this).hasClass('chosen')) return false;
        var id = jQuery(this).closest('div').attr('id');
        var points = jQuery(this).attr('rel');
        var thisdiv = jQuery(this).closest('div')
        //console.log(jQuery(this).parent().parent().closest('div'));
        //console.log(points);
        jQuery.post(prefix+'modules/shop/vote.php',{id: id, option: points}, function(data) {
            jQuery(thisdiv).addClass('disabled');
            //console.log(data);
            var points = parseInt(jQuery(thisdiv).parent().find('.voting_result2 strong').text()) + parseInt(data);
            jQuery(thisdiv).parent().find('.voting_result2 strong').text(data);
        })
        return false;
    });
});
