﻿$(document).ready(function() { 
    var fv = $().flash.hasFlash.playerVersion().split(',')[0]
    if (fv > 8 && !disableFlash) {
        $('#mainFlash').flash(
             {
                 src: webRoot + '/swf/home.swf',
                 width: "950",
                 height: "438",
                 wmode: 'transparent',
                 flashvars: { xmlpath: xmlpath }
             },
              {
                  expressInstall: true,
                  version: '8'
              }
         );
         
         
    } else {
         
        $.getJSON(jsonpath,
        function(data){
            var sol_orta = "<div class='image-container'>";
            $.each(data["6"], function(){
                sol_orta += "<div><a href='"+ this.link +"'><img src='"+ this.url +"' alt='" + this.title +"' /></a></div>"
            });
            sol_orta += "</div>"
            sol_orta += "<div class='tabs'><ul>"
            $.each(data["6"], function(i){
                sol_orta += "<li><a href=''>"+ parseInt(i+1) +"<span>"+ this.title.substr(0,15) +"...</span></a></li>"
            });
              sol_orta += "</ul></div>"
            $("#campaign_sol_orta").html(sol_orta)
            init_sol_orta();
        });     
        
        var timercount = 1
        function init_sol_orta(){
            $(".tabs ul li a").bind("click",function() {
                var gidici = $(".tabs ul li a").index(this)
                var yol = $(".image-container div").eq(gidici);
                var katsayi = gidici;
                var ml = katsayi * 285
                $(".image-container").css({
                    marginLeft: -ml
                }, 500);
                $(".tabs ul li").removeClass("selected")
                $(this).parent().addClass("selected")


                return false;
            })
            function timerla() {
                $(".tabs ul li a").eq(timercount).click();

                timercount++
                if (timercount == $(".tabs ul li a").size()) {
                    timercount = 0
                }
            }
            $(".tabs ul li a").eq(0).click()
            setInterval(timerla, 4000)
        }
        
        
        
        $.getJSON(jsonpath,
        function(data){
              var orta_alan = "";
              $.each(data["7"], function(i){
                 orta_alan += '<div id="banner_'+parseInt(i+1)+'" class="banItem"><a href="'+ this.link +'"><img src="'+ this.url +'" alt="'+ this.title +'" /></a></div>';
              });
              orta_alan += '<div class="bannerNavigator">';
              $.each(data["7"], function(i){
                 orta_alan += '<a href="javascript:;" class="bann_'+parseInt(i+1)+'">'+this.title.substr(0,10)+'...</a>'
              });
              orta_alan += '</div>';
              $("#midFlash").html(orta_alan)
              bind_homepage();
              $(".bannerNavigator a").eq(0).click();
        }); 
        
        function bind_homepage(){            
            $(".bannerNavigator a").click(function(){
                var _banIndex = parseInt($(".bannerNavigator a").index(this) + 1);
                $(".bannerNavigator a").attr("style","")
                if(_banIndex == 1){
                    $(this).css("background","url("+webRoot+"/images/alternate/banner_tab_1_on.png) no-repeat left top"),
                    $(this).css("margin","0px")
                }
                else if(_banIndex == 2){
                    $(this).css("background","url("+webRoot+"/images/alternate/banner_tab_2_on.png) no-repeat left top"),
                                  $(this).css("margin","0px")
                }
                 else if(_banIndex == 3){
                    $(this).css("background","url("+webRoot+"/images/alternate/banner_tab_3_on.png) no-repeat left top"),
                                  $(this).css("margin","0px")
                }
                 else if(_banIndex == 4){
                    $(this).css("background","url("+webRoot+"/images/alternate/banner_tab_4_on.png) no-repeat left top"),
                                  $(this).css("margin","0px")
                }
                 else if(_banIndex == 5){
                    $(this).css("background","url("+webRoot+"/images/alternate/banner_tab_5_on.png) no-repeat left top"),
                                  $(this).css("margin","0px")
                }
                $("#midFlash .banItem").removeClass("active")
                $("#midFlash").children("#banner_"+_banIndex).addClass("active")
                $(".bannerNavigator a").removeClass("active")
                $(this).addClass("active")
            })
        }
        
        $.getJSON(jsonpath,
        function(data){
            var sag = "";
            $.each(data["8"], function(i){
                if(i >= 3){
                
                }
                else {
                    sag += "<div><a href='#'><img src='"+ this.url +"' alt='" + this.title +"' /></a></div>"
                }
            });
            $("#rcont_content").append(sag)
        }); 
        
        $(".haberdar-et").css("top", "211px");
        
           
   }                  
});
