var load = "<b>spracuvávam zmeny..</b>";

$(document).ready(function()
{ 

 
  $('.targetblank').attr("target","_blank");
	$('#menu ul ul').addClass("sub");
	$('#menu ul > li').addClass("main");
	$('.menu2 ul ul').addClass("sub2");
	$('.menu2 ul > li').addClass("main");
	$('#news div:first').addClass("sign");
	$('#news div:last').addClass("last");
	$('#breadcrumbs ul li a:first').parent().addClass("none");
	$("#setup").prepend("<div class='setupTop'><a href='http://www.deltro.cz' target='_blank' class='classLogoClick'>www.deltro.cz</a></div>");
    $("#leftCol").addClass("connectedSortable");
    $("#rightCol").addClass("connectedSortable");
    $(".spamprotection").val("125459");
    
    //prida k obrazkom tag title a text preberie z altu 
    jQuery.each($("img"), function()
    { 
    	$(this).attr("title",$(this).attr("alt")); 
    });
    
    //optionVoteResult
    jQuery.each($(".optionVoteResult"), function()
    { 
      
    	$(this).attr("style","width:"+Math.round(($(this).parent().find(".prc").html()*2))+"px"); 
    });
    
    
    jQuery.each($(".pageItem"), function()
    { 
    	var img = $(this).find("img:first"); 
    	img.remove();
    	if(img.attr("src")) $(this).prepend("<a href='"+$(this).find("h2 a").attr("href")+"'><img class='left' src='"+img.attr("src")+"' width='200' /></a>");  
    });; 
    
	
	$(".connectedSortable").sortable({
		handle: '.handle',
        connectWith: '.connectedSortable',   
        update: function(event, ui) {  
        serial = $(this).sortable("toArray"); 
        
        $.ajax({
               type: "POST",
               url: "/modules/boxs/ajax.php",
               data: "w=changePosition&fromID="+this.id+"&classFrom="+serial+"", 

               success: function(msg)
               {
                 $("#ajaxR").append(msg+"<hr/>"); 
               }
             });
           
           
        } 

    });
    
	 
	 
	//$("#categoryList").append("<div class='footer'></div>");
	
	$.listen('click','a.showHide',function(event) 
		    { 
		          var obj = $(this).parent().find("div.showHide"); 
		          if (obj.css('display') == 'none')
		          {
		            //obj.css('display','block');
		        	  obj.show("slow");
		          } else   /* block or undefined*/
		          {
		            //obj.css('display', 'none');
		        	  obj.hide("slow");
		          }
		           /*   tvar html
		            <div class='to je jedno'>
		             <a href='javascript://' class='showHide'>add category</a>
		             <div class='showHide hide'>
		               formulaaaaaaar
		             </div>
		            </div>
		           */
		    });
		    
	//showHideOnmouse
/*$('.showHideOnmouse').mouseover(function() {
   $('div.showHide').hide("slow");
   var obj = $(this).parent().find("div.showHide"); 
	 obj.show("slow"); 
});*/

$('.showHideOnmouse').click(function() {
	   $('div.showHide').hide("slow");
	   var obj = $(this).parent().find("div.showHide"); 
		 obj.show("slow"); 
	});
	    
	
  $.listen('click', 'a.viewInfo', function(event) {
     
      $(this).parent().find("div.viewInfo").remove(); 
      $(this).parent().append("<div class='viewInfo'><a href='javascript://' class='removeParent right'>X</a>"+$(this).attr("rel")+"<div>");
  
  });	    
  $.listen('click', 'a.removeParent', function(event) {
     
      $(this).parent().remove();  
  
  });	
	 
	
	$.listen('click','a.showHide2',function(event) 
		    { 
		          var obj = $(this).parent().parent().find("div.showHide2"); 
		          if (obj.css('display') == 'none')
		          {
		            obj.css('display','block');
		          } else   /* block or undefined*/
		          {
		            obj.css('display', 'none');
		          }
		            
		    });
	
   
  $(".closeParent").click(function()
  {
    $(this).parent().css('display', 'none');
  });

 $('.showhide .blockhide').hide();
       $('.showhide a.show').click(function()
       { 
         //$(this).parent().find('div.blockhide').hide('slow');   
         // alert($(this).parent().find('div.blockhide').css('display'));  
          var element = $(this).parent().find('div.blockhide');
         if (element.css('display') == 'block')
         {
           element.parent().removeClass('open');
           element.hide('slow');
         }  
         else
         {
           element.slideDown('slow'); 
           element.parent().addClass('open');
         }  
       }); 
        
        $('.minimalize').click(function()
         { 
           $(this).parent().addClass("minimize"); 
  
         }); 
         $('.maximize').click(function()
         { 
           $(this).parent().removeClass("minimize"); 
  
         }); 
       
         $("input[type='radio']").addClass('radioInput');
         
        /* $(".viewbigFoto").click(function()
           { 
               
	          var img = $(this).find("img");
	          alert(img.attr("style"));
	          img.attr("src",$(this).attr("rel"));
	          img.addClass("bigImg");
           }); */
         $(".jq_clikBig").click(function()
          {
        	 $(this).removeClass("jq_clikBig"); 
        	 $(this).addClass("origPhoto"); 
        	 changeUrlToRel($(this));
          });
         
         $(".photoProfil .small").click(function()
         {
        	 alert("click");
        	 var old =  $(this).parent().find(".big");
        	 old.css("display","block");
        	 if(old.width()>830) old.css("width","830px");
        	  
         });
         $(".photoProfil .big").click(function()
          {
        	  
            $(this).css("display","none");      	  
          });
         
         $("#first .userMiniBox:first").addClass("firstBox"); 
         
         $('.skryvany').hide();
         $('.show').click(function()
         {  
           if ($('.skryvany').css('display') == 'block') $('.skryvany').hide('slow');
           else $('.skryvany').slideDown('slow');
         }); 
          
         $(".showDebug").click(function()
                 { 
                   $("#setup .debug").css("display","block");      	  
                 });
                 
                 
  
   /* ak najdeme structureID vo formulare, posleme ho xhr a zistime co podporuje */ 
     
    
   $.listen('click','a.getPageSetupPro',function(event) 
    { 
      // $("form #structureID").parent().prepend("<div id='pageSetupPro'></div>");
      
       $.ajax({  
          type: "POST",
          url: "/modules/jquery/ajax.php", 
          data:"w=getPageSetupPro&structureID="+$("#structureID").val(),
          beforeSend: function()
          { 
             $("#pageSetupPro").html(load); 
          },   
          success: function(msg)
          {   
             $("#pageSetupPro").html(msg);
          } 
       });  
    });
      
     /* skryjeme galeriu */
     if($("#fotoGallery")) $("#fotoGallery").css("display","none");        
    /* pridame galeriu */
    $.listen('click','a.addGalleryWidget',function(event) 
    {  
          $("#fotoGallery").css("display","block"); 
           var structureID = $("#structureID").val();
           
           getPhotoList(structureID);  
        
    });
     /* ak uzivatel nahra foto refreshneme zoznam fotiek*/
      
    
    /*window.setInterval("refreshAllData()", 20 * 1000);*/
 
     
    $.listen('click','a.promtAndAction',function(event) 
    {  
    	var valueArr = $(this).attr("rel").split(";");
    	
    	$.prompt(valueArr[0],{ buttons: { 'ANO': valueArr[1], 'NE':false }, callback: promtAndActioncallback });
    });    
    
  
  //udrzat ostale online, koli rovnakemu cardID pri dlhej necinosti alebo aby to neodhlasilo zbytocne
   
  if($(".setupTop").html())
  {
    if(!$(".setupTop .time").html())
    {
        var currentTime = new Date()
        var hours = currentTime.getHours()
        var minutes = currentTime.getMinutes();
        if(minutes < 10) minutes = "0"+minutes;
       $(".setupTop").append("<span class='time' style='display:block;position:absolute;right:10px;color:white'>"+hours+":"+minutes+"</span>");
    } 
     
  }
  window.setInterval("refresSession()", 1000 * 60 * 10); //kazdych 10min = 1000 * 60 * 10 
  
    
}); /*dokumen ready end*/

function promtAndActioncallback(v,m,f)
{
	//ak klikol ano mame hodnotu v ak nie nic sa nedeje, okno sa zavre
	if(v)
	{
		window.location.href=v;
	}
		
}
 
function importScript(url){
    var tag = document.createElement("script");
    tag.type="text/javascript";
    tag.src = url;
    document.body.appendChild(tag);
}

function getPhotoList(structureID)
{
   $.ajax({  
          type: "POST",
          url: "/modules/jquery/ajax.php", 
          data:"w=addGalleryWidget&structureID="+structureID,
          beforeSend: function()
          { 
             $("#pageSetupPro").html("Prepočitávam.."); 
          },   
          success: function(msg)
          {   
             $("#pageSetupPro").html(msg);
          }   
       });
}

function updatePhotoList()
{
   
  var structureID = $("#structureID").val();     
  getPhotoList(structureID);  
}
function refresSession()
{
   
    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes();
    if(minutes < 10) minutes = "0"+minutes;
     
   
     $.ajax({  
          type: "POST",
          url: "/modules/jquery/ajax.php", 
          data:"w=refreshSession",
          beforeSend: function()
          { 
             if($(".setupTop .time").html()) $(".setupTop .time").html("refreshSession"); 
          },   
          success: function(msg)
          {   
            if($(".setupTop .time").html()) $(".setupTop .time").html(""+hours+":"+minutes+"");
          }   
       });
}

