//var status = "visitor";var status = "visitor";
//var status = "visitorSearch";
//var status = "logedUser";  
var headerStatus;
var newsStatus = "normal";  
var carouselStatus = "normal";

function showCountOf(what, count){
  for (i=0; i < (count); i++){
    $(what+":eq("+i+")").css("display", "block");
  }
}
function smallerSearchMenu(speed){
  if (speed == 0){
    $(".div_search_small_btn").css("display", "block");
    $("#div_select_filter_sm").css("display", "block");
    $("#div_select_ob").css("display", "none");
    $("#div_select_filter").css("display", "none");
    $("#div_search_container").css("width", "407px");
    $("#div_search_container_middle").css("width", "393px");
    $("#div_search_container").css("left", "212px");
    
    $("#div_el_container_left").css("width", "38px");
    $("#div_el_container_right").css("width", "74px"); 
  }else{
    $("#div_select_filter").fadeOut(speed);
    $("#div_select_ob").fadeOut(speed, function(){
      $("#div_el_container_left").animate({width: '38px'}, speed);
      $("#div_el_container_right").animate({width: '74px'}, speed);
      $("#div_search_container").animate({width: '407px', left: '240px'}, speed);
      $("#div_search_container_middle").animate({width: '393px'}, speed, function(){   
        $(".div_search_small_btn").fadeIn(speed);
        $("#div_select_filter_sm").fadeIn(speed);
      });
    });
    
  }
}

function biggerSearchMenu(speed){
  if (speed == 0){
    $(".div_search_small_btn").css("display", "none");
    $("#div_select_filter_sm").css("display", "none");
    $("#div_select_ob").css("display", "block");
    $("#div_select_filter").css("display", "block");

    $("#div_search_container").css("width", "480px");
    $("#div_search_container").css("left", "195px");
    $("#div_search_container_middle").css("width", "466px");    
    $("#div_el_container_left").css("width", "75px");
    $("#div_el_container_right").css("width", "111px");    
  }else{
    $(".div_search_small_btn").fadeOut(speed);
    $("#div_select_filter_sm").fadeOut(speed, function(){
      $("#div_el_container_left").animate({width: '75px'}, speed);
      $("#div_el_container_right").animate({width: '111px'}, speed);
      $("#div_search_container").animate({width: '480px', left: '195px'}, speed);
      $("#div_search_container_middle").animate({width: '466px'}, speed, function(){   
        $("#div_select_ob").fadeIn(speed);
        $("#div_select_filter").fadeIn(speed);
      });
    });
  }
}

function smallerHeader(time){
  $("#div_header_container").animate({height: '169px'}, time);
  $("#div_search_container").stop(true, true).animate({top: '141px'}, time);
  $("#div_logo").animate({marginTop: '15px'}, time);
  $("#div_header_info").css("display", "none");
  $("#div_tricolor").fadeOut(time);
  $("#div_arrows_registration").fadeOut(time);
  $("#div_arrows_login").fadeOut(time);
  $("#div_arrows_creation").fadeOut(time);
  headerStatus = "small";           
}

function biggerHeader(time){
  $("#div_header_container").animate({height: '270px'}, time);
  $("#div_search_container").stop(true, true).animate({top: '242px'}, time);
  $("#div_logo").animate({marginTop: '65px'}, time);
  $("#div_header_info").css("display", "block");
  $("#div_header_info").css("opacity", "0");
  $("#div_tricolor").fadeIn(time);
  
  $("#div_arrows_registration").fadeIn(time);
  $("#div_arrows_login").fadeIn(time);
  $("#div_arrows_creation").fadeIn(time);
  headerStatus = "big";           
}

function loadNewPage(){
  if (status == "visitor"){  
    smallerSearchMenu(0); 
    headerStatus = "big";
    showCountOf(".div_news_container", 10);
    $("#div_tricolor").css("display", "block");
    $("#div_header_container").slideDown(300, function(){
      $("#div_welcome_login").slideDown(300, function(){
        
        $("#div_carousel_mover").fadeIn(300);
        $("#div_left_part_main").fadeIn(300);
        $(".div_new_futures").fadeIn(300, function(){
          resize_page();
        });
      });  
    }); 
  }else if (status == "logedUser"){
    biggerSearchMenu(0);
    smallerHeader(0);
    $(".div_new_futures").css("margin-top", "70px");
    $("#div_header_container").css("display", "none");
    showCountOf(".div_news_container", 10);
    $("#div_header_container").slideDown(300, function(){
      $("#div_loged_information").fadeIn(300);
      //smallCarousel();
      //$("#div_carousel_mover").fadeIn(300);
      //$("#div_my_materials").fadeIn(300);
      $(".div_new_futures").fadeIn(300);
      $("#div_searched_box").fadeIn(300, function(){
        resize_page();
      }); 
      resize_page();
    });
  }else if (status == "videoDocs"){
    biggerSearchMenu(0);
    smallerHeader(0);
    $(".div_new_futures").css("margin-top", "70px");
    $("#div_header_container").css("display", "none");
    showCountOf(".div_news_container", 10);
    $(".div_video_container").fadeIn(300);
    $("#div_header_container").slideDown(300, function(){
      $("#div_loged_information").fadeIn(300);
      $(".div_new_futures").fadeIn(300);
      resize_page();
    });
  }else if (status == "logedUserSearch"){
  
  
  }else if (status == "visitorSearch"){
    smallerHeader(0);
    smallerSearchMenu(0)
    $("#div_header_container").css("display", "none");
    showCountOf(".div_news_container", 10);
    
    $("#div_header_container").slideDown(300, function(){
      //smallCarousel();
      //$("#div_carousel_mover").fadeIn(300);
      $("#div_searched_box").fadeIn(300, function(){
        resize_page();
      });   
      $(".div_new_futures").fadeIn(300);
    });   
  }
  
}

function smallCarousel(){
  $(".div_carousel_prev").css("display", "none");
  $(".div_carousel_next").css("display", "none");
  $("#div_carousel_mover").css("left", "588px");
  $("#div_carousel_mover").css("top", "280px");
  $("#div_carousel_mover").css("width", "320px");
  $(".div_carousel_line:eq("+(position+0)+")").css("left", "-3px");
  $(".div_carousel_line:eq("+(position+1)+")").css("left", "145px");
  //$(".div_pagination_carousel").css("left", "144px");
  $(".div_pagination_carousel").css("left", ((310-((maximum/9)*14))/2)+"px");
  
  carouselStatus = "small";
}

function smallerCarousel(time){
  $(".div_carousel_prev").fadeOut(time/10);
  $(".div_carousel_next").fadeOut(time/10);
  $("#div_carousel_mover").animate({left: '588px', top: '280px', width: '320px'}, time);
  $(".div_carousel_line:eq("+(position+0)+")").animate({left: '-3px'}, time);
  $(".div_carousel_line:eq("+(position+1)+")").animate({left: '145px'}, time);
  $(".div_pagination_carousel").animate({left: ((310-((maximum/9)*14))/2)+"px"}, 300);
  carouselStatus = "small";
}

function biggerCarousel(time){
  $("#div_carousel_mover").animate({left: '0px', top: '220px', width: '565px'}, time, function(){
    $(".div_carousel_prev").fadeIn(time/10);
    $(".div_carousel_next").fadeIn(time/10);  
  });  
  $(".div_carousel_line:eq("+(position+0)+")").animate({left: '5px'}, time);
  $(".div_carousel_line:eq("+(position+1)+")").animate({left: '170px'}, time);
  $(".div_pagination_carousel").animate({left: ((490-((maximum/9)*14))/2)+"px"}, 300);
  carouselStatus = "normal";      
}

var isAutoSaving = false;
function startAutoPlay(){
  /*
  $('body').everyTime(60000, 'timerAutoSave', function() {
    isAutoSaving = true;
    $("#div_btn_save").css("opacity", "0.5");
    $(".saving_icon").css("display", "block");
    ajax_auto_save_slide();
    //alert("asd");                   
  }); */
}

function stopAutoPlay(){  /*
  isAutoSaving = false;
  $("#div_btn_save").fadeIn(150);
  $('body').stopTime('timerAutoSave');     */
}





$(window).load(function(){
  loadNewPage(); 
});

var gallery = false;
$(document).ready(function(){

$("#share_size_width").keyup(function() {  
    getShareIframe(null);
});

$(".div_share_color").click(function (){
  var col = $(this).attr("id");
  $(".div_share_color").css("border", "1px white dotted") 
  $(this).css("border", "1px #00baff solid")
  COLOR = col; 
  getShareIframe(null);
});

$("#div_temp_auto_save").click(function (){
  ajax_auto_save_slide();
});
var count = 3;
var pos = 1;

$("#div_slider_prev").click(function (){
  pos++;
  if (pos <= count){
  $("#slider_"+(pos-1)).fadeOut(150, function(){
    $("#slider_"+pos).fadeIn(150);
  }); 
  }else if (pos <= count-1){
  }
});                           

var tabActive = 0;
$("#div_tab_creation").click(function (){
  //if (canChangeMode){
    endSaverMoving();
    canChangeMode = false
    var notActive = ($(this).attr("class").indexOf("active") == -1);
    if (notActive){
      $("#div_hide_controller").css("visibility", "visible");
      $("#controll").css("visibility", "visible");
      $("#TdoBackground_UI").css("visibility", "visible");
      $("#TdoDimension_UI").css("visibility", "visible");
      $("#div_btn_save").css("visibility", "visible");
      $("#TdoBackground_UI").css("visibility", "visible");
      $("#show_gallery").css("display", "block");
                                          
      
      $(".div_tab_left_active").css("opacity", "0.5");
      $(".div_tab_left_active").removeClass('div_tab_left_active');    
      $(this).addClass('div_tab_left_active');
      $(this).css("opacity", "1.0");
      setAnimStatus("editor");
    }
  //}
});

$("#div_tab_play").click(function (){
  //if (canChangeMode){
    startSaverMoving("draw");  
    canChangeMode = false
    var notActive = ($(this).attr("class").indexOf("active") == -1);
    if (notActive){
      $("#div_hide_controller").css("visibility", "hidden");
      $("#div_btn_save").css("visibility", "hidden");
      $("#controll").css("visibility", "hidden");
      $("#TdoBackground_UI").css("visibility", "hidden");
      $("#TdoDimension_UI").css("visibility", "hidden");
      $("#TdoBackground_UI").css("visibility", "hidden");     
      $("#show_gallery").css("display", "none");
      
      $(".div_gallery_sellect_container #div_image_picture").parent().attr("id", "");
      closeGallery();   

      $(".div_tab_left_active").css("opacity", "0.5");
      $(".div_tab_left_active").removeClass('div_tab_left_active')
      $(this).addClass('div_tab_left_active');
      $(this).css("opacity", "1.0");
      setAnimStatus("player");
    }
  //}
});


$("#div_forgott_password").click(function (){
  $("#div_image_alert").attr("class", "popUpImageQuest");
  
  
  var html = '<div id="div_close_alert_popup" style="position:absolute; top:22px; right:28px;" onclick="hideAlertPopUp()"></div><ul class="div_anim_btn_container" id="div_btn_login" onclick="forgottedEmailSend()" style="float:right; margin-top:17px; margin-right:4px; width:93px;"><li style="float:right"><div class="div_anim_btn_inside_container"><div class="div_left"></div><div class="div_middle">Odeslat<div class="white_text_anim_btn">Odeslat</div></div><div class="div_right"></div></div></li><li class="div_anim_btn_hover" style="float:right; right:0px;"><div class="div_anim_btn_inside_container"><div class="div_left"></div><div class="div_middle">Odeslat<div class="white_text_anim_btn">Odeslat</div></div><div class="div_right"></div></div></li></ul> ';
  html += '<div class="div_input_send_email"><input type="text" id="div_forgotted_pasw_input"></div>';
  
  html += "<script> $('.div_anim_btn_hover').hover(function () {      $(this).stop().animate({opacity: '1.0'}, 200);}, function () {$(this).stop().animate({opacity: '0.0'}, 400);}); </script>";
  
  $(".div_text_alert").html("Váš e-mail:"+html);
  showAlertPopup(500, 160, false);      
});



$("#share_size_height").keyup(function() {  
    getShareIframe(null);
});

  $("#page_select").change(function() {
    var value = $("#page_select").attr("value");
    if (value == "first"){  
      goBackSearch();
      status = "visitor";  
    }else if (value == "second"){
      status = "visitorSearch";
      resize_page();
      searchUnlog();
    }else if (value == "third"){
      logInUser();
      resize_page();
      status = "visitorSearch";
    }else if (value == "fourth"){
      logInUser();
    }
  });    
  
  $("#div_close_share_popup").click(function () {
    creating = false;
    hideStartCreationPopUp();
    $("#div_black_page_alert").fadeOut(200);
  });
  
  
  
  $("#div_show_edit_slide").click(function () {
    showStartCreationPopup();
    
    $("#div_ok_btn").css("display", "block");
    $("#div_continue_btn").css("display", "none");
    $("#div_storno_btn").css("display", "none");
    $("#div_close_share_popup").css("display", "none");
  });
  
  
  $(".div_gallery_sellect_container #div_image_picture").click(function () {
    if (!gallery){
      $(this).parent().attr("id", "div_gallery_selected");
      showGallery();
    }else{
      $(this).parent().attr("id", "");
      closeGallery();
    }
  });
  
  $("#div_select_ob .div_search_select_l").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $("#selected_tab").attr("id", "");
      $(this).attr("id", "selected_tab");   
    }
    geSlidesByTop();
  });
  $("#div_select_ob .div_search_select_m").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $("#selected_tab").attr("id", "");
      $(this).attr("id", "selected_tab");
    }
    geSlidesByTop();
  });
  $("#div_select_ob .div_search_select_r").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $("#selected_tab").attr("id", "");
      $(this).attr("id", "selected_tab");
    }
    geSlidesByTop();
  });  
  
  
  
  $("#div_select_filter_sm .div_search_select_l").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $(this).attr("id", "selected_tab");
    }else{
      if ($("#div_select_filter_sm .div_search_select_r").attr("id") == "selected_tab"){ 
        $(this).attr("id", "");
      }
    }
    geSlidesByTop();
  });
  
  $("#div_select_filter_sm .div_search_select_r").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $(this).attr("id", "selected_tab");
    }else{
      if ($("#div_select_filter_sm .div_search_select_l").attr("id") == "selected_tab"){ 
        $(this).attr("id", "");
      }
    }
    geSlidesByTop();
  });  
    
  $("#div_select_filter .div_search_select_l").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $(this).attr("id", "selected_tab");
    }else{                        
      if (($("#div_select_filter .div_search_select_m").attr("id") == "selected_tab") || ($("#div_select_filter .div_search_select_r").attr("id") == "selected_tab")){           
        $(this).attr("id", "");
      }  
    }
    geSlidesByTop();
  });
  $("#div_select_filter .div_search_select_m").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $(this).attr("id", "selected_tab");
    }else{
      if (($("#div_select_filter .div_search_select_l").attr("id") == "selected_tab") || ($("#div_select_filter .div_search_select_r").attr("id") == "selected_tab")){           
        $(this).attr("id", "");
      }  
    }
    geSlidesByTop();
  });
  $("#div_select_filter .div_search_select_r").click(function () {
    var sel = ($(this).attr("id") == "selected_tab");
    if (!sel){
      $(this).attr("id", "selected_tab");
    }else{
      if (($("#div_select_filter .div_search_select_m").attr("id") == "selected_tab") || ($("#div_select_filter .div_search_select_l").attr("id") == "selected_tab")){           
        $(this).attr("id", "");
      } 
    }
    geSlidesByTop();
  });     
  
  
  $(".div_search_small_btn").click(function () {
    geSlidesByTop();
  });     
  
  
  

  
  
  
  function saveNewSlide(status){
    $("#div_image_alert").attr("class", "popUpImageLoading");
    $(".div_text_alert").html("Snímek se ukládá ...");
    
    showAlertPopup(500, 160, false);      
    ajax_save_slide(status); 

    closeSavePopUp();
    $("#div_black_page_alert").stop(true, false).fadeTo(0, 0.6);
  }

  $("#div_save_to_working").click(function () { 
    if (editingSlide == null){   
      saveNewSlide(1);
    }else{
      $("#div_image_alert").attr("class", "popUpImageLoading");
      $(".div_text_alert").html("Snímek se ukládá ...");
      showAlertPopup(500, 160, false);      
      ajax_update_slide(editingSlide, 1);    
    }
  });  

  $("#div_save_to_waiting").click(function () {
    if (editingSlide == null){    
      saveNewSlide(2);
    }else{
      $("#div_image_alert").attr("class", "popUpImageLoading");
      $(".div_text_alert").html("Snímek se ukládá ...");
      showAlertPopup(500, 160, false);      
      ajax_update_slide(editingSlide, 2);
    }
  });    
  
    
  $("#div_btn_save").click(function () {  
    if (!isAutoSaving){
      showSavePopup(487, 180);
    } 
    /*  
    if (editingSlide == null){
      //ajax_save_slide(); tady  
      showSavePopup(487, 180);     
    }else{  
      $("#div_image_alert").attr("class", "popUpImageLoading");
      $(".div_text_alert").html("Snímek se ukládá ...");
      showAlertPopup(500, 160, false);      
      ajax_update_slide(editingSlide);
    } */
  });

  $(".next_slides_sheared").click(function () {
    alert("asd");  
  });
  
  
  $("#div_btn_new_slide").click(function () {
    creating = true;
    editingSlide = null;
    showStartCreationPopup();
    clearTags();
    //$("#div_continue_btn").css("display", "block");
    $("#div_disabled_continue").css("display", "block");
    
    $("#div_close_share_popup").css("display", "block");
    $("#div_ok_btn").css("display", "none");
    $("#div_continue_btn").css("display", "block");
    $("#div_storno_btn").css("display", "block");
    $("#div_new_slide_name").attr("value", "Název snímku ...");
    $("#div_new_slide_description").attr("value", "Popis snímku ...");
    if (gallery){
      closeGallery()
    }          
  });
  
  
  
  
  $("#div_ok_btn").click(function () {
    if (isCreateFormOk()){
      $("#div_black_page_alert").fadeOut(200);
      hideStartCreationPopUp();
    }else{
      whatIsNotOk();
    }
  });
  
  $("#div_continue_btn").click(function () {
    if (isCreateFormOk() || isBeta){
      hideStartCreationPopUp();
      startAutoPlay()
      createNewSlide();       
      $("#div_image_alert").attr("class", "popUpImageLoading");
      $(".div_text_alert").html("Animace se načítá ...");

      //changeTextComponentWidth(1);    
      //changeFillComponentWidth(1);
      //noPenSetting()
            
      showAlertPopup(500, 160, false);
    }else{
      whatIsNotOk();
    }      
  });
  
  
  $("#div_storno_btn").click(function () {
    hideStartCreationPopUp();
    $("#div_black_page_alert").fadeOut(200);
    creating = false;
  });   
  
  
  $("#input_search").keydown(function (e) {
    if (e.keyCode == '13') {
       geSlidesByTop();
     }
  });  
  
  
});
    
function createNewSlide(){//tady
  var source = $("#draw").attr("movie");    
  $("#draw").attr("movie", "klasjd laksdl a"); 
  $("#draw").attr("movie", source);   
  $("#div_creation_popup_container").fadeIn(400,function(){
    $("#draw").css("display", "block");      
  });
  $("#div_black_page").fadeTo(400, 0.95);
}


function openSlidePopUp(){;
  $("#div_open_popup_container").fadeIn(400,function(){
    $("#play").css("display", "block");
  });
  $("#div_black_page").fadeTo(400, 0.8);
}

function goBackSearch(){
  $("#div_loged_information").fadeOut(300);
  $("#div_header_login").fadeOut(300);   
  $("#div_my_materials").fadeOut(300, function(){
    $("#div_searched_box").fadeOut(300,function(){
      $(".div_new_futures").animate({marginTop: '0px'}, 300);
      showAllNews();
      biggerHeader(300);
      $("#div_left_part_main").fadeIn(300);
      $("#div_carousel_mover").fadeIn(300); 
      $("#div_welcome_login").slideDown(300, function(){
        resize_page();             
      });
    }); 
  });
}


function reduceNewsToTwo(){
  //$(".div_news_container:eq(2)").fadeOut(250);
  //$(".div_news_container:eq(3)").fadeOut(250);
  $(".div_new_futures").animate({marginTop: '56px'}, 300);
  newsStatus = "reduced";
}

function showAllNews(){
  //$(".div_news_container:eq(2)").fadeIn(250);
  //$(".div_news_container:eq(3)").fadeIn(250);
  newsStatus = "normal";
}


function logInUser(){
  if (headerStatus != "small"){
    smallerHeader(300); 
  }
  if (newsStatus != "reduced"){
    reduceNewsToTwo();
  }   
  if (carouselStatus != "small"){
    $("#div_carousel_mover").fadeOut(250);
    //smallerCarousel(300);
  } 
                                          
  $("#div_header_login").fadeOut(300);
  $("#div_searched_box").fadeOut(250);
  $("#div_left_part_main").fadeOut(300);
  $("#div_welcome_login").slideUp(300, function(){
    $(this).css("display", "none");
    //document.getElementById('div_login_email').value = "";
    document.getElementById('div_login_password').value = "";
    biggerSearchMenu(200);
    geSlidesByTop();    
    $("#div_loged_information").fadeIn(300);
    /*$("#div_searched_box").fadeIn(300, function(){
      resize_page();
    });*/                                             
  });         
}
     
$("#draw").css("display", "none");
$("#play").css("display", "none");

function searchUnlog(){ 
  $("#div_my_materials").fadeOut(300);
  $("#div_loged_information").fadeOut(300);
  $("#div_left_part_main").fadeOut(300);
  $("#div_carousel_mover").fadeOut(300);
  //smallerCarousel(300);
  reduceNewsToTwo();
  smallerHeader(300);       
  $("#div_welcome_login").slideUp(300, function(){
    $(this).css("display", "none");
    $("#div_header_login").fadeIn(300);
    
    $("#div_searched_box").fadeIn(400, function(){
      resize_page();
    })    
  }); 
}
          
function searchLoged(){   
  $("#div_my_materials").fadeOut(300);
  //$("#div_my_materials .div_search_item").animate({width: '180'}, 300);
  //$("#div_carousel_mover").fadeOut(300);
  /*$("#div_searched_box").fadeIn(400, function(){
      resize_page();
  })*/                       
}
          
var rightPadding = 0;
function resizeCreatingPopup(){
  
  
  if (gallery == true){
    rightPadding = 300;
  }
  var leftPadding = 65;
  var documentWidth = parseInt(document.body.clientWidth);
  var documentHeight = parseInt(document.body.clientHeight);  
  
  $("#draw").css("width", (documentWidth-56-rightPadding)+"px");
  $("#draw").css("height", (documentHeight-138)+"px");  

  if (gallery){
    $("#div_creation_popup_container #div_middle_right").css("height", (documentHeight-138)+"px");
    $("#div_btn_cancel").css("margin-right", 300+"px");
  }  


  $("#div_creation_popup_container .div_top_middle").css("width", (documentWidth-leftPadding)+"px");  
  $("#div_creation_popup_container .div_middle_middle_container").css("width", (documentWidth-leftPadding+9-rightPadding)+"px");
  $("#div_creation_popup_container .div_bottom_middle").css("width", (documentWidth-leftPadding)+"px");
  $("#div_creation_popup_container .div_middle_middle").css("width", (documentWidth-leftPadding+9-rightPadding)+"px");
  $("#div_creation_popup_container .div_middle_inside_top_middle").css("width", (documentWidth-leftPadding-5-rightPadding)+"px");
  $("#div_creation_popup_container .div_middle_inside_bottom_middle").css("width", (documentWidth-leftPadding-5-rightPadding)+"px");
  $("#div_creation_popup_container .div_middle_left").css("height", (documentHeight-138)+"px");
  $("#div_creation_popup_container .div_middle_inside_left").css("height", (documentHeight-152)+"px");
  $("#div_creation_popup_container .div_middle_inside_right").css("height", (documentHeight-152)+"px");
  $("#div_creation_popup_container .div_middle_middle_container").css("height", (documentHeight-138)+"px");     
  $("#div_creation_popup_container .div_middle_middle").css("height", (documentHeight-138)+"px");                
}

function showGallery(){
  gallery = true;
  var documentWidth = parseInt(document.body.clientWidth);
  var documentHeight = parseInt(document.body.clientHeight);  
  
  var leftPadding = 65;
  var rightPadding = 300;
  var speed = 250;
  $("#draw").css("width", (documentWidth-56-rightPadding)+"px");
     
  $("#div_creation_popup_container #div_middle_right").css("height", (documentHeight-138)+"px");
  $("#div_creation_popup_container #div_middle_right").animate({width: '310px'}, speed);
  
  $("#div_creation_popup_container .div_middle_middle_container").animate({width: (documentWidth-leftPadding+9-rightPadding)+'px'}, speed);
  $("#div_creation_popup_container .div_middle_middle").animate({width: (documentWidth-leftPadding+9-rightPadding)+'px'}, speed);
  $("#div_creation_popup_container .div_middle_inside_top_middle").animate({width: (documentWidth-leftPadding-5-rightPadding)+'px'}, speed);
  $("#div_creation_popup_container .div_middle_inside_bottom_middle").animate({width: (documentWidth-leftPadding-5-rightPadding)+'px'}, speed,function(){
    loadImageDirectory(baseDir);
    $("#div_middle_right_content").fadeIn(200);
  
  });
  
  $("#draw").css("width", (documentWidth-56-rightPadding)+"px");//animate({width: (documentWidth-56-rightPadding)+'px'}, speed);
    
    $("#div_btn_cancel").animate({marginRight: '298px'}, speed);  
}

function closeGallery(){
  gallery = false;
  var documentWidth = parseInt(document.body.clientWidth);
  var documentHeight = parseInt(document.body.clientHeight);  
  
  var leftPadding = 65;
  var rightPadding = 0;
  var speed = 250;        
  $("#div_middle_right_content").fadeOut(200, function(){

       
    $("#div_creation_popup_container #div_middle_right").css("height", (documentHeight-138)+"px");
    $("#div_creation_popup_container #div_middle_right").animate({width: '0px'}, speed);
    
    $("#div_creation_popup_container .div_middle_middle_container").animate({width: (documentWidth-leftPadding+9-rightPadding)+'px'}, speed);
    $("#div_creation_popup_container .div_middle_middle").animate({width: (documentWidth-leftPadding+9-rightPadding)+'px'}, speed);
    $("#div_creation_popup_container .div_middle_inside_top_middle").animate({width: (documentWidth-leftPadding-5-rightPadding)+'px'}, speed);
    $("#div_creation_popup_container .div_middle_inside_bottom_middle").animate({width: (documentWidth-leftPadding-5-rightPadding)+'px'}, speed);
      
    $("#div_btn_cancel").animate({marginRight: '5px'}, speed,function (){
      $("#draw").css("width", (documentWidth-56-rightPadding)+"px");
    })
  });  
}



function resizeOpenPopup(){  
  var leftPadding = 65;
  var documentWidth = parseInt(document.body.clientWidth);
  var documentHeight = parseInt(document.body.clientHeight);  
  //alert(documentWidth); 
  $("#play").css("width", documentWidth-20+"px");
  $("#play").css("height", documentHeight-62+"px"); 
  $("#div_settingcontainer").css("left", (documentWidth-400)/2+"px");    
  $("#div_open_popup_container .div_top_middle").css("width", (documentWidth-leftPadding+29)+"px");  
  $("#div_open_popup_container .div_middle_middle_container").css("width", (documentWidth-leftPadding+9+36)+"px");
  $("#div_open_popup_container .div_bottom_middle").css("width", (documentWidth-leftPadding+36)+"px");
  $("#div_open_popup_container .div_middle_middle").css("width", (documentWidth-leftPadding+9+36)+"px");
  $("#div_open_popup_container .div_middle_inside_top_middle").css("width", (documentWidth-leftPadding-5+36)+"px");
  $("#div_open_popup_container .div_middle_inside_bottom_middle").css("width", (documentWidth-leftPadding-5+36)+"px");
  
  
  $("#div_open_popup_container .div_middle_left").css("height", (documentHeight-62)+"px");
  $("#div_open_popup_container .div_middle_inside_left").css("height", (documentHeight-76)+"px");
  $("#div_open_popup_container .div_middle_inside_right").css("height", (documentHeight-76)+"px");
  $("#div_open_popup_container .div_middle_middle_container").css("height", (documentHeight-62)+"px");     
  $("#div_open_popup_container .div_middle_middle").css("height", (documentHeight-62)+"px");  
  
  $("#div_disable_opened").css("width", (documentWidth-20)+"px");
  $("#div_disable_opened").css("height", (documentHeight-62)+"px");  
    
  $("#div_show_alert_clear").css("left", (documentWidth-600)/2+"px");
  $("#div_show_alert_clear").css("top", (documentHeight-250)/2+"px");  
  
   
}

var penCompWidth = 0;
var fillCompWidth = 0;
var textCompWidth = 0;


function noPenColorOpacity(){
  changePenComponentWidth(64);
}

function allPenShow(){
  changePenComponentWidth(215);
}

function noBrushColorOpacity(){
  changeFillComponentWidth(64);
}

function allBrushShow(){      
  changeFillComponentWidth(215)
}


function allTextSetting(){
  changeTextComponentWidth(157);    
}

function noTextSetting(){
  changeTextComponentWidth(1);    
}

function noBrushSetting(){
  changeFillComponentWidth(1);
}

function noPenSetting(){
  changePenComponentWidth(1);
}




function changePenComponentWidth(Width){
  $("#div_change_width_pen_component").animate({width: Width+'px'}, 300);
}

function changeFillComponentWidth(Width){
  $("#div_change_width_fill_component").animate({width: Width+'px'}, 300);
}

function changeTextComponentWidth(Width){
  $("#div_change_width_text_component").animate({width: Width+'px'}, 300);
}

function duplicateSlide(folder, id){
    $("#div_image_alert").attr("class", "popUpImageLoading");
    $(".div_text_alert").html("Duplikují snímek ...");
    showAlertPopup(500, 160, false);      
    ajax_duplicate_slide(folder, id);  
}

var smer = [1,1];
var pos = [0,0];
var timerSaver = null;
function startSaverMoving(mode){ 
  $("#div_running_logo").css("display", "block");
  var pos = $("#"+mode).offset();
  var left = pos.left;
  var top = pos.top;
  var right = parseInt($("#"+mode).width())-284+left;//parseInt(document.body.clientWidth)-284;
  var bottom = parseInt($("#"+mode).height())-135+top;//parseInt(document.body.clientHeight)-135;
  timerSaver = setInterval("moveSaver("+right+", "+bottom+", "+left+", "+top+")", 7);                                    
    
}

function endSaverMoving(){
  $("#div_running_logo").css("display", "none");
  if (timerSaver != null){
    clearInterval(timerSaver);
  }
}

function moveSaver(right, bottom, left, top){
  if (pos[0] < left){
    smer[0] = 1;
    pos[0] = left+1;
  }else if (pos[0] > right){
    smer[0] = 0;
    pos[0] = right-1;
  }else if (pos[1] < top){
    smer[1] = 1;
    pos[1] = top+1;
  }else if (pos[1] > bottom){
    smer[1] = 0;
    pos[1] = bottom-1;
  }else{
    if (smer[0] == 1){
      pos[0]++;
    }else{
      pos[0]--;    
    }

    if (smer[1] == 1){
      pos[1]++;
    }else{
      pos[1]--;    
    }    
  }  
  $("#div_running_logo").css("left", pos[0]+"px"); 
  $("#div_running_logo").css("top", pos[1]+"px");       
}


