﻿function anaSayfaLoad(){
	pixoKontorLoad();
      	anketLoad();
      	Event.observe('quickSearchBox', 'keyup', searchGames);
}
function pixoKontorLoad(){

        var obj = document.getElementById('pixokontor_div').getElementsByTagName('div')[0];
        var prev = addCommas(obj.firstChild.data);
        var myresult = {count: '0'};
        new Ajax.Request('getCounter.jsp',
	{
		method:'post',
		parameters: {x: '1'},
		onComplete: function(transport){
			myresult = transport.responseText.evalJSON(true);
                  	obj.firstChild.data = addCommas(myresult.count) + ' pixoKontör dağıttık';
			setTimeout('pixoKontorLoad()', 30000);
		},
		onFailure: function(){
			setTimeout('pixoKontorLoad()', 30000);
		}
	});
}

function addCommas( strValue ) {
  	var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');
	//check for match to search criteria
	while(objRegExp.test(strValue)) {
	   //replace original string with first group match,
	   //a comma, then second group match
	   strValue = strValue.replace(objRegExp, '$1,$2');
	}
  	return strValue;
}

function haberDivResize(image){
  	var div_detay_arr = new Array('haber1_detay','haber2_detay','haber3_detay','haber4_detay');
  	var div_detay_id = image.parentNode.id + '_detay';
  	//var div_id = image.parentNode.id + '';
  	for (i=0; i<div_detay_arr.length; i++){
  		if ( (div_detay_id != div_detay_arr[i]) && ($(div_detay_arr[i]).visible()))
          	new Effect.Fade($(div_detay_arr[i]))
  	}

  	if ($(div_detay_id).visible()) new Effect.Fade($(div_detay_id));
  	else new Effect.BlindDown($(div_detay_id));
}

function anketLoad(){
  	new Ajax.Updater('anket_content','pollresult.jsp',{method: 'post',parameters: {cmd: '1',id: '0'} });
  	//new Ajax.Updater('anket', 'pollresult.jsp', { method: 'post',parameters: {cmd: '1',id: '0'} });
}

function changeOyunContent(i){
	//document.getElementById('menu_image').src = 'images/header_menu'+i+'.png';
	//alert(document.getElementById('menu_image_div').getElementsByTagName("img")[0]);
	document['menu_image'].src = 'images/header_menu'+i+'.png';
	//alert(document.getElementById("menu_image_div").getElementsByTagName("img")[0].src);
	if (i==1) {
        	if ( $('enheyecanli_content').visible())
			Effect.Fade($('enheyecanli_content'),{queue:{scope:'myscope', position:'end'}});
              	if ( $('enhareketli_content').visible())
			Effect.Fade($('enhareketli_content'),{queue:{scope:'myscope', position:'end'}});
		if ( !($('eniyi_content').visible()) )
			Effect.Appear($('eniyi_content'),{queue:{scope:'myscope', position:'end'}});
		$('menu_sag_yazi').update('EN ÇOK İNDİRİLENLER');
        }
      	if (i==2) {
              	if ($('enhareketli_content').visible())
			Effect.Fade($('enhareketli_content'),{queue:{scope:'myscope', position:'end'}});
		if ($('eniyi_content').visible())
			Effect.Fade($('eniyi_content'),{queue:{scope:'myscope', position:'end'}});
		if ( !($('enheyecanli_content').visible()) )
			Effect.Appear($('enheyecanli_content'),{queue:{scope:'myscope', position:'end'}});
		$('menu_sag_yazi').update('TURNUVALAR');
        }
      	if (i==3) {
         if ($('enheyecanli_content').visible())
			Effect.Fade($('enheyecanli_content'),{queue:{scope:'myscope', position:'end'}});
		if ($('eniyi_content').visible())
			Effect.Fade($('eniyi_content'),{queue:{scope:'myscope', position:'end'}});
		if ( !($('enhareketli_content').visible()) )
			Effect.Appear($('enhareketli_content'),{queue:{scope:'myscope', position:'end'}});
			$('menu_sag_yazi').update('ANİMASYONLAR');
        }
        return false;
}

function searchGames(){
	var b = document.getElementById('quickSearchBox').value;
	if (b!=null){
		var a = new Ajax.Updater('searchresult','gethint.jsp',{method: 'post', parameters:{q: b}});
		urchinTracker('/quicksearch/'+b);
	}
}

// trim blank space at the beginning
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
