	var question_flag = 0;
	var points_array = new Array(); // holds all ages or all ratings corresponding to the game type
	var guessed_array = new Array(); // holds the guessed ages or ratings
	var current_point = 0; // holds the correct answer of the current question
	var guessed_point = 0; // holds the guessed answer of the vurrent question
	var total_points = 100;
	var current_points = 0; // holds the current points ammount
	var points_per_click = 10; //How many points are added per correct answer
	var can_click = true; // bool - Holds if the pictures can be clicked (disabled when setTimeOut is running)
	var last_guessed; //bool - Holds if the last guess was successfuul or not
	var game_type; // 'rating' or 'age'
	
	Array.prototype.find = function (s)
		{
			for(var i=0;i<this.length;i++)
				if (this[i] == s) return true;
				
			return false;
		};

	/*function openLogin() {
	
		document.getElementById("member_login").style.display = "block";
	}
	function closeLogin() {
	
		document.getElementById("member_login").style.display = "none";
	}
	*/
  
	function sortNumber(a, b) {
	
		return a - b
	}
	
	function reverseFlag() {
	
		question_flag = !question_flag;
	}
	
	function startPlay() {
    
		game_type = document.getElementById("game_type").getAttribute("value");
		var pics_count = document.getElementById("pics_count").getAttribute("value");
		if (pics_count) {
			for (i = 1; i <= pics_count; i++) {
			
				an_item = document.getElementById("pic_" + i + "_" + game_type).getAttribute("value");	
				//ages.push(age);
         points_array[points_array.length] = an_item;
			}
			points_array.sort((sortNumber));	
			document.getElementById("score_points").innerHTML = current_points;
			ask();	
		}
	}
	
	function ask() {
	
		if (question_flag) {
		
			if (game_type == 'age') {
			
			    if (points_array.length > 1) {
                    
				    question = 'Wyznacz osobę młodszą niż ' + points_array[1]; 
                } else {
                    
                    question = 'Teraz wyznacz ostatnią osobę jeśli potrafisz ją znaleźć !!!';        
                }
			} else {
			
				question = 'Wyznacz osobę o ocenie niższej niż ' + points_array[1];
			}
			current_point = points_array[0];
		} else {
		
			if (game_type == 'age') {
			
			    if (points_array.length > 1) {
                    
				    question = 'Wyznacz osobę starszą niż ' + points_array[points_array.length - 2];
                } else {
                    question = 'Teraz wyznacz ostatnią osobę jeśli potrafisz ją znaleźć !!!';    
                }
			} else {
			
				question = 'Wyznacz osobę o ocenie wyższej niż ' + points_array[points_array.length - 2];
			}
			current_point = points_array[points_array.length - 1];
		}
		
		document.getElementById("puzzle_text").innerHTML = question;
	}
	
	function myCallback(returnstring) {

			can_click = true;
  } 
	
	function changePic(num) {

		can_click = false;
		el = document.getElementById("pic_" + num + "_text");
		hidePic(el);
		guessed_point = document.getElementById("pic_" + num + "_" + game_type).getAttribute("value");
		answer = (guessed_point == current_point);
		if (answer) {
		
			ans_type = 'Dobrze';
			if (question_flag) {
			
				guessed_array.push(points_array.shift()); 	
			} else {
			
				guessed_array.push(points_array.pop()); 
			}
      el.style.backgroundColor = "#FFC91B";
      el.style.color = "000";
			if (game_type == 'age') {
			
				document.getElementById("puzzle_text").innerHTML = 'Tak! Ta osoba ma ' +  guessed_point + 'lat';
			} else {
			
				document.getElementById("puzzle_text").innerHTML = 'Tak! Ta osoba ma ocenę ' +  guessed_point;
			}
      
			current_points += points_per_click; 
			document.getElementById("score_points").innerHTML = current_points;

      
			last_guessed = true;
      
			 if ('function' == typeof window.jsrsExecute) {
			 
			 	 can_click = false;
				 jsrsExecute("savescore.php", myCallback, "test", Array(String(points_per_click),"ok"));
			 } 
			 
		} else {
			
			ans_type = 'Źle';	
			if (points_per_click != 1) {
				points_per_click--;	
			}
      el.style.backgroundColor = "red";
      el.style.color = "white";
			if (game_type == 'age') {
		
				document.getElementById("puzzle_text").innerHTML = 'Ta osoba ma ' +  guessed_point + 'lat';
			} else {
			
				document.getElementById("puzzle_text").innerHTML = 'Ta osoba ma ocenę ' +  guessed_point;
			}
			last_guessed = false;
		}

		el.innerHTML = "<br /><br /><strong style=\"font: bold 14px Tahoma, sans-serif;\">" + ans_type + "!</strong><br />Następna dobra odpowiedź <strong style=\"font: normal 18px Tahoma, sans-serif;\">" + points_per_click + "pts.</strong>"; //ans_type + "<br />You have" + points_per_click + " points per click";
    if(document.getElementById("uname_" + num))
      el.innerHTML = "<br /><br /><strong style=\"font: bold 14px Tahoma, sans-serif;\">" + ans_type + "!</strong><br />Następna dobra odpowiedź <strong style=\"font: normal 18px Tahoma, sans-serif;\">" + points_per_click + "pts.</strong><p style=\"text-align: right; padding-right: 5px;\"><br /><strong style=\"font: bold 12px Tahoma, sans-serif; \" onclick=\"location.href='./" + document.getElementById("uname_" + num).innerHTML + "';\">-&gt; profil</a></p>";

    reverseFlag();
		setTimeout("showPic('"+num+"')",3000,"JavaScript")
	}
	
	function guessed(num) {
	
		temp_point = document.getElementById("pic_" + num + "_" + game_type).getAttribute("value");
		if (guessed_array.find(temp_point)) {
		
			alert('Już masz punkty za to pole!');
      //window.open('http://www.phppod.com','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
			return true;
		};	

		return false;
	}
	
	function tryClick(num) {
	
		if (can_click) {
			
			if (!guessed(num)) {

				changePic(num);
				return true;
			}
		} 
		
		return false;
	}
	
	function hidePic(el) {
	
		el.style.backgroundColor = "#FAA41C";
		el.style.display = "block";	
	}
	
	function createAdsContainer()
	{
			var a_tag = cssQuery("a[href *= 'ad.adtegrity.net']");
			var img_tag = cssQuery("img", a_tag);
			eAnchor = document.createElement("a");
			eAnchor.setAttribute("target", "_blank");
			eAnchor.setAttribute("href", a_tag);
			eAnchor.appendChild(img_tag[0]);	
			document.getElementById("ads_container").appendChild(eAnchor);	

	}
		
	function showPic(num) {
	
		var el = document.getElementById("pic_" + num + "_text");
		var el_cont = document.getElementById("pic_" + num);
		if (last_guessed) {
		
			el.style.backgroundColor = "#FFC91B";
			//el.innerHTML = "<br /><br /><strong style=\"font: normal 12px Tahoma, sans-serif;color: #000;\">Sponsored By phppod.com - custom scripts, articles, tutorials</strong>"
			//popUpProperties(el_cont);
			
			//el_cont.innerHTML = document.getElementById("ads_container").innerHTML;-->
			<!-- var ads = getElementByIdCompatible("ads_container").cloneNode(true);-->
			//ahref = ads.getElementsByTagName("a");
			<!-- el_cont.innerHTML = ''; -->
			<!-- el_cont.innerHtml.style.visibility = "hidden";-->
			<!-- el_cont.appendChild(ads.childNodes[0]); -->
			
		} else {
			el.style.display = "none";	
		}
		can_click = true;
		ask();
	}
	
    function f_open_window_max( aURL, aWinName )
    {
       var wOpen;
       var sOptions;

       sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
       sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
       sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
       sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

       wOpen = window.open( '', aWinName, sOptions );
       wOpen.location = aURL;
       wOpen.focus();
       wOpen.moveTo( 0, 0 );
       wOpen.resizeTo( screen.availWidth, screen.availHeight );
       return wOpen;
    }
