$(document).ready(function () {
  $('.gameOver').mouseover(function (e) {
    var game=$(this).attr('id');
    var wHeight=$(window).height();
    var adjY=20;
    var adjX=$('#'+game+'Detail').width()/2;
    if (e.screenY>wHeight/2)
      adjY=-$('#'+game+'Detail').height()-20;
    $('#'+game+'Detail').css({'display':'block', 'top' : (e.pageY+adjY)+'px', 'left': (e.pageX-adjX)+'px'});
  }
  );
  
  $('.gameOver').mouseout(function (e) {
    var game=$(this).attr('id');
    $('#'+game+'Detail').css('display','none');
  }
  );
  
  $('.title').each(function () {
    var txt=$(this).html();
    $(this).html("<embed width=\""+$(this).width()+"\" height=\""+$(this).height()+"\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" src=\"/themes/blue/images/avalon.swf\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" flashvars=\"css=*%20%7B%20color%3A%20%23122d44%3B%20%7D&amp;txt="+escape(txt)+"\"/>");
  }
  );

  $('.changeNames').each(function () {
    $(this).html($('#cName'+$(this).attr('cName')).html());
  }
  );

  }
  
);

function engelle(e){if (typeof (e.preventDefault)!='undefined') {e.preventDefault();} else e.returnValue=false;}
function rate(p,i)
{
  url="/js/rate.html";
  data='i='+i+'&p='+p+'&r='+Math.random();;
  callback=parseRate;
  jQuery.get(url,data,callback);
}

var cR,cV;

function star(x)
{
cR=idBul('score').innerHTML;
cV=idBul('votes').innerHTML;
idBul('score').innerHTML=x;
idBul('votes').innerHTML='';
}

function resetstar()
{
idBul('score').innerHTML=cR;
idBul('votes').innerHTML=cV;
}

function parseRate(xmlObj)
{
  root=xmlObj.documentElement;
  child=root.firstChild;
  var score=child.getAttribute('score');
  var votes=child.getAttribute('votes');
    html="<b>Your rating has been saved!</b>";
    html+='<ul class="star-rating">';
    html+='<li class="current-rating" id="current-rating" style="width: '+score*25+'px"></li>';
    html+='</ul>';
    idBul('rating').innerHTML=html;
    idBul('score').innerHTML=score;
    idBul('votes').innerHTML=votes+' votes';
    html='Rated <b>'+score+'</b> out of 10 based on <b>'+votes+'</b> votes';
    html+='<br>Thank you for rating this game!';
    idBul('rating_text').innerHTML=html;   
}

function idBul(eid)
{
    try{return document.getElementById(eid)}catch(e){};
}

function goster(id)
{
	idBul(id).style.display="block";
}

function gizle(id)
{
	idBul(id).style.display="none";
}

function tabClick(t,q)
{
  for (var i=1;i<=q;i++)
  {
  gizle('tab_'+i);
  idBul('tabbutton'+i).className='inactivetab';
  }
  goster('tab_'+t);
  idBul('tabbutton'+t).className='activetab';
}

function hintGoster(id,obj)
{
  var x=(document.body.clientWidth-980)/2;
  if (x<0) x=0;
  x+=obj.offsetLeft+320;
  idBul(id).className='field-hint';
  idBul(id).style.left=x+'px';
}

function sendComment(i)
{
  if (idBul(i+"name").value.length<2)
  {
    idBul(i+"commentAjaxMessage").innerHTML='<font color="red">Plese enter your name!</font>';
    return false;
  }
  else if (idBul(i+"comment").value.length<2)
  {
    idBul(i+"commentAjaxMessage").innerHTML='<font color="red">Plese write something to post!</font>';
    return false;
  }
  url='/js/comment.html';
  if (i==1)
  {
    data=$('#yorumformu').serialize()+"&r="+Math.random();
    callback=function(html) 
      {idBul('commentholder').innerHTML+=html;
      $('.loadingDiv').css("display","none");
      $('.commentForm').css("display","block");
      idBul('yorumformu').reset();  
      }
  }
  else if (i==2)
  {
    data=$('#hileformu').serialize()+"&r="+Math.random();
    callback=function(html) 
      {idBul('hileholder').innerHTML+=html;
      $('.loadingDiv').css("display","none");
      $('.commentForm').css("display","block");
      idBul('hileformu').reset();  
      }
  }
  else
  {
    data=$('#walkthroughformu').serialize()+"&r="+Math.random();
    callback=function(html) 
      {idBul('walkthroughholder').innerHTML+=html;
      $('.loadingDiv').css("display","none");
      $('.commentForm').css("display","block");
      idBul('walkthroughformu').reset();  
      }
  }

  jQuery.post(url,data,callback,"html");
  $('.loadingDiv').css("display","block");
  $('.commentForm').css("display","none");
}


function reply(r)
{
idBul("replyTo").value=r;
}

  var firstBox=1;
  var currentBox=1;
  var currentId=1;
  var totalBox=10;
  var first=1;
  var boxes=new Array(1,2,3,4);


	if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    }
	}

  function showBoxD(box)
  {
    moveSelectBox(box);
  }
  
  function showBox(box)
  {
    box=boxes.indexOf(box)+1;
    moveSelectBox(box);
  }
  
  function moveSelectBox(box)
  {
    var startTop=29;
    var moveTo=startTop+(box-1)*(57);
    currentBox=box;
    if (currentId!=boxes[box-1])
    {
      currentId=boxes[box-1];
      document.getElementById('ss-selected').style.top=moveTo+'px';
      $('#ss-img'+(boxes[box-1])).fadeIn(1500);
      for (i=1;i<=totalBox;i++)
      { if (i!=boxes[box-1])
          document.getElementById('ss-img'+i).style.display='none';
      }
    }
  }
  
  function randomXToY(minVal,maxVal,floatVal)
  {
    var randVal = minVal+(Math.random()*(maxVal-minVal));
    return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
  }
  
  function prev()
  {
  firstBox--;
  if (firstBox<=-totalBox)
    firstBox=totalBox;
    adjustBoxes();
  }
  
  function next()
  {
    firstBox++;
    if (firstBox>totalBox)
      firstBox=1;
    adjustBoxes();
  }
  
  function adjustBoxes()
  {
    var temp='';
    for (i=0;i<=3;i++)
    {
      if ((firstBox+i)%(totalBox)<0)
      {
        boxes[i]=totalBox+firstBox+i;
      }
      else
        boxes[i]=(firstBox+i)%(totalBox);
      if (boxes[i]==0)
        boxes[i]=totalBox;
    }
    
    for (i=1;i<=totalBox;i++)
    {
     document.getElementById('ss-dol'+i).style.top='300px';
    }

    for (i=0;i<=3;i++)
    {
      document.getElementById('ss-dol'+(boxes[i])).style.top=i*57+'px';
    }
    
    showBoxD(currentBox);
  }
