$("document").ready(function(){
  $("#warn a").click(function(){
         $("#warn").hide();
         $("#step1").show()
  });
  $("#swfuploaddiv").mouseover(function(){
         $("#select_file").removeClass("select_file");
         $("#select_file").addClass("select_file_hover")
  });
  $("#swfuploaddiv").mouseout(function(){
        $("#select_file").addClass("select_file");
        $("#select_file").removeClass("select_file_hover")
  });
  var a=$('<img src="/images/close.png" />');
  a.prependTo("#hint");
  $("#hint img").click(function(){
         $(this).parent().hide();
         $("#hintbg").hide();
         $("#news").css("z-index",15)
  });
  $("#select_descr a").click(function(){
         if($("#hint").css("display")=="none"){
            $("#news").css("z-index",5);
            $("#hint").show();
            $("#hintbg").show();
            $("#hintbg").height($("#hint").height())
         }
         else{
            $("#news").css("z-index",15);$("#hint").hide();$("#hintbg").hide()
         }
         return false
  });
});

var settings={
  flash_url:"/swfupload.swf",
  prevent_swf_caching: false,
  //debug: true,
  button_placeholder_id:"spanButtonPlaceHolder",
  upload_url:"/image/upload",
  post_params: ckey,
  file_size_limit:"5 MB",
  file_types:"*.jpg; *.jpeg",
  file_types_description:"Jpeg Files",
  file_upload_limit:5,
  file_queue_limit:1,
  button_width:"295",
  button_height:"34",
  button_text:"",
  button_text_style:"",
  button_text_left_padding:0,
  button_text_top_padding:0,
  button_window_mode:"transparent",
  file_dialog_complete_handler:function()
    {
      this.startUpload()
    },
  upload_start_handler:function(b)
    {
      $("#bar_proc").css("backgroundPosition","0px 0px");
      jQuery("#step1").css("top","1000px");
      jQuery("#step2").show();
      jQuery("#bar_proc").css("width","0px");
      jQuery("#bar_proc").everyTime(50,function(){var c=parseInt($("#bar_proc").css("backgroundPosition"))+2;$("#bar_proc").css("backgroundPosition",c+"px 0px")})
    },
  upload_progress_handler:function(d,b,c)
    {
      var e=b/c;
      document.getElementById("bar_proc").style.width=Math.ceil(244*e)+"px";
    },
  file_queue_error_handler:function(b,d,c)
    {
      if(d===SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED)
        {alert("Вы выбрали несколько файлов. Загружать можно только один.");return}
      switch(d){
        case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:alert("Файл больше 5 мб.");break;
        case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:alert("Нельзя загрузить файл нулевой длины.");break;
        case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:alert("Неверный тип файла.");break;
      }
    },
  upload_success_handler:function(c,e)
    {
      var b=e.substr(0,1);
      if(b!="0"){
        jQuery("#step1").css("top",0);
        jQuery("#step2").hide();
        jQuery("#step3").hide();
        jQuery("#bar_proc").stopTime();
        switch(b){
          case"1":alert("Файл больше 5 Мб.");break;
          case"2":alert("Неверный тип файла.");break;
          case"3":alert("Картинка слишком маленькая. Минимум - 500 пикселей по любой стороне.");break;
          case"4":alert("Картинка слишком большая. Максимум - 3000 пикселей по любой стороне.");break;
          default:alert("Ошибка при загрузке файла.");break;
        }
      } else {
        var d=parseInt(e.substr(1));
        if(d==0) {
          $.get("/image/isuploaded?"+Math.random(),function(f){if(f=="1"){jQuery("#step2").hide();
          jQuery("#bar_proc").stopTime();
          jQuery("#step3").hide();
          jQuery("#step4").show()}else{jQuery("#step3").stopTime();
          jQuery("#step3").hide();
          jQuery("#step2").hide();
          jQuery("#step1").css("top",0);
          alert("Произошел сбой загрузки");}})
        }
        else {
          jQuery("#step3 #waittime span").html(rus_text("секунд,секунду,секунды",d));
          jQuery("#step3 #waittime span").everyTime(1000,function(){var f=parseInt($(this).html());f--;if(f<1){$(this).stopTime();$(this).html("совсем немного")}else{$(this).html(rus_text("секунд,секунду,секунды",f))}});
          jQuery("#step2").hide();
          jQuery("#step3").show();
          jQuery("#bar_proc").stopTime();
          jQuery("#roundbar div").css("backgroundPosition","0px 0px");
          jQuery("#roundbar div").css("left","0px");
          jQuery("#roundbar div").everyTime(140,function(){
              var g=parseInt($(this).css("left"));var f=parseInt($(this).css("backgroundPosition").split(" ")[0]);var h=parseInt($(this).css("backgroundPosition").split(" ")[1]);if(h==0){if(g>=162){h=27;g=g-27;f=f+27}else{g=g+27;f=f-27}}else{if(g<=0){h=0;g=g+27;f=f-27}else{g=g-27;f=f+27}}$(this).css("backgroundPosition",f+"px "+h+"px");$(this).css("left",g+"px")
          });
          jQuery("#step3").oneTime(d*1000,function(){jQuery("#step3").everyTime(2000,function(){$.get("/image/isuploaded?"+Math.random(),function(f){if(f=="1"){jQuery("#step3").stopTime();jQuery("#step3").hide();jQuery("#step4").show()}})});$.get("/image/isuploaded?"+Math.random(),function(f){if(f=="1"){jQuery("#step3").stopTime();jQuery("#step3").hide();jQuery("#step4").show()}})})
        }
      }
    }
};
var swfu = new SWFUpload(settings);