var state = 'none';

function showhide(layer_ref) {

   if (state == 'block') {
      state = 'none';
   }
   else {
      state = 'block';
   }

   if (document.all) { //IS IE 4 or 5 (or 6 beta) 
      var layer = document.getElementById(layer_ref);
      if (layer != null) {
         if (layer.style.display == 'block') {
            state = 'none';
         }
         else {
            state = 'block';
         }
         eval("document.all." + layer_ref + ".style.display = state");
      }
   }
   if (document.layers) { //IS NETSCAPE 4 or below 
      if (document.layers[layer_ref].display == 'block')
         document.layers[layer_ref].display = 'none';
      else
         document.layers[layer_ref].display = 'block';
   }
   if (document.getElementById && !document.all) {
      var layer = document.getElementById(layer_ref);
      if (layer.style.display == 'block') {
         state = 'none';
      }
      else {
         state = 'block';
      }
      layer.style.display = state;
   }
   
   return state;
} 

function changeText(objId,txt) {
  var el = document.getElementById(objId);
  //alert(el.innerHTML);
  el.innerHTML = txt;
}

$(function() {
    $( "#tabs" ).tabs();
    $(".tarih").datepicker({
        showOn: 'both',
        buttonImageOnly: true,
        dateFormat: "dd.mm.yy"
    });
        jQuery('#caro').jcarousel({
        // Configuration goes here
    });
   // $( "#dugmetasiyici" ).sortable();
    var t=setTimeout("sat()",1000);
    var t2=setTimeout("sat()",1500);
});
$(document).ready(function() {
    $("img.kucukresim").click(function(){
     	$("img.kucukresim").css("border","none");
    	$(this).css("border","3px solid #909090");
        //$("#buyukresim").fadeOut("500");
        var src=$(this).attr("src");
        $("#buyukresim").attr("src",src);
        $("#buyukresim").fadeIn("200");
        $("#buyukresim").aeImageResize({ height: 300 });
    })
    $('[role="ara"]').click(function(){
        $(this).css("color","black");
    })
    
    $('[tip="para"]').click(function() {
       $(this).css("color","black");
    });
    $(".danres").aeImageResize({ width: 100,height:125 });
    $(".satres").aeImageResize({ height:180});
    $('#slider').nivoSlider({
    directionNav:true,
    controlNav:false
    });

});
function sat()
{
    $(".satres").each(function(index) {
    	//$(this).css("margin-top",181-$(this).attr("height")+"px");
    	var deger=index+1;
    	//alert($("#satildi"+deger).attr("width"))
    	var gen=160-$("#satildi"+deger).attr("width");
    	if(gen!=160)
    	{
    	    gen=gen/2;
    		$("#satildi"+deger).css("margin-left",gen+"px");
    	}
    	else
    	{
    		var t2=setTimeout("sat()",500);
    	}

  	});
}
$(function($){
	$(function(){
		$('[tip="para"]').setMask({
		 mask : '999.999.999.999.999', type : 'reverse'
		});
	});
});

function tipGuncelle()
{
    var grup= $("#grupsecici").val();
    $("#tipsecici").empty();
    if(grup=="Konut")
    {
        var html='<select name="tip">';
        for(i in konut)
        {
            html=html+'<option value="'+konut[i]+'">'+konut[i]+'</option>'
        }
        html=html+"</select>";
        $("#tipsecici").html(html);
        $('[arazi="0"]').slideDown();
    }
    if(grup=="İşyeri")
    {
        var html='<select name="tip">';
        for(i in isyeri)
        {
            html=html+'<option value="'+isyeri[i]+'">'+isyeri[i]+'</option>'
        }
        html=html+"</select>";
        $("#tipsecici").html(html);
        $('[arazi="0"]').slideDown();
    }
    if(grup=="Arazi")
    {
        var html='<select name="tip">';
        for(i in arazi)
        {
            html=html+'<option value="'+arazi[i]+'">'+arazi[i]+'</option>'
        }
        html=html+"</select>";
        $("#tipsecici").html(html);
        $('[arazi="0"]').slideUp();
    }

}
function saveuser()
{
    var userData = $("#userform").serialize();
    //alert(site+'register/save/'+userData);
    $.ajax({
      type: 'POST',
      url: site+'register/save/'+userData,
      dataType: "json",
      success: function(data) {
          if(data.result)
          {
            $("#tabs").tabs( "select" , 1 );
            $("#userid").val(data.ident);
            $.cookie('user',data.ident);
          }
          else
          {
            alert("upps.. Houston, we have a problem")
          }

      }
    });
}

function mesajGonder()
{
    var isim=$("#isim").val();
    var eposta=$("#eposta").val();
    var mesaj=$("#mesaj").val();
    if(isim!="" || eposta !="" || mesaj!="")
    {
        $.ajax({
          type: 'POST',
          url: site+'mesajGonder',
          data:{
            isimveri:isim,
            epostaveri:eposta,
            mesajveri:mesaj
          },
          dataType: "json",
          success: function(data)
          {
            if(data.result)
            {
                $("#iletisimform").html("<b>Mesajınız Gönderildi.</b>")
            }
            else
            {
                alert("Bir Hata Oluştu.")
            }

          }
        });
    }

}
function boyutla(gen,id)
{
	$("#satildi"+id).aeImageResize({ width: gen });

}


