var load = "<b>spracuvávam zmeny..</b>";

$(document).ready(function()
{ 
  
	$('#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")); 
    });
    
    jQuery.each($(".pageItem"), function()
    { 
    	var img = $(this).find("img:first"); 
    	img.remove();
    	if(img.attr("src")) $(this).prepend("<a href='"+$(this).find("h4 a").attr("href")+"'><img class='left' src='"+img.attr("src")+"' width='150' /></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>
		           */
		    });
	
	$.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 */ 
     
    if($("form #structureID").html())
    {
       //$("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 });
    });    
    
    
}); /*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);  
}

