// Index
// ---------------------------------------------
var index = new Object;
$(document).ready(function() {
    index = {

        // Init
        // ---------------------------------------
        init: function() {
            //	$(document).pngFix();
            //	if($.cookie('color')) index.color($.cookie('color'));
            // var lst = $('div.hepsiburada'); for (var i = 0; i < lst.length; i++) index.hepsiburada(lst[i]);
            var lst = $('div.toplist'); for (var i = 0; i < lst.length; i++) index.toplist(lst[i]);
            var lst = $('div.select'); for (var i = 0; i < lst.length; i++) index.select(lst[i]);
            var lst = $('div.carousel'); for (var i = 0; i < lst.length; i++) index.carousel(lst[i]);
            try { document.execCommand("BackgroundImageCache", false, true); } catch (e) { }

            $('H1').click(function() { location.href = loc + 'default.aspx'; });
        },

        // Color
        // ---------------------------------------
        color: function(color) {
            $('link[ref=sclr]').attr('href', loc + 'App_Themes/CSS/index.' + color + '.css');
            $.cookie('color', color);
        },

        // Search
        // ---------------------------------------
        search: function(kelime, kategori) {
            location.href = loc + 'Arama/Default.aspx?kelime=' + kelime + '&kategori=' + kategori;
        },

        // Hepsi Burada
        // ---------------------------------------
        hepsiburada: function(div) {
            var lnk = $(div).find('H4 A');
            var lst = $(div).find('BLOCKQUOTE');
            lst.hide();
            for (var i = 0; i < lnk.length; i++) {
                lnk[i].lst = lst[i];
                $(lnk[i]).click(function() {
                    lnk.removeClass('hvr');
                    lst.hide();
                    $(this).addClass('hvr');
                    $(this.lst).show();
                });
                if (lnk[i].className == 'hvr') {
                    $(lst[i]).show();
                }
            }
        },

        // Toplist
        // ---------------------------------------
        toplist: function(div) {
            var lnk = $(div).find('H4 A');
            var lst = $(div).find('UL');
            lst.hide();
            for (var i = 0; i < lnk.length; i++) {
                lnk[i].lst = lst[i];
                $(lnk[i]).click(function() {
                    lnk.removeClass('hvr');
                    lst.hide();
                    $(this).addClass('hvr');
                    $(this.lst).show();
                });
                if (lnk[i].className == 'hvr') {
                    $(lst[i]).show();
                }
            }
        },

        // Select
        // ---------------------------------------
        select: function(div) {
            $(div).find('UL').wrap('<div></div>');
            $(div).find('DIV').prepend('<span><input type="text" name="text"/></span>');
            var inp = $(div).find('INPUT');
            var lst = $(div).find('UL');
            inp.click(function() {
                lst.show(200);
            });
            inp.hover(function() {
                inp.addClass('hvr');
            }, function() {
                inp.removeClass('hvr');
            });
            lst.find('A').click(function() {
                lst.find('A').removeClass('hvr');
                $(this).addClass('hvr');
                inp.attr('value', $(this).text());
                $(this).focus();
            });
            $(document).click(function(e) {
                if (typeof (e) == 'undefined') e = window.event; var elm = (e.target) ? e.target : e.srcElement;
                if (typeof (lst) != 'undefined' && elm.tagName != 'INPUT') {
                    lst.hide();
                }
            });
            var lnk = lst.find("A[class='hvr']").length ? lst.find("A[class='hvr']").get(0) : lst.find('A').get(0);
            inp.attr('value', $(lnk).text());
            $(lnk).focus();
        },

        // Carousel
        // ---------------------------------------
        carousel: function(div) {
            var cnt = $(div).find('div.cnt');
            var lst = $(div).find('ul');
       
            if (lst.attr('className') == '')
                var min = lst.width() - (lst.find('li').length * lst.find('li').width()); else
                var min = lst.width() - ((lst.find('li').length / 12) * 600);
            var max = 0;
            var spd = 0;
            var int = false;
            var mov = function() {
                var pos = parseInt(lst.css('margin-left')) - spd;
                if (pos < max && pos > min) lst.css('margin-left', pos);
            }
            cnt.mousemove(function(e) {
                var wdt = cnt.width();
                var off = cnt.offset();
                var pos = e.clientX - off.left;
                if (pos > (wdt / 2)) { spd = (pos - (wdt / 2)); }
                else if (pos < (wdt / 2)) { spd = -((wdt / 2) - pos); }
                spd = parseInt(spd / 50);
            });
            cnt.hover(function() { int = setInterval(function() { mov(); }, 10); }, function() { clearInterval(int); });
            $(div).find('a.prv').hover(function() { if (spd >= 0) spd = -5; int = setInterval(function() { mov(); }, 10); }, function() { clearInterval(int); });
            $(div).find('a.nxt').hover(function() { if (spd <= 0) spd = 5; int = setInterval(function() { mov(); }, 10); }, function() { clearInterval(int); });
            $(div).find('a.prv2').hover(function() { if (spd >= 0) spd = -5; int = setInterval(function() { mov(); }, 10); }, function() { clearInterval(int); });
            $(div).find('a.nxt2').hover(function() { if (spd <= 0) spd = 5; int = setInterval(function() { mov(); }, 10); }, function() { clearInterval(int); });
            if (lst.attr('className') == '')
                lst.width(lst.find('li').length * lst.find('li').width()); else
                lst.width(((lst.find('li').length / 12) * 600));
        }
    }

    index.init();
    tab_menu();
  //  gethepsiburada("hobiveeglence");
});






        /* gezisitesi*/
        function getgezisitesi(deger) {
            $('#output').hide();
            $('#load').show();

            $.ajax({
                type: "POST",
                url: "TestService.asmx/GeziSitesi",
                data: "{catname: '" + deger + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {

                    $('#load').hide();
                    $('#output').show();
                    var GeziSitesi = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    $('#output').empty();
                    for (var i = 0; i < GeziSitesi.length; i++) {
                        $('#output').append('<div><a href="' + GeziSitesi[i].header_link + '"><img class="yerimseni" src="' + GeziSitesi[i].image + '" alt="' + GeziSitesi[i].header + '" /></a><div style="border:1px solid #c7e4f7;"><table width="210px"border="0" cellspacing="2" cellpadding="2"><tr><td><span class="testme2"><a href="' + GeziSitesi[i].header_link + '">' + GeziSitesi[i].header + '</a></span></td></tr><tr><td><a href="' + GeziSitesi[i].header_link + '">' + GeziSitesi[i].def_text + '</a><br /><span class="testme3">' + GeziSitesi[i].retailprice + '</span></td></tr><tr><td align="right"><a href="' + GeziSitesi[i].header_link + '"><img id="img" style="border:0px;" src="http://www.kanald.com.tr/App_Images/btn.hbc.buy.png" alt="satın al" /></a></td></tr></table></div></div><div style="clear:both;height:2px;"></div>');

                    }

                },

                failure: function(msg) {
                    $('#output').text(msg);
                }

            });
        }
        /*gezisitesi bitti*/
        

       /*hemal hemsat*/
        function gethemalhemsat() {
            $('#output').hide();
            $('#load').show();

            $.ajax({
                type: "POST",
                url: "TestService.asmx/HemAlHemSat",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {

                    $('#load').hide();
                    $('#output').show();
                    var HemAlHemSat = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    $('#output').empty();
                    for (var i = 0; i < HemAlHemSat.length; i++) {
                        $('#output').append('<div><a href="' + HemAlHemSat[i].adv_header_link + '"><img class="yerimseni" src="' + HemAlHemSat[i].adv_image + '" alt="' + HemAlHemSat[i].adv_header + '" /></a><div style="border:1px solid #c7e4f7;"><table width="210px"border="0" cellspacing="2" cellpadding="2"><tr><td><span class="testme2"><a href="' + HemAlHemSat[i].adv_header_link + '">' + HemAlHemSat[i].adv_header + '</a></span></td></tr><tr><td><a href="' + HemAlHemSat[i].adv_header_link + '">' + HemAlHemSat[i].adv_spot + '</a><br /><span class="testme3">' + HemAlHemSat[i].adv_finalprice + '</span></td></tr><tr><td align="right"><a href="' + HemAlHemSat[i].adv_header_link + '"><img id="img" style="border:0px;" src="http://www.kanald.com.tr/App_Images/btn.hbc.buy.png" alt="satın al" /></a></td></tr></table></div></div><div style="clear:both;height:2px;"></div>');

                    }

                },

                failure: function(msg) {
                    $('#output').text(msg);
                }

            });
        }
         /*hem al hem sat bitti*/
         
         /* her eve lazım*/
        function getherevelazim(deger) {
            $('#output').hide();
            $('#load').show();

            $.ajax({
                type: "POST",
                url: "TestService.asmx/HerEveLazim",
                data: "{catname: '" + deger + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(response) {

                    $('#load').hide();
                    $('#output').show();
                    var HerEveLazim = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    $('#output').empty();
                    for (var i = 0; i < HerEveLazim.length; i++) {
                        $('#output').append('<div><a href="' + HerEveLazim[i].adv_LinkID + '"><img class="yerimseni" src="' + HerEveLazim[i].adv_ImagePath + '" alt="' + HerEveLazim[i].adv_UrunIsmi + '" /></a><div style="border:1px solid #c7e4f7;float:right;"><table width="190px"border="0" cellspacing="2" cellpadding="2"><tr><td><span class="testme2"><a href="' + HerEveLazim[i].adv_LinkID + '">' + HerEveLazim[i].adv_UrunIsmi + '</a></span></td></tr><tr><td><a href="' + HerEveLazim[i].adv_LinkID + '">' + HerEveLazim[i].adv_UrunAciklamasi + '</a><br /><span class="testme3">' + HerEveLazim[i].adv_finalprice + '</span></td></tr><tr><td align="right"><a href="' + HerEveLazim[i].adv_LinkID + '"><img id="img" style="border:0px;" src="http://www.kanald.com.tr/App_Images/btn.hbc.buy.png" alt="satın al" /></a></td></tr></table></div></div><div style="clear:both;height:2px;"></div>');

                    }

                },

                failure: function(msg) {
                    $('#output').text(msg);
                }

            });
        }
        /*her eve lazım bitti*/
        
        /*sayfa yüklenirken çalışacak komutlar*/
       /* $(document).ready(function() {
            tab_menu();          
            gethepsiburada("hobiveeglence");
        });*/
        /* komut istemi bitti*/

      
      


      
      
      
        function gethepsiburada(deger) {
               $('#output').hide();
               $('#load').show();
               
               $.ajax({
                   type: "POST",
                   url: "TestService.asmx/HepsiBurada",
                   data: "{catname: '" + deger + "'}",
                   contentType: "application/json; charset=utf-8",
                   dataType: "json",
                   success: function(response) {

                   $('#load').hide();
                   $('#output').show();
                       var HepsiBuradaCom = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                       $('#output').empty();
                       for (var i = 0; i < HepsiBuradaCom.length; i++) {
                           $('#output').append('<div><a href="' + HepsiBuradaCom[i].adv_header_link + '"><img class="yerimseni" src="' + HepsiBuradaCom[i].adv_image + '" alt="' + HepsiBuradaCom[i].adv_header + '" /></a><div style="border:1px solid #c7e4f7;"><table width="210px"border="0" cellspacing="2" cellpadding="2"><tr><td><span class="testme2"><a href="' + HepsiBuradaCom[i].adv_header_link + '">' + HepsiBuradaCom[i].adv_header + '</a></span></td></tr><tr><td><a href="' + HepsiBuradaCom[i].adv_header_link + '">' + HepsiBuradaCom[i].adv_spot + '</a><br /><span class="testme3">' + HepsiBuradaCom[i].adv_def_text + '</span></td></tr><tr><td align="right"><a href="' + HepsiBuradaCom[i].adv_header_link + '"><img id="img" style="border:0px;" src="http://www.kanald.com.tr/App_Images/btn.hbc.buy.png" alt="satın al" /></a></td></tr></table></div></div><div style="clear:both;height:2px;"></div>');

                       }

                   },

                   failure: function(msg) {
                       $('#output').text(msg);
                   }

               });
               
               
              
           
           }
     
        var aktif_tab = 0;
        function tab_menu() {
            tab_degistir(0);
            $("#tab_basliklar > span").mouseover(function() {
                var index = $("#tab_basliklar > span").index(this);
                if (aktif_tab != index) {
                    tab_degistir(index);
                    aktif_tab = index;
                }
            });
        }
        function tab_degistir(index) {
            $("#tab_basliklar > span").stop().animate({ opacity: "0.4" }, 500);
            $("#tab_basliklar > span:eq(" + index + ")").stop().animate({ opacity: "1" }, 500);
            $("#tab_goster").html($("#tab_menuler > div:eq(" + index + ")").html());
            $("#tab_goster a").css("opacity", "0.4").animate({ opacity: "1" }, 500);
        }



