var sMax;	
var holder; 
var preSet; 
var rated;
var animatedcollapse={
divholders: {}, 
divgroups: {}, 
lastactiveingroup: {}, 
preloadimages: [],

show:function(divids){ 
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "show")
	}
	else
		this.showhide(divids, "show")
},

hide:function(divids){ 
	if (typeof divids=="object"){
		for (var i=0; i<divids.length; i++)
			this.showhide(divids[i], "hide")
	}
	else
		this.showhide(divids, "hide")
},

toggle:function(divid){
	if (typeof divid=="object")
		divid=divid[0]
	this.showhide(divid, "toggle")
},

addDiv:function(divid, attrstring){
	this.divholders[divid]=({id: divid, $divref: null, attrs: attrstring})
	this.divholders[divid].getAttr=function(name){ //assign getAttr() function to each divholder object
		var attr=new RegExp(name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,)
		return (attr.test(this.attrs) && parseInt(RegExp.$1)!=0)? RegExp.$1 : null //return value portion (string), or 0 (false) if none found
	}
	this.currentid=divid //keep track of current div object being manipulated (in the event of chaining)
	return this
},

showhide:function(divid, action){
	var $divref=this.divholders[divid].$divref //reference collapsible DIV
	if (this.divholders[divid] && $divref.length==1){ //if DIV exists
		var targetgroup=this.divgroups[$divref.attr('groupname')] //find out which group DIV belongs to (if any)
		if ($divref.attr('groupname') && targetgroup.count>1 && (action=="show" || action=="toggle" && $divref.css('display')=='none')){ //If current DIV belongs to a group
			if (targetgroup.lastactivedivid && targetgroup.lastactivedivid!=divid) //if last active DIV is set
				this.slideengine(targetgroup.lastactivedivid, 'hide') //hide last active DIV within group first
				this.slideengine(divid, 'show')
			targetgroup.lastactivedivid=divid //remember last active DIV
		}
		else{
			this.slideengine(divid, action)
		}
	}
},

slideengine:function(divid, action){
	var $divref=this.divholders[divid].$divref
	var $togglerimage=this.divholders[divid].$togglerimage
	if (this.divholders[divid] && $divref.length==1){ //if this DIV exists
		var animateSetting={height: action}
		if ($divref.attr('fade'))
			animateSetting.opacity=action
		$divref.animate(animateSetting, $divref.attr('speed')? parseInt($divref.attr('speed')) : 500, function(){
			if ($togglerimage){
				$togglerimage.attr('src', ($divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
			}
			if (animatedcollapse.ontoggle){
				try{
					animatedcollapse.ontoggle(jQuery, $divref.get(0), $divref.css('display'))
				}
				catch(e){
					alert("An error exists inside your \"ontoggle\" function:\n\n"+e+"\n\nAborting execution of function.")
				}
			}
		})
		return false
	}
},

generatemap:function(){
	var map={}
	for (var i=0; i<arguments.length; i++){
		if (arguments[i][1]!=null){ //do not generate name/value pair if value is null
			map[arguments[i][0]]=arguments[i][1]
		}
	}
	return map
},

init:function(){
	var ac=this
	jQuery(document).ready(function($){
		animatedcollapse.ontoggle=animatedcollapse.ontoggle || null
		var urlparamopenids=animatedcollapse.urlparamselect() //Get div ids that should be expanded based on the url (['div1','div2',etc])
		var persistopenids=ac.getCookie('acopendivids') //Get list of div ids that should be expanded due to persistence ('div1,div2,etc')
		var groupswithpersist=ac.getCookie('acgroupswithpersist') //Get list of group names that have 1 or more divs with "persist" attribute defined
		if (persistopenids!=null) //if cookie isn't null (is null if first time page loads, and cookie hasnt been set yet)
			persistopenids=(persistopenids=='nada')? [] : persistopenids.split(',') //if no divs are persisted, set to empty array, else, array of div ids
		groupswithpersist=(groupswithpersist==null || groupswithpersist=='nada')? [] : groupswithpersist.split(',') //Get list of groups with divs that are persisted
		jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object
			this.$divref=$('#'+this.id)
			if ((this.getAttr('persist') || jQuery.inArray(this.getAttr('group'), groupswithpersist)!=-1) && persistopenids!=null){ //if this div carries a user "persist" setting, or belong to a group with at least one div that does
				var cssdisplay=(jQuery.inArray(this.id, persistopenids)!=-1)? 'block' : 'none'
			}
			else{
				var cssdisplay=this.getAttr('hide')? 'none' : null
			}
			if (urlparamopenids[0]=="all" || jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains the single array element "all", or this div's ID
				cssdisplay='block' //set div to "block", overriding any other setting
			}
			else if (urlparamopenids[0]=="none"){
				cssdisplay='none' //set div to "none", overriding any other setting
			}
			this.$divref.css(ac.generatemap(['height', this.getAttr('height')], ['display', cssdisplay]))
			this.$divref.attr(ac.generatemap(['groupname', this.getAttr('group')], ['fade', this.getAttr('fade')], ['speed', this.getAttr('speed')]))
			if (this.getAttr('group')){ //if this DIV has the "group" attr defined
				var targetgroup=ac.divgroups[this.getAttr('group')] || (ac.divgroups[this.getAttr('group')]={}) //Get settings for this group, or if it no settings exist yet, create blank object to store them in
				targetgroup.count=(targetgroup.count||0)+1 //count # of DIVs within this group
				if (jQuery.inArray(this.id, urlparamopenids)!=-1){ //if url parameter string contains this div's ID
					targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded). Overrides other settings
					targetgroup.overridepersist=1 //Indicate to override persisted div that would have been expanded
				}
				if (!targetgroup.lastactivedivid && this.$divref.css('display')!='none' || cssdisplay=="block" && typeof targetgroup.overridepersist=="undefined") //if this DIV was open by default or should be open due to persistence								
					targetgroup.lastactivedivid=this.id //remember this DIV as the last "active" DIV (this DIV will be expanded)
				this.$divref.css({display:'none'}) //hide any DIV that's part of said group for now
			}
		}) //end divholders.each
		jQuery.each(ac.divgroups, function(){ //loop through each group
			if (this.lastactivedivid && urlparamopenids[0]!="none") //show last "active" DIV within each group (one that should be expanded), unless url param="none"
				ac.divholders[this.lastactivedivid].$divref.show()
		})
		if (animatedcollapse.ontoggle){
			jQuery.each(ac.divholders, function(){ //loop through each collapsible DIV object and fire ontoggle event
				animatedcollapse.ontoggle(jQuery, this.$divref.get(0), this.$divref.css('display'))
			})
		}
 		//Parse page for links containing rel attribute
		var $allcontrols=$('a[rel]').filter('[rel^="collapse["], [rel^="expand["], [rel^="toggle["]') //get all elements on page with rel="collapse[]", "expand[]" and "toggle[]"
		$allcontrols.each(function(){ //loop though each control link
			this._divids=this.getAttribute('rel').replace(/(^\w+)|(\s+)/g, "").replace(/[\[\]']/g, "") //cache value 'div1,div2,etc' within identifier[div1,div2,etc]
			if (this.getElementsByTagName('img').length==1 && ac.divholders[this._divids]){ //if control is an image link that toggles a single DIV (must be one to one to update status image)
				animatedcollapse.preloadimage(this.getAttribute('data-openimage'), this.getAttribute('data-closedimage')) //preload control images (if defined)
				$togglerimage=$(this).find('img').eq(0).data('srcs', {open:this.getAttribute('data-openimage'), closed:this.getAttribute('data-closedimage')}) //remember open and closed images' paths
				ac.divholders[this._divids].$togglerimage=$(this).find('img').eq(0) //save reference to toggler image (to be updated inside slideengine()
				ac.divholders[this._divids].$togglerimage.attr('src', (ac.divholders[this._divids].$divref.css('display')=="none")? $togglerimage.data('srcs').closed : $togglerimage.data('srcs').open)
			}
			$(this).click(function(){ //assign click behavior to each control link
				var relattr=this.getAttribute('rel')
				var divids=(this._divids=="")? [] : this._divids.split(',') //convert 'div1,div2,etc' to array 
				if (divids.length>0){
					animatedcollapse[/expand/i.test(relattr)? 'show' : /collapse/i.test(relattr)? 'hide' : 'toggle'](divids) //call corresponding public function
					return false
				}
			}) //end control.click
		})// end control.each

		$(window).bind('unload', function(){
			ac.uninit()
		})
	}) //end doc.ready()
},

uninit:function(){
	var opendivids='', groupswithpersist=''
	jQuery.each(this.divholders, function(){
		if (this.$divref.css('display')!='none'){
			opendivids+=this.id+',' //store ids of DIVs that are expanded when page unloads: 'div1,div2,etc'
		}
		if (this.getAttr('group') && this.getAttr('persist'))
			groupswithpersist+=this.getAttr('group')+',' //store groups with which at least one DIV has persistance enabled: 'group1,group2,etc'
	})
	opendivids=(opendivids=='')? 'nada' : opendivids.replace(/,$/, '')
	groupswithpersist=(groupswithpersist=='')? 'nada' : groupswithpersist.replace(/,$/, '')
	this.setCookie('acopendivids', opendivids, 365)
	this.setCookie('acgroupswithpersist', groupswithpersist, 365)
},

getCookie:function(Name){ 
	var re=new RegExp(Name+"=[^;]*", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return null
},

setCookie:function(name, value, days){
	if (typeof days!="undefined"){ //if set persistent cookie
		var expireDate = new Date()
		expireDate.setDate(expireDate.getDate()+days)
		document.cookie = name+ "="+value+"; path=/; expires="+expireDate.toGMTString()
	}
	else //else if this is a session only cookie
		document.cookie = name+"="+value+"; path=/"
},

urlparamselect:function(){
	window.location.search.match(/expanddiv=([\w\-_,]+)/i) //search for expanddiv=divid or divid1,divid2,etc
	return (RegExp.$1!="")? RegExp.$1.split(",") : []
},

preloadimage:function(){
	var preloadimages=this.preloadimages
	for (var i=0; i<arguments.length; i++){
		if (arguments[i] && arguments[i].length>0){
			preloadimages[preloadimages.length]=new Image()
			preloadimages[preloadimages.length-1].src=arguments[i]
		}
	}
}

}

// AJAX for all browsers
function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch(e) {
        //Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

// AJAX POST FUNCTION
function AjaxPost(url, param, success_function) {
	xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Your browser doesn't support AJAX. You should upgrade it!")
        return
    }
    xmlHttp.onreadystatechange = success_function;
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(param);
}

function $(d) {
    return document.getElementById(d);
}

// Rollover for image Stars //
function rating(num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "on";
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+i).className = "";
			}
		}else{
			rating(preSet);
		}
	}
}

// When you actually rate something //
function rateIt(me, id, site_url){
	if(!rated){
		preSet = me;
		rated=1;
		sendRate(me, id, site_url);
		rating(me);
	}
}

// Send the rating information somewhere using Ajax or something like that
function sendRate(sel, id, site_url){
	AjaxPost(site_url+"/includes/view_game/ajax/add_rating.php", "id=" + id + "&rating=" + sel.title, 
			 function () {}
	)
}

// ADD/DELETE FAV GAME
function AddFav(id, typ, site_url, unfav, fav) {
	AjaxPost(site_url+"/includes/view_game/ajax/add_fav.php", "id=" + id, 
			 function () {}
	)
	
	if (typ == 0) {
		document.getElementById('favbutton').innerHTML = '<a href="#" onclick="AddFav('+id+', 1, \''+site_url+'\', \''+unfav+'\', \''+fav+'\'); return false">'+unfav+'</a>';
	}
	else {
		document.getElementById('favbutton').innerHTML = '<a href="#" onclick="AddFav('+id+', 0, \''+site_url+'\', \''+unfav+'\', \''+fav+'\'); return false">'+fav+'</a>';
	}
}

// ADD HINTS

function AddHints(id, site_url) {
	document.getElementById('hints_submit').disabled=true;
	document.getElementById('hints_submit').value="Добавляю текст...";
	
	thehints = document.getElementById('the_hints').value; 
	
	AjaxPost(site_url+"/includes/view_game/ajax/add_hints.php", "hints="+thehints+"&id="+id, 
	function () {
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
 			if (xmlHttp.responseText == '') {
	 			alert("Ошибка при отправке текста!");
 			}
 			else {
  				alert("Спасибо! Ваш текст отправлен на проверку модератору.");
  				
  			}
		}
	}
	)
}

function AddComment(id, site_url) {
	document.getElementById('comment_submit').disabled=true;
	document.getElementById('comment_submit').value="Adding comment...";
	
	thecomment = document.getElementById('the_comment').value; 
	
	AjaxPost(site_url+"/includes/view_game/ajax/add_comment.php", "comment="+thecomment+"&id="+id, 
	function () {
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
 			if (xmlHttp.responseText == '') {
	 			alert("An error occured in sending your message");
 			}
 			else {
  				var container = document.getElementById('comment_list');
  				var new_element = document.createElement('li');
  				new_element.innerHTML = xmlHttp.responseText;
  				container.insertBefore(new_element, container.firstChild);
  				window.location.hash="1"; 
  				document.getElementById('comment_submit').value="Comment added!";
  				setTimeout("EnableButton()",30000);
  			}
		}
	}
	)
}

function EnableHintsButton () {
	document.getElementById('hints_submit').value="Add hints";
	document.getElementById('hints_submit').disabled=false;
}

function EnableButton () {
	document.getElementById('comment_submit').value="Add comment";
	document.getElementById('comment_submit').disabled=false;
}

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}
    
function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

function DeleteComment(id, site_url) {
	AjaxPost(site_url+"/admin/includes/delete_comment.php", "id=" + id, 
			 function () {
					document.getElementById('comment-' + id).style.display = 'none';
    		}
	)
}

function serverQuery( callback_function, url, responseType )
	{
		var XMLHttpRequestObject = false;
		

	    if( window.XMLHttpRequest )
	    {
			XMLHttpRequestObject = new XMLHttpRequest || window.ActiveXObject && function() { return new ActiveXObject('Msxml2.XMLHTTP'); };
		}
		else if( window.ActiveXObject )
		{
			XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if( XMLHttpRequestObject )
	    {
			XMLHttpRequestObject.open( "GET", url );
			XMLHttpRequestObject.onreadystatechange = function()
			{
				if ( XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200 )
		    	{

					if ( '' != callback_function )
					{
						if ( 'xml' == responseType )
							answer = XMLHttpRequestObject.responseXML;
						else
							answer = XMLHttpRequestObject.responseText;

						callback_function(answer);
					}

					delete XMLHttpRequestObject;
					XMLHttpRequestObject = null;

				}
		    }
			XMLHttpRequestObject.send( null );
		}

		return true;
	}

	function pollVariantList( variant )
	    	{

				var ID = variant.getElementsByTagName('id')[0].firstChild.data;
				
// make question -------------------
	    		var aQuestion = variant.getElementsByTagName('question');

	    		var container = document.getElementById('dpol_caption_' + ID );

				var newDiv = document.createElement("div");
				newDiv.id = "dpol_caption_text_" + ID;
				newDiv.className = "pollTextBox";
				newDiv.onmouseover = function() { scrollStart(this,'horizontal'); };
				newDiv.onmouseout = function() { scrollStop(); };

				var newText = document.createTextNode(aQuestion[0].firstChild.data);

				newDiv.appendChild( newText );
				container.appendChild( newDiv );
// -----------------------------------------
// make variant lists ----------------------
	    		var aVariantList = variant.getElementsByTagName('variant');

	    		container = document.getElementById('dpol_content_' + ID );

				var newInput = document.createElement("input");
				newInput.type = "hidden";
				newInput.id = "current_vote_" + ID;
				newInput.value = '';

				container.appendChild( newInput );

	    		for ( var i = 0; i < aVariantList.length; i++ )
	    		{

				    sText = aVariantList[i].getElementsByTagName('text')[0].firstChild.data;
				    newText = document.createTextNode(sText);

				    newDiv = document.createElement("div");
				    newDiv.id = 'var_' + ID + '_' + i;
				    newDiv.className = "pollTextBox";
				    newDiv.onmouseover = function(){ scrollStart(this,'horizontal'); };
				    newDiv.onmouseout = function(){ scrollStop(); };
				    newDiv.appendChild( newText );

				    var newDiv2 = document.createElement("div");
					newDiv2.className = "pollTextBoxWrapper";
				    newDiv2.appendChild( newDiv );


				    var newDiv3 = document.createElement("div");
				    newDiv3.className = "pollTextContainer";

				    newInput = createNamedElement( "input", "vote_" + ID );
				    newInput.type = "radio";
				    newInput.value = i;
				    newInput.className = "pollRadioButton";
				    newInput.onclick = function(){ setVote( 'current_vote_' + ID, this.value ); };

				    newDiv3.appendChild( newInput );
				    newDiv3.appendChild( newDiv2 );

				    container.appendChild( newDiv3 );

				}
				scrollDisplay(container, ID);

				return true;

	    	}


	    	function pollResultList( variant, cVote )
	    	{

				var ID = variant.getElementsByTagName('id')[0].firstChild.data;

// hide actions block --------------
				document.getElementById('dpol_actions_' + ID ).style.display = 'none';
				
// -------------------------------------				
// make question -------------------
				if ( null === document.getElementById('dpol_caption_text_' + ID) )
				{
		    		var aQuestion = variant.getElementsByTagName('question');

		    		var container = document.getElementById('dpol_caption_' + ID );

					var newDiv = document.createElement("div");
					newDiv.id = "dpol_caption_text_" + ID;
					newDiv.className = "pollTextBox";
					newDiv.onmouseover = function() { scrollStart(this,'horizontal'); };
					newDiv.onmouseout = function() { scrollStop(); };

					var newText = document.createTextNode(aQuestion[0].firstChild.data);

					newDiv.appendChild( newText );
					container.appendChild( newDiv );
				}
// -------------------------------------
// make result list

	    		var aVariantList = variant.getElementsByTagName('variant');

				// get total votes num
				var iTotalVotes = 0;
				var aVoteList = new Array();
				for ( var i = 0; i < aVariantList.length; i++ )
    			{
    			 	// if vote set
    				if ( '' != cVote && i == cVote )
    				{
						aVariantList[i].getElementsByTagName('votes')[0].firstChild.data++;
					}

					aVoteList[i] = aVariantList[i].getElementsByTagName('votes')[0].firstChild.data;
					iTotalVotes += (+aVoteList[i]);
				}

				// generate percent values
				var aPercentList = new Array();
				for ( var i = 0; i < aVoteList.length; i++ )
    			{
    				if ( 0 == iTotalVotes )
    					aPercentList[i] = 0;
    				else
						aPercentList[i] = Math.round((aVoteList[i]/iTotalVotes*100)*10)/10;
    			}


				container = document.getElementById('dpol_content_' + ID );
				container.innerHTML = '';

				for ( var i = 0; i < aVariantList.length; i++ )
	    		{

					sText = aVariantList[i].getElementsByTagName('text')[0].firstChild.data;


					var newText = document.createTextNode(sText + ' (' + aVoteList[i] + '): ');

					var newDiv = document.createElement("div");
					newDiv.className = "pollTextBox";

					newDiv.id = 'r_' + ID + "_" + i;
					newDiv.onmouseover = function(){ scrollStart(this,'horizontal'); };
					newDiv.onmouseout = function(){ scrollStop(); };
					newDiv.appendChild(newText);

					var newDiv2 = document.createElement("div");
					newDiv2.className = "pollTextBoxWrapperRes";
					newDiv2.appendChild(newDiv);

					var newDiv3 = document.createElement("div");
					newDiv3.className = "pollTextContainerRes";
					newDiv3.appendChild(newDiv2);

					var newDiv4 = document.createElement("div");
					newDiv4.id='p_' + ID + '_' + i;
					newDiv4.className = "pollProgressBar";

					newText = document.createTextNode('0');
//					newText = document.createTextNode(aPercentList[i] + '%');
					newDiv4.appendChild( newText );
					
					container.appendChild( newDiv3 );
					container.appendChild( newDiv4 );

					drawBar(newDiv4.id,aPercentList[i]);

	    		}

				scrollDisplay(container, ID);

	    		return true;
	    	}
// =========================================================================
// Utils====================================================================
// =========================================================================

		// create element with name ( this is problem with IE )
			function createNamedElement( type, name )
			{
				var element;
				try
				{
					element = document.createElement('<'+type+' name="'+name+'">');
				}catch(e){}
				if (!element || !element.name) // Cool, this is not IE !!
				{
					element = document.createElement(type)
					element.name = name;
				}
				return element;
			}


		    function scrollDisplay(container, ID)
		    {
				// jump to top position
				container.style.top = '0px';

				if ( ( container.offsetTop + container.offsetHeight ) <= container.parentNode.offsetHeight )
				{
				    document.getElementById( 'dpol_arr_up_' + ID ).style.display='none';
				    document.getElementById( 'dpol_arr_down_' + ID ).style.display='none';
				}
				else
				{
				    document.getElementById( 'dpol_arr_up_' + ID ).style.display='block';
				    document.getElementById( 'dpol_arr_down_' + ID ).style.display='block';
				}

				return true;
	    	}


    		function scrollStart( item, direction )
    		{

				currentItem = item;

				if ( 'horizontal' == direction )
				{

					if ( currentItem.offsetWidth <= currentItem.parentNode.offsetWidth)
						return false;

					if ( 1 != aPollDoubleItem[currentItem.id] )
					{
						currentItem.innerHTML = currentItem.innerHTML + "  " +  currentItem.innerHTML;
						aPollDoubleItem[currentItem.id] = 1;
				    }

					currentMiddle = currentItem.offsetWidth / 2;
		    		scrollStop();
		    		iter = window.setInterval( 'moveLeft()', 10 );
				}


				if ( 'up' == direction )
				{
				    scrollStop();
				    iter = window.setInterval( 'moveUp()', 10 );
				}


				if ( 'down' == direction )
				{
				    scrollStop();
				    iter = window.setInterval( 'moveDown()', 10 );
				}

				return true;

    		}


    		function scrollStop()
    		{
				if ( undefined != window.iter )
				{
	    			window.clearInterval(iter);
				}
    		}


    		function moveLeft()
    		{
				if (currentItem.offsetLeft + currentMiddle > 0)
				{
	    			currentItem.style.left = (currentItem.offsetLeft-1) + 'px';
				}
				else
				{
	    			currentItem.style.left = '0px';
				}
		    }


		    function moveUp()
    		{
				if ( (currentItem.offsetTop + currentItem.offsetHeight) > currentItem.parentNode.offsetHeight )
				{
	    			currentItem.style.top = (currentItem.offsetTop-2) + 'px';
				}
		    }


    		function moveDown()
    		{
				if ( currentItem.offsetTop < 0 )
				{
	    			currentItem.style.top = (currentItem.offsetTop+2) + 'px';
				}
			}


		    function setVote( item, val )
			{
    			document.getElementById( item ).value = val;
			}


// This function devoted to all spamers that make me feel not so along in this world
			function drawBar( item, size )
	        {
				var bar = document.getElementById(item);
			    var widthLim = Math.floor( size * (bar.parentNode.offsetWidth / 100) );

				if ( widthLim > bar.offsetWidth )
			    {

					bar.style.width = bar.offsetWidth + 2 + 'px';
// for correct final percent value,  offsetWidth mast be equal to widthLim
					if ( widthLim < bar.offsetWidth )
						bar.style.width = widthLim + 'px';

					var percentStep = Math.round(((size*bar.offsetWidth)/widthLim)*100)/100;
					bar.innerHTML = percentStep;

					setTimeout("drawBar('"+item+"',"+size+")", 50 );
				}
				else
				{
					//bar.innerHTML += '%';
					bar.innerHTML = size + '%';					
				}
		    }
			

		function googleTranslateElementInit() {
		new google.translate.TranslateElement({
		pageLanguage: 'ru',
		includedLanguages: 'en,de,fr'
			}, 'google_translate_element');
		}
		
		
function vk_login() {
    VK.Auth.login(vk_handler);
    return false;
}

function vk_handler(response) {
    if (response.session) {
		var start = document.cookie.indexOf('vk_app_'+VK._apiId);
		var end = document.cookie.indexOf(';', start);
		var vk_cookie = (end == -1)?document.cookie.substring(start):document.cookie.substring(start, end);
		start = vk_cookie.indexOf('mid') + 4;
		end = vk_cookie.indexOf('&', start);
		var mid = vk_cookie.substring(start, end);
		VK.Api.call('getProfiles', {uids: mid,fields:'uid,photo_medium,nickname,city'}, function(r) {
			if(r.response) {
				VK.Api.call('getCities', {cids: r.response[0].city}, function(r2) {
					if(r2.response) {
					window.location = 'http://igrodom.com/register_vk.php?done=1&vk_uid='+r.response[0].uid+'&vk_nickname='+r.response[0].nickname+'&vk_city='+r2.response[0].name+'&vk_username='+r.response[0].last_name + ' ' + r.response[0].first_name+'&vk_photo='+r.response[0].photo_medium;						
					//VK.Api.call('activity.set', {text:'Playing at Igrodom.com'}, function(r3) {});
					}
					else {
					window.location = 'http://igrodom.com/register_vk.php?done=1&vk_uid='+r.response[0].uid+'&vk_nickname='+r.response[0].nickname+'&vk_username='+r.response[0].last_name + ' ' + r.response[0].first_name+'&vk_photo='+r.response[0].photo_medium;							
					//VK.Api.call('activity.set', {text:'Playing at Igrodom.com'}, function(r3) {});
					}
				});

				
			}
		});
    }
}

 function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }

function slider () {
	
jQuery(document).ready(function(){
		$('#featured').tabs({fx:{opacity: 'toggle'}}).tabs('rotate', 5000, true);
	});
}


