var Drag={obj:null,intersect:0,response:0,init:function(D,H,F,B,E,A,I,G,J,C){D.onmousedown=Drag.start;D.hmode=I?false:true;D.vmode=G?false:true;D.root=H&&H!=null?H:D;if(D.hmode&&isNaN(parseInt(D.root.style.left))){D.root.style.left="0px"}if(D.vmode&&isNaN(parseInt(D.root.style.top))){D.root.style.top="0px"}if(!D.hmode&&isNaN(parseInt(D.root.style.right))){D.root.style.right="0px"}if(!D.vmode&&isNaN(parseInt(D.root.style.bottom))){D.root.style.bottom="0px"}D.minX=typeof F!="undefined"?F:null;D.minY=typeof E!="undefined"?E:null;D.maxX=typeof B!="undefined"?B:null;D.maxY=typeof A!="undefined"?A:null;D.xMapper=J?J:null;D.yMapper=C?C:null;D.root.onDragStart=new Function();D.root.onDragEnd=new Function();D.root.onDrag=new Function()},start:function(B){var C=Drag.obj=this;C.style.zIndex=++zzIndex;C.root.style.top=C.root.offsetTop+"px";C.root.style.left=C.root.offsetLeft+"px";C.root.style.position="absolute";B=Drag.fixE(B);var D=parseInt(C.vmode?C.root.style.top:C.root.style.bottom);var A=parseInt(C.hmode?C.root.style.left:C.root.style.right);C.root.onDragStart(A,D);C.lastMouseX=B.clientX;C.lastMouseY=B.clientY;if(C.hmode){if(C.minX!=null){C.minMouseX=B.clientX-A+C.minX}if(C.maxX!=null){C.maxMouseX=C.minMouseX+C.maxX-C.minX}}else{if(C.minX!=null){C.maxMouseX=-C.minX+B.clientX+A}if(C.maxX!=null){C.minMouseX=-C.maxX+B.clientX+A}}if(C.vmode){if(C.minY!=null){C.minMouseY=B.clientY-D+C.minY}if(C.maxY!=null){C.maxMouseY=C.minMouseY+C.maxY-C.minY}}else{if(C.minY!=null){C.maxMouseY=-C.minY+B.clientY+D}if(C.maxY!=null){C.minMouseY=-C.maxY+B.clientY+D}}initX=C.root.offsetLeft;initY=C.root.offsetTop;document.onmousemove=Drag.drag;document.onmouseup=Drag.end;return false},drag:function(E){var D;E=Drag.fixE(E);var F=Drag.obj;var B=E.clientY;var C=E.clientX;var G=parseInt(F.vmode?F.root.style.top:F.root.style.bottom);var A=parseInt(F.hmode?F.root.style.left:F.root.style.right);if(F.minX!=null){C=F.hmode?Math.max(C,F.minMouseX):Math.min(C,F.maxMouseX)}if(F.maxX!=null){C=F.hmode?Math.min(C,F.maxMouseX):Math.max(C,F.minMouseX)}if(F.minY!=null){B=F.vmode?Math.max(B,F.minMouseY):Math.min(B,F.maxMouseY)}if(F.maxY!=null){B=F.vmode?Math.min(B,F.maxMouseY):Math.max(B,F.minMouseY)}nx=A+((C-F.lastMouseX)*(F.hmode?1:-1));ny=G+((B-F.lastMouseY)*(F.vmode?1:-1));if(F.xMapper){nx=F.xMapper(G)}else{if(F.yMapper){ny=F.yMapper(A)}}Drag.obj.root.style[F.hmode?"left":"right"]=nx+"px";Drag.obj.root.style[F.vmode?"top":"bottom"]=ny+"px";Drag.obj.lastMouseX=C;Drag.obj.lastMouseY=B;document.onmouseup=Drag.end;return false},end:function(){var C=Drag.obj;var D;var H;var B;eleman:for(var G=0;G<roots.length;G++){if(C!=roots[G]){var E=new intersection(C,roots[G]);if((E.Top||E.Bottom)&&(E.Left||E.Right)){D=C.id.split("_");H=roots[G].id.split("_");ansID=""+(D[1]-1)+"*"+(H[1]-1);var I=G;if(ready==1){ready=0;var A;new Ajax.Request("/tools/gamesAjaxCheck.php",{method:"post",parameters:{cardsAjaxAnswer:ansID},onSuccess:function(K){response=K.responseText;A=response.split("#");if(A[0]!="1"){pointPopUp(roots[I]);$("spanPoint").style.fontSize="130%";$("spanPoint").innerHTML=A[1]+" ";$("triesCount").innerHTML=A[2]+" ";if(soundStatus==1){try{audioDo("play","testSound1")}catch(J){}}if(A[3]=="submit"){wrongAnswer(C,roots[I],1)}else{wrongAnswer(C,roots[I])}}else{$("spanPoint").style.fontSize="130%";$("spanPoint").innerHTML=A[1]+" ";pointPopUp(roots[I],1);if(soundStatus==1){try{audioDo("play","testSound2")}catch(J){}}if(A[2]=="submit"){$("showWordButton").style.display="none";rightAnswer(C,roots[I],1)}else{rightAnswer(C,roots[I])}}},onFailure:function(){alert("Something went wrong...");ready=1}})}document.onmousemove=null;document.onmouseup=null;break eleman}}}document.onmousemove=null;document.onmouseup=null;Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode?"left":"right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode?"top":"bottom"]));Drag.obj=null;for(var F=0;F<roots.length;F++){roots[F].style.position="relative";roots[F].style.top="0px";roots[F].style.left="0px"}reactivate()},fixE:function(A){if(typeof A=="undefined"){A=window.event}if(typeof A.layerX=="undefined"){A.layerX=A.offsetX}if(typeof A.layerY=="undefined"){A.layerY=A.offsetY}return A}};function intersection(H,G){var J;var I;var B;var A;var F=new Array(4);var C=new Array(4);this.Left=false;this.Right=false;this.Top=false;this.Bottom=false;this.Limit=false;var E=navigator.appName;if((E=="Microsoft Internet Explorer")){ieMarginX=0;ieMarginY=0;J=((H.offsetLeft+(H.offsetWidth/2)));I=((H.offsetTop)+(H.offsetHeight/2));B=((G.offsetLeft+(G.offsetWidth/2))+ieMarginX);A=((G.offsetTop+ieMarginY)+(G.offsetHeight/2));F[0]=(H.offsetLeft);F[2]=H.offsetLeft+H.offsetWidth;F[1]=(H.offsetTop);F[3]=(F[1]+H.offsetHeight);C[0]=(G.offsetLeft+ieMarginX);window.status="sonuc   "+C[0];C[2]=(G.offsetLeft+G.offsetWidth+ieMarginX);C[1]=((G.offsetTop+ieMarginY));C[3]=(C[1]+G.offsetHeight)}else{J=(H.offsetLeft+(H.offsetWidth/2));I=(H.offsetTop+(H.offsetHeight/2));B=(G.offsetLeft+(G.offsetWidth/2));A=(G.offsetTop+(G.offsetHeight/2));F[0]=H.offsetLeft;F[1]=H.offsetTop;F[2]=H.offsetLeft+H.offsetWidth;F[3]=H.offsetTop+H.offsetHeight;C[0]=G.offsetLeft;C[1]=G.offsetTop;C[2]=G.offsetLeft+G.offsetWidth;C[3]=G.offsetTop+G.offsetHeight}var D=-2;if((B>F[0])&&(F[0]>(C[0]+D))){this.Left=true}if((F[2]>B)&&(F[2]<C[2])){this.Right=true}if(((F[3]<C[3])&&(F[3]>A))||((F[1]<C[3])&&(F[1]>A))){this.Bottom=true}if((F[1]>C[1])&&(F[1]<A)){this.Top=true}if(F[1]<C[1]){}this.Limit=true}function wrongAnswer(G,D,A){var F=G.id.split("_");var E=F[1];var C=D.id.split("_");var B=C[1];G=$("cardLight_"+E);D=$("cardLight_"+B);G.style.backgroundColor="FF002A";D.style.backgroundColor="FF002A";G.style.visibility="visible";D.style.visibility="visible";fadeIn(G.id,99,3);fadeIn(D.id,99,3);if(A==1){$("showWordButton").style.visible="hidden";setTimeout("$('cardsGameValue').value = \"mali\";$('cardsSoundValue').value = soundStatus;$('cardsGameForm').submit();",1000)}}function rightAnswer(F,D,E){var B=F.id.split("_");var I=B[1];var A=D.id.split("_");var H=A[1];ttObj1=$("cardLight_"+I);ttObj2=$("cardLight_"+H);ttObj1.style.backgroundColor="2AFF2A";ttObj2.style.backgroundColor="2AFF2A";ttObj1.style.visibility="visible";ttObj2.style.visibility="visible";var C=100;var G=navigator.appName;if(G=="Microsoft Internet Explorer"){ttObj1.style.filter="alpha(opacity="+C+")";ttObj2.style.filter="alpha(opacity="+C+")"}else{ttObj1.style.MozOpacity=C/100;ttObj2.style.MozOpacity=C/100}fadeIn(F.id,99,3,1);fadeIn(D.id,99,3,1);if(E==1){setTimeout("$('cardsGameValue').value = \"mali\";$('cardsSoundValue').value = soundStatus;$('cardsGameForm').submit();",2000)}}function fadeIn(B,E,D,A){if(E>=0&&E<100){E=E-D;var C=navigator.appName;if(C=="Microsoft Internet Explorer"){$(B).style.filter="alpha(opacity="+E+")"}else{$(B).style.MozOpacity=E/100}setTimeout("fadeIn('"+B+"',"+E+","+D+","+A+")",26)}else{ready=1;if(A==1){$(B).parentNode.removeChild($(B))}else{$(B).style.visibility="hidden"}}}function pointPopUp(C,B){if(B==1){var A=$("pointPopUpPlus");setTimeout("$('pointPopUpPlus').style.visibility = \"hidden\";",2000)}else{var A=$("pointPopUpMinus");setTimeout("$('pointPopUpMinus').style.visibility = \"hidden\";",2000)}A.style.left=(C.offsetLeft+35)+"px";A.style.top=(C.offsetTop+15)+"px";A.style.visibility="visible";A.style.zIndex=zzIndex*10}function showValue(){if(0<value){value--;var D=document.getElementById("showClock");var B=parseInt(value/60);if(B==0){factor=1}else{factor=B}var C=value%(factor*60);if(C<10){D.innerHTML=B+":0"+C}else{D.innerHTML=B+":"+C}if(value<10&&(soundStatus==1)){var A=document.embeds[2];A.Play()}return(value-1)}else{window.clearInterval(setClock);$("cardsSoundValue").value=soundStatus;$("cardsGameValue").value="time";$("cardsGameForm").submit()}}function stopClock(A){clearInterval(A)}function startClock(){setClock=setInterval("showValue()",1000)}function instructions(link){window.open(link,"babla_instructions","width=400, height=400, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, toolbar=no")}function creatediv(G,B,C,A,F,E){var D=document.createElement("div");D.setAttribute("id",G);if(C){D.style.width=300}if(A){D.style.height=300}if((F||E)||(F&&E)){D.style.position="absolute";if(F){D.style.left=F}if(E){D.style.top=E}}D.style.backgroundImage=url(URL)|none;if(B){D.innerHTML=B}else{D.innerHTML="nothing"}document.body.appendChild(D)}function audioDo(A,C){if(C=="testSound1"){var B=document.embeds[0]}else{if(C=="testSound2"){var B=document.embeds[1]}}if(B!=null){if(A=="stop"){B.stop()}else{B.Stop();B.Play()}}}function soundOnOff(){if(soundStatus==1){soundStatus=0;$("soundDiv").src="img/sound_off.png"}else{if(soundStatus==0){soundStatus=1;$("soundDiv").src="img/sound_on.png"}}new Ajax.Request("/tools/gamesAjaxCheck.php",{method:"post",parameters:{cardsSoundSetting:soundStatus},onSuccess:function(A){},onFailure:function(){alert("Something went wrong...")}})};
