$(document).ready(function() {   
  
     $('#contentBG').css('opacity','0.8');

     $('#imgSR1').animate({
          left: '+1101px'
        }, 4500 );
     $('#imgSR2').animate({
          left: '+1101px'
        }, 5500 );
     $('#imgSR3').animate({
          left: '+1101px'
        }, 4500 );
     $('#imgSD1').animate({
          top: '+700px'
        }, 4500 );
     $('#imgSD2').animate({
          top: '+700px'
        }, 5500 );
     $('#imgSD3').animate({
          top: '+700px'
        }, 4500 );

  	$(function() {        
  		$("#sortable").sortable( 
        { 
        opacity: 0.7 ,
        revert: true, 
        scroll: true,
            update:function(e,ui) {
              var items = $(".ui-state-default");
              var photos = [];
              var add = '' ;
              $("#a").val('');
              
              for(var x=0; x<items.length; x++)
              {
              
                  var photo = {}
                  photo.id = items[x].id;   
                  addVal = $("#a").val();                     
                  $("#a").val(addVal+','+items[x].id);
                  add = add + items[x].id+':';
                  
              }

              $.ajax({
              url: "_menu.php?n="+add,
              cache: false
              });

            } 
        } 
      );
  		
     $('#block').css('opacity','0');
     $('#block').css('display','block');
        
     $('#block').delay(1500).animate({
          opacity: '+1'
        }, 900 );
  		
    $("#sortable").disableSelection();
    
    $('#prev').click(function() {
        $('#tabMenuMove').animate({
          top: '+=110px'
        }, 400 );
     });     		
    
    $('#next').click(function() {
        $('#tabMenuMove').animate({
          top: '-=110px'
        }, 400 );
     });  
    
    $('#prevB').click(function() {
        $('#tabMenuMoveB').animate({
          top: '+=110px'
        }, 400 );
     });     		
    
    $('#nextB').click(function() {
        $('#tabMenuMoveB').animate({
          top: '-=110px'
        }, 400 );
     });  
     
    $('#prevL').click(function() {
        $('#linkBoxMoveIn').animate({
          top: '+=110px'
        }, 400 );
     });     		
    
    $('#nextL').click(function() {
        $('#linkBoxMoveIn').animate({
          top: '-=110px'
        }, 400 );
     }); 
    
    $('#prevM').click(function() {
        $('#clrBoxInfoMenuIn').animate({
          top: '+=80px'
        }, 400 );
     });     		
    
    $('#nextM').click(function() {
        $('#clrBoxInfoMenuIn').animate({
          top: '-=80px'
        }, 400 );
     }); 
     
  	}); 
   
     $('#imgBack').click(function() {
        $('#hide').animate({
          opacity: '-0'
        }, 150, function() {
          $('#hide').css('display','none');
          $('#page_show').css('display','none');
        }); 
     });
        
     $('#block').delay(1500).animate({
          opacity: '+1'
        }, 900 );
        
     function hideBox(){
        $('#hide').css('opacity','0');
        $('#hide').css('display','block');
        $('#page_show').css('display','block');
        $('#hide').animate({
          opacity: '+0.75'
        }, 150 );
     }
     
     function run_box(f){

        $.ajax({
        url: "/_"+f+".php",
        cache: false,
        success: function(html){
          $("#linkBoxMoveIn").html("");
          $("#linkBoxMoveIn").append(html);
            $('#linkBoxMoveIn').animate({
            top: '0px'
            }, 400 );
        },
        beforeSend: function(html){
          $("#linkBoxMoveIn").html("");
          $("#linkBoxMoveIn").append('<img src="http://www.plikigrafiki.com/upload/styl68.gif" />');
        }
        });
        
     }

     $('#aLinkBack').click(function() {
       run_box('loginBoxDefault');  
     });
    
    run_box('loginBoxDefault');  

    $('#closeMSGBox').click(function() { 

      $('#hideBox').remove();
         
      $('#upHMsgBox').remove();

    });
    
    var timer = setInterval( showData, 5000);

    function showData() { 
        //alert('asd');
        var now = new Date();
        var nowMin = now.getMinutes();
        if(nowMin<10){nowMinV = '0'+nowMin;}else{nowMinV = nowMin;}
        var outStr = now.getHours()+':'+nowMinV;
        $("#dataTopBox").html(outStr);
  
    }
   
    var timer = setInterval( counterStart, 1000);

});         
    
    function counterStart(){
    
                  var items = $(".timer");
                  for(var x=0; x<items.length; x++)
                  {
    
                      var htmlId = items[x].id;
                      htmlStr = $('#'+htmlId).html();
                      
                      htmlArr = htmlStr.split(":");
    
                      thisH = htmlArr[0] * 3600;
                      thisM = htmlArr[1] * 60;
                      thisS = htmlArr[2] * 1;
                      
                      newTime = thisH+thisM+thisS-1;
                      
                      if(newTime > 0){
                      
                        h = Math.floor(newTime / 3600);
                        hCount = h * 3600;
                        restH = newTime - hCount;
                        m = Math.floor(restH / 60);
                        mCount = m * 60;
                        restM = restH - mCount;
                        s = restM;
      
                        if (h < 10) {
                            h = "0" + h ;
                        }
                        if (m < 10) {
                            m = "0" + m ;
                        }
                        if (s < 10) {
                            s = "0" + s ;
                        }
                        
                        $('#'+htmlId).html(h+':'+m+':'+s);
                        
                        if(newTime < 60 ){
                            $('#'+htmlId).css('color','#FFF700');
                            $('#'+htmlId).animate({
                              fontSize: '22px'
                            }, 500 );
                            $('#'+htmlId).animate({
                              fontSize: '18px'
                            }, 500 );
                        }  
    
                      }else{
                      
                        $('#'+htmlId).html('00:00:00');       
                        $('#'+htmlId).css('color','#333');
                        $('#box'+htmlId).css('background','transparent url(/img/bDDE.jpg) 0 0 repeat-x');
                        $('#desc'+htmlId).css('color','#004020');
                        $('#'+htmlId).css('fontSize','18px');
                      
                      }
    
                  }
    
    }

    function msgBox(a){ 
    
      var size_height_to = $('#top').height() + $('#bottom').height();
          
      var sizeWidthTo = screen.availWidth/2-150; 

      $('#top').before('<div id="upHMsgBox"><p class="mHideBoxB">'+a+'</p><p class="mHideBoxC"><img src="/img/sub_sea5.png" id="closeMSGBox" class="pointer" alt="Zamknij" /></p></div>');
      $('#upHMsgBox').css('left',sizeWidthTo);
      $('#upHMsgBox').css('display','block');
      
      $('#top').before('<div id="hideBox"></div>');
      $('#hideBox').css('height',size_height_to);
      $('#hideBox').css('display','block');
          $('#hideBox').animate({
            opacity: '+0.75'
          }, 500 );

    }
