﻿
$(window).scroll(function () {
    if ($(this).scrollTop() > 333) {
        $('#yukariGit').fadeIn();
    } else {
        $('#yukariGit').fadeOut();
    }

});

function queryString() {
    var qs = location.search.substring(1, location.search.length).replace(/(%20|\+)/g, " ");
    if (arguments.length == 0 || qs == "") return qs; else qs = "&" + qs + "&";
    return qs.substring(qs.indexOf("=", qs.indexOf("&" + arguments[0] + "=") + 1) + 1, qs.indexOf("&", qs.indexOf("&" + arguments[0] + "=") + 1));
}


//--------------------------------------------- FAVORİ OYUN LİSTESİNE EKLE-------------------------
function addFavori(id) {
    $.colorbox({ opacity: "0.50", html: "Ekleniyor..." });

    if (id != null && id != "") {
        game = id.split('_')[1];
    }
    else
        game = queryString('id');  // play.aspx sayfasında
    $.post('veri_isle.aspx', '13,' + game, // 
      function (deger) {
          if (deger != "") {
              $.colorbox({ opacity: "0.50", html: deger });
              if (deger.match("zaten") == null) {
                  // var oldCount = parseInt($("#favoriCount").html());
                  //var newCount = parseInt(oldCount + 1);
                  // $("#favoriCount").html(newCount);
                  showFavoriesCount();
              }
          }
      });
}


//---------------------------------------------- contact formları için------------------------------
function setTips() {
    $('#TextName').poshytip({
        className: 'tip-darkgray',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        allowTipHover: false,
        offsetX: 5
    });
    $('#TextEmail').poshytip({
        className: 'tip-darkgray',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        allowTipHover: false,
        offsetX: 5
    });
    $('#TextComment').poshytip({
        className: 'tip-darkgray',
        showOn: 'focus',
        alignTo: 'target',
        alignX: 'right',
        alignY: 'center',
        allowTipHover: false,
        offsetX: 5
    });
}


function CharCounter(textId, totalchar) {
    var txtbox = document.getElementById(textId);
    var kalan = document.getElementById('kalanRakam');
    if (txtbox.value.length > totalchar) {
        txtbox.value = txtbox.value.substring(0, totalchar);
    }
    kalan.innerHTML = (totalchar - txtbox.value.length);
}

////--------------------------------------------------file download -----------------------------------
//function download(id) {// download file
//    var x = id.split('_');
//    //$.post('work.aspx', "2," + x[1]);
//    //$('#' + id).val("Downloading");
//    $.post('veri_isle.aspx', "gadgetDownload," + x[1], // download++ then indir...
//         function (answer) {
//            // top.location = "downloadFile.aspx?id=" + x[1];
//             $("#gadgetlink").css("title", answer + " kez indirildi ");
//             $('#gadgetlink').poshytip({
//                 className: 'tip-darkgray',
//                 showTimeout: 1,
//                 followCursor: true,
//                 alignTo: 'target',
//                 alignX: 'center',
//                 offsetY: 9,
//                 slide: true,
//                 allowTipHover: false,
//                 content: answer + " kez indirildi. "
//             });
//             //$('#' + id).val("Download");
//         });
//}

/********************************************************************
* You may use this code for free on any web page provided that     *
* these comment lines and the following credit remain in the code. *
* Keep In View (c) JavaScript-FX. (www.javascript-fx.com)          *
********************************************************************/
JSFX_KeepInView = function (id) {
    var getPageY = function (el) {
        return (el == null) ? 0 : el.offsetTop + getPageY(el.offsetParent);
    };
    var getScrollTop = function () {
        return document.body.scrollTop || document.documentElement.scrollTop
    };
    var el = document.getElementById(id);
    if (el == null) return;
    if (el.style.position == "absolute") {
        el.startPageTop = -el.offsetTop; el.currentX = el.offsetLeft; el.currentY = el.offsetTop;
    }
    else {
        el.style.position = "relative"; el.startPageTop = getPageY(el); el.currentX = el.currentY = 0;
    };
    el.floatInView = function () {
        var targetY = (getScrollTop() > this.startPageTop) ? getScrollTop() - this.startPageTop : 0;
        this.currentY += (targetY - this.currentY) / 4; this.style.top = this.currentY + "px";
    };
    setInterval('document.getElementById("' + id + '").floatInView()', 40);
};
/////////////////////////////
function changeColor(id, color) {
    if (color == 1)
    //color = "#b5b5b5";
        color = "#D2F3F3";
    if (color == 2)
        color = "white";
    document.getElementById(id).style.backgroundColor = color;
    var item = document.getElementById(id);
    var imgOfIt = item.getElementsByTagName("img");
    var imag = imgOfIt[0];
    if (imag.width == "98") {
        imag.width = "80";
        imag.height = "80";
    }
    else {

        imag.width = "98";
        imag.height = "98";
    }
}
function changeColor3(id, color) {
    if (color == 1)
        color = "#D2F3F3";
    if (color == 2)
        color = "white";
    document.getElementById(id).style.backgroundColor = color;
    var item = document.getElementById(id);
    var imgOfIt = item.getElementsByTagName("img");
    // var imag = imgOfIt[0];
    //if (imag.width == "40") {
    // imag.width = "60";
    // imag.height = "60";
    // }
    //else {

    //  imag.width = "40";
    //imag.height = "40";
    // }
}

$(function () {
    // $('#id.class')   :)
    try {
        //        $('#aramaBox').blur(function() {
        //            $('#aramaBox').poshytip('hide');
        //        });
        //        $('#aramaBox').poshytip({
        //            className: 'tip-darkgray',
        //            showOn: 'focus',
        //            alignTo: 'target',
        //            alignX: 'right',
        //            alignY: 'center',
        //            allowTipHover: false,
        //            offsetX: 5,
        //            content: 'Aranacak kelime!'
        //        });


        $('#aramaBox').click(function () {
            var k = document.getElementById("aramaBox").value;

            if (k != "") {
                $('#aramaBox').poshytip('show');
                $('.fg').poshytip({
                    className: 'tip-darkgray',
                    showTimeout: 1,
                    followCursor: true,
                    alignTo: 'target',
                    alignX: 'left',
                    alignY: 'center',
                    offsetX: 12,
                    slide: false,
                    fade: true,
                    hideAniDuration: 0,
                    allowTipHover: false
                });
            }
        });

        //        $('#btnSrch').poshytip({
        //            className: 'tip-darkgray',
        //            showOn: 'hover',
        //            alignTo: 'target',
        //            alignX: 'right',
        //            alignY: 'center',
        //            allowTipHover: false,
        //            showTimeout: 1,
        //            offsetX: 5,
        //            hideAniDuration: 0,
        //            content: 'Aramak için birşeyler yazın !'
        //        });

        $('.game_box').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: -8,
            offsetX: 0,
            slide: false,
            fade: true,
            hideAniDuration: 0,
            allowTipHover: false
        });
    }
    catch (ex) {
    }
    try {
        $('#em').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: 9,
            slide: true,
            allowTipHover: false,
            content: "oyunotobusu.com uzantılı e-mail adresi alın"
        });
        $('#de').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: 9,
            slide: true,
            allowTipHover: false,
            content: "Anasayfa"
        });
        $('#il').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: 9,
            slide: true,
            allowTipHover: false,
            content: "şikayet/öneri/teşekkür"
        });
        $('#face').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: 9,
            slide: true,
            allowTipHover: false,
            content: "Oyunlarımızı Facebook ta oynayın (yeni sekmede açılır .)"
        });

        $('#yukariGit').poshytip({
            className: 'tip-darkgray',
            showTimeout: 1,
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            offsetY: 9,
            slide: true,
            allowTipHover: false,
            content: "Yukarı Çık"
        });

    }
    catch (ex) {
    }
});
// function to only allow numeric key presses in a TextBox
// this doesn't stop pasting of non numeric values
function RakamKontrolu(e) {
    // deal with unicode character sets
    var unicode = e.charCode ? e.charCode : e.keyCode;
    // if the key is backspace, tab, or numeric
    if (unicode == 8 || unicode == 9 || (unicode >= 48 && unicode <= 57)) {
        // we allow the key press
        return true;
    }
    else {
        // otherwise we don't
        return false;
    }
}
function searchGame() {
    var k = document.getElementById("aramaBox").value;
    if (k == "" || k == null) {
        $('#aramaBox').poshytip('show');
    }
    else {
        document.getElementById("btnSrch").innerHTML = "Aranıyor";
        top.location = "found.aspx?key=" + k;
    }
}
function kaydir(id) {
    $.scrollTo('#' + id, 800, {
        duration: 2000
    });
}
$(document).ready(function () {

    // JSFX_KeepInView("rightSide");
    // JSFX_KeepInView("adhoodReklam");

    try {

        showFavoriesCount();
        // $("#gadgetlink").css("title", );
        //        $('#gadgetlink').poshytip('disable');
        //        $('#gadgetlink').poshytip('hide');
        //        $('#gadgetlink').poshytip({
        //            className: 'tip-darkgray',
        //            showTimeout: 1,
        //            followCursor: true,
        //            alignTo: 'target',
        //            alignX: 'center',
        //            offsetY: 9,
        //            slide: true,
        //            allowTipHover: false,
        //            content: $("#gadgetDownloads").val() + " kez indirildi. "
        //        });
    }
    catch (ex) {

    }

    function capatMenu() {
        $('#gameCategory').slideToggle('slow', function () {
        });
    }

    setTimeout(capatMenu, 3000);

    $('#gameCategoryContainer,#searchGameContainer,#visitorStatisticContainer,#gameStatisticContainer').click(function () {
        var id = $(this).attr("id");
        var x = id.split("Container")[0];
        //        var cs = $("#" + id + " span").attr("class");
        //        alert(cs);

        if ($("#" + id + " span").hasClass("ui-icon ui-icon-circle-triangle-s"))
            $("#" + id + " span").attr("class", "ui-icon ui-icon-circle-triangle-n")
        else if ($("#" + id + " span").hasClass("ui-icon ui-icon-circle-triangle-n"))
            $("#" + id + " span").attr("class", "ui-icon ui-icon-circle-triangle-s")
        //        var imgsi = $("#" + id + " img").attr("src");
        //        if (imgsi == "images/upArrow.png")
        //            $("#" + id + " img").attr("src", "images/downArrow.png");
        //        if (imgsi == "images/downArrow.png")
        //            $("#" + id + " img").attr("src", "images/upArrow.png");

        $('#' + x).slideToggle('400', function () {
            // Animation complete.
        });
    });

    //    var social = "<iframe src='./iframes/social.htm' width='330px' height='56px' style=' float:right;' frameborder='0' scrolling='no' >"
    //              + "Sosyal Ağlar Yüklenemedi... </iframe>";

    //    $("#facebookTwitter").html(social);

    //    //    var gameCats = "<iframe src='iframes/gameCategories.aspx' width='247px' height='185px'  frameborder='0' scrolling='no' >"
    //    //              + "Oyun Kategorileri Yüklenemedi... </iframe>";

    // $("#gameCategories").html(gameCats);

    var gameStats = "<iframe src='iframes/gameStatistics.aspx' width='244px' height='100px'  frameborder='0' scrolling='no' >"
              + "Oyun İstatistikleri Yüklenemedi... </iframe>";

    $("#gameStatus").html(gameStats);

    var visitorStats = " <iframe src='iframes/visitors.aspx' width='244' height='100' frameborder='0' scrolling='no'>"
                    + "  Ziyaretçi İstatistikleri Yüklenemedi... </iframe>";

    $("#visitorStatus").html(visitorStats);

    var href = jQuery(location).attr('href');
    var index = href.lastIndexOf("/");
    filename = href.substr(index + 1);
    var queryStrings = filename.split('?');
    if (queryStrings.length > 0) {
        filename = queryStrings[0];
    }
    //var url = jQuery(this).attr('title');
    $("li[id*='" + filename + "']").addClass("current");

    //    if (href.match("Default") != null || href.match("aspx") == null) {
    //        $("#de").addClass("current");
    //    }
    //    if (href.match("contact") != null) {
    //        $("#il").addClass("current");
    //    }
    //    if (href.match("email") != null) {
    //        $("#em").addClass("current");
    //    }
    //    if (href.match("comments") != null) {
    //        $("#yo").addClass("current");
    //    }

    $("#2").lavaLamp({
        fx: "backout",
        speed: 700,
        click: function (event, menuItem) {
        }
    });

    senYokkenEklenenOyunlar();
    // setTimeout("checkEvents()", 3000);

});

var seninSonOyunun = "";
var bugunkuOyunlar = "";

function showLastGame() {
    $("#sonOyunYukleniyor").css("display", "block");
    $.post('/veri_isle.aspx', '6,', // bugün ve seninki ni beraber dön
      function (deger) {
          if (deger != "") {
              var x = deger.split(';;');
              //     $("#silider").html(x[0]);
              //     $('#slider-code').tinycarousel({ pager: true, interval: true });
              // $("#bugun").html(x[0]);
              bugunkuOyunlar = x[0];
              $("#sonOyunYukleniyor").css("display", "none");

              seninSonOyunun = x[1];
              $.colorbox({ opacity: "0.50", html: seninSonOyunun, width: 180, height: "auto" });
          }
      });
}

function showFavories() {
    $("#listeYukleniyor").css("display", "block");
    $.post('/veri_isle.aspx', '14,', // bugün ve seninki ni beraber dön
      function (deger) {
          if (deger != "") {
              $("#listeYukleniyor").css("display", "none");
              $.colorbox({ opacity: "0.50", html: "<div align='center' id='favoriesTableDiv'><span class='title'>Favori Oyunların :  "
                  + "Tıkla Oyna</span> </br>" + deger + "</div>"
              });
          }
      });
}

function showFavoriesCount() {
    $("#listeYukleniyor").css("display", "block");
    $.post('/veri_isle.aspx', '15,', // bugün ve seninki ni beraber dön
      function (deger) {
          if (deger != "") {
              $("#listeYukleniyor").css("display", "none");
              $("#favoriCount").html(deger);
          }
      });
}

function senYokkenEklenenOyunlar() {

    $.post('/veri_isle.aspx', '12,',
        function (deger) {
            $.fx.speeds._default = 200;
            if (deger != "no") {
                //                $("#dialogSenYokken").dialog({
                //                    show: "blind",
                //                    hide: 'bounce',
                //                    autoOpen: false,
                //                    position: ['center', 55],
                //                    modal: true,
                //                    minHeight: '300px',
                //                    width: '270px',
                //                    closeText: "Kapat",
                //                    buttons: "close",
                //                    title: 'Sen Yokken Eklenen Oyunlarımız ( En Yeni 3 )'
                //                });
                //                $("#dialogSenYokken").dialog('open');

                //$("#senYokken").html(deger);
                $.colorbox({ opacity: "0.50",
                 html: "<div align='center' >" + deger + "</div>",
                 width:"250px"
                });

                $('.senYoktun').poshytip({
                    className: 'tip-darkgray',
                    showTimeout: 1,
                    followCursor: true,
                    alignTo: 'target',
                    alignX: 'right',
                    alignY: 'center',
                    offsetX: 5,
                    slide: false,
                    fade: true,
                    hideAniDuration: 0,
                    allowTipHover: false
                });
                $(".senYoktun").mouseover(function () {
                    $(this).css("background-color", "#D2F3F3");
                });
                $(".senYoktun").mouseout(function () {
                    $(this).css("background-color", "white");
                });
            }
            else
                $("#senYokken").html("");
        }
        );
}


function checkEvents() {

    if (document.body && document.body.offsetWidth) {
        winW = document.body.offsetWidth;
        winH = document.body.offsetHeight;
    }
    if (document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.offsetWidth) {
        winW = document.documentElement.offsetWidth;
        winH = document.documentElement.offsetHeight;
    }
    if (window.innerWidth && window.innerHeight) {
        winW = window.innerWidth;
        winH = window.innerHeight;
    }

    // alert("aaa");
    $.post('/veri_isle.aspx', '11,',
                function (deger) {
                    $.fx.speeds._default = 200;
                    if (deger != "no") {

                        $("#dialogNewGame").dialog({
                            show: "bounce",
                            hide: 'bounce',
                            autoOpen: false,
                            position: [winW - 170, winH - 195],
                            bottom: '5px',
                            minHeight: '300px',
                            width: '170px',
                            closeText: "Kapat",
                            buttons: "close",
                            title: 'Yeni Oyun Eklendi !'
                        });
                        $("#dialogNewGame").dialog('open');

                        $("#newGame").html(deger);

                        $('.senYoktun').poshytip({
                            className: 'tip-darkgray',
                            showTimeout: 1,
                            followCursor: true,
                            alignTo: 'target',
                            alignX: 'center',
                            offsetY: -8,
                            offsetX: 0,
                            slide: false,
                            fade: true,
                            hideAniDuration: 0,
                            allowTipHover: false
                        });
                        $(".senYoktun").mouseover(function () {
                            $(this).css("background-color", "#D2F3F3 ");
                        });
                        $(".senYoktun").mouseout(function () {
                            $(this).css("background-color", "white");
                        });
                    }

                }
           );
    setTimeout("checkEvents()", 8000);

}

function kapa() {
    $.unblockUI();
}

var aramaPost;
function aramami(e) {
    var k = document.getElementById("aramaBox").value;

    // document.getElementById("aramaSonuclar").innerHTML = "";
    var result, cdo = 0;
    if ((e.charCode) && (e.keyCode == 0)) {
        cdo = e.charCode;
    } else {
        cdo = e.keyCode;
    }
    //alert(cdo);

    if (k == "" || k == null) {
    }
    else {
        // document.getElementById("aranan").innerHTML = "Aranıyor";
        $('#aramaBox').poshytip("destroy");
        $('#aramaBox').poshytip({
            className: 'tip-simple',
            showTimeout: 1,
            showOn: 'none',
            followCursor: true,
            alignTo: 'target',
            alignX: 'center',
            alignY: 'top',
            offsetY: 5,
            width: 250,
            slide: true,
            allowTipHover: false,
            content: "<div align='center'><img src='images/yukleniyorSmall.gif' />  Aranıyor...</div>"
        });

        // ddd = "<div style='position:relative; max-height:250px; overflow:auto;'>" + deger + "</div>";
        // $('#aramaBox').poshytip("update",ddd);
        $('#aramaBox').poshytip("show");
        if (aramaPost)
            aramaPost.abort();

        if (k != "") {
            aramaPost = $.post('/searchGame.aspx', k,
            function (deger) {
                var ddd = "";
                document.getElementById("aranan").innerHTML = "";
                // document.getElementById("aramaSonuclar").innerHTML = deger;
                $('#aramaBox').poshytip("destroy");
                $('#aramaBox').poshytip({
                    className: 'tip-simple',
                    showTimeout: 1,
                    showOn: 'none',
                    followCursor: true,
                    alignTo: 'target',
                    alignX: 'center',
                    alignY: 'top',
                    offsetY: 5,
                    slide: true,
                    allowTipHover: false,
                    content: "<div style='position:relative; max-height:250px; overflow:auto;'>" + deger + "</div>"
                });

                // ddd = "<div style='position:relative; max-height:250px; overflow:auto;'>" + deger + "</div>";
                // $('#aramaBox').poshytip("update",ddd);
                $('#aramaBox').poshytip("show");

                $('.fg').poshytip({
                    className: 'tip-darkgray',
                    showTimeout: 1,
                    followCursor: true,
                    alignTo: 'target',
                    alignX: 'right',
                    alignY: 'center',
                    offsetX: 15,
                    slide: false,
                    fade: true,
                    hideAniDuration: 0,
                    allowTipHover: false
                });

            } // end function
            ); // end post
        }

    }

}

$(document).click(function (e) {
    if ($(e.target).is('#oyunArama, #oyunArama *,#foundGames *,#foundGames'))
        return;
    $('#aramaBox').poshytip("hide");
});
function kapa() {
    $.unblockUI();
}
function GetDescriptionFor(e) {
    var result, code;
    if ((e.charCode) && (e.keyCode == 0)) {
        result = "charCode: " + e.charCode;
        code = e.charCode;
    } else {
        result = "keyCode: " + e.keyCode;
        code = e.keyCode;
    }
    if (code == 8) result += " BKSP"
    else if (code == 9) result += " TAB"
    else if (code == 27) result = "ESC"
    else if (code == 46) result += " DEL"
    else if ((code >= 41) && (code <= 126)) result += " '" + String.fromCharCode(code) + "'";
    if (e.shiftKey) result += " shift";
    if (e.ctrlKey) result += " ctrl";
    if (e.altKey) result += " alt";
    return result;
}
function MonitorKeyDown(e) {
    if (!e) e = window.event;
    // alert(GetDescriptionFor(e));
    if (GetDescriptionFor(e) == "ESC")
        kapa();
}
function MonitorKeyUp(e) {
    if (!e) e = window.event;
    if (GetDescriptionFor(e) == "ESC")
        kapa();
}
function MonitorKeyPress(e) {
    if (!e) e = window.event;
    if (GetDescriptionFor(e) == "ESC")
        kapa();
}
document.onkeydown = MonitorKeyDown;
document.onkeyup = MonitorKeyUp;
document.onkeypress = MonitorKeyPress;

