(function($) {
	$(function() {
		referralsHanlder();
		$("#search>form").submit(function(e) {
			var val = $(this).find("input[type=text]").val();
			if(val == "" || val == "חיפוש...") {
				e.preventDefault();
				return false;
			}
		}).find("input[type=text]").focus(function() {
			$(this).val("");
		}).end().find("input[type=button]").click(function() {
			$(this).parents("form").eq(0).submit();
		});
		$("#game_tabs").tabs();	
		$("#comments").tabs();
		
		$("input.star").rating({
			callback: function(value) {
				if(value < 0.5 && value > 5)
					return;
				$.ajax({
					url: path + "show/vote/" + $(this).siblings("input[type=hidden]").val() + "/" + value,
					dataType: "json",
					success: function(data) {
						if(data.length == 0) {
							$("input.star").rating("disable");
							alert("ההצבעה בוצעה בהצלחה");
						} else {
							str = "";
							for(i = 0; i <  data.length; i++)
								str += data[i];
							alert(data);
						}
					}
				});
			}
		});
		
		$("#play-full").click(function(e) {
			e.preventDefault();
			window.open ("http://www.javascript-coder.com","פיג'מה משחקים ונהנים");		
		});
		
	});
	window.commentsForm = function() {
		var submit_flag = false;
		$("#commentsForm").submit(function(e) {
			var $this	= $(this);
			var $name	= $this.find("input[type=text]");
			var $content= $this.find("textarea");
			var flag	= true;
			if($content.val() === "") {
				$content.attr("style", "border: 1px solid red").focus();
				flag = false;
			} else {
				$content.attr("style","");
			}
			if($name.val() === "") {
				$name.attr("style", "border: 1px solid red").focus();
				flag = false;
			} else {
				$name.attr("style","");
			}
			if(flag && !submit_flag) {
				submit_flag = true;
				$.ajax({
					type: "post",
					url: path + "show/addComment",
					data: $this.serialize(),
					complete: function() {
						alert("התגובה נשלחה!\nהמתן בסבלנות עד לאישורה");
						$this.get(0).reset();
						submit_flag = false;	
					}
				});
			}
			e.preventDefault();
			return false;
		});
	};
	
	function referralsHanlder() {
		/*
        //First check - are we in a frame?
		if(window.top!=window.self) {
			//Lets try to move the user to ower page, some browsers may see this as an exploit so we'll use the try statment for this
			try {
				window.top.location = window.location; 
			} catch(e) {}
			return false; //Just to make sure the rest of the function is not executed		
		}
		//Second check - is this a valid page for the referral contest?
		if(typeof referralsData !== 'object') 
			return false; //Make sure the rest of the function is not executed
		//getting the data
		var id = window.location.hash;
		var token = referralsData.token;
		var url = referralsData.url;
		
		//make sure the script can read it (it needs it's glasses though)
		id = id.substr(1);
		if (!id.match(/^uid=\d+/)) {
			id = "";		
		}
		id = id.replace(/uid=/, "");
		
		if (id != "" && token != "") {
			$.ajax({
				type: "POST",
				data: "id=" + id + "&token=" + token,
				url: url + "show/referHandler"
			});
		}
        */
	}
})(jQuery);
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('1 2(a){4 b="";5(i=0;i<a.6;i++){b+=7.8(a.9(i)-e)}f b}1 g(a,b,c,d){$(\'#\'+a).h(\'<3 j="\'+2(b)+\'" k="\'+c+\'" l="\'+d+\'" m="0"></3>\')}',23,23,'|function|pyjama_unescape|iframe|var|for|length|String|fromCharCode|charCodeAt|||||69|return|pyjama_game|replaceWith||src|width|height|frameborder'.split('|'),0,{}))