Autor: Só Eu Penso Isso | Publicado: 2011-06-21T17:05:00-07:00

        
    var ready=0;                                                                //do tego by init() byl odpalany po zaladowaniu xmli
    var genealogy=new Array(3);
    var names=new Array();
    var trashHelper=1;
    var progress=new Array();
    var connections1=new Array();
    var connections2=new Array();

    $(document).ready(function(){
      xmlReadGenealogy("library.xml"); 
      xmlReadNames("en_us.xml");
      loadProgress();
      $('#options ul').css({marginLeft: -(($('#options ul').width())-($('#options span').width()))-1}); 
    });
    
    $(window).resize(function()
    {
      width=$(window).width();
      height=$(window).height();
      if(width>=1050)libWidth=580;
      else if(width>=900)libWidth=450;
      else if(width>=640) libWidth=306;
      else libWidth=176; 
      if(width<400)width=400;
      if(height<350)height=350;
      $('body').css({width: width, height: height});
      $('#table').css({width: (width-libWidth), height: (height-35), marginTop: 35});
      $('#library').css({height: (height-35), width: libWidth});
      $('#statusBar').css({width: (width-libWidth)});
      $('#trash').css({top: (height-180), left:(width-libWidth-155)});
      $('#search').css({width: (libWidth-146)});
      $('.tablebox').each(function(){
        if(ifLeaveTable(this))$(this).fadeOut("normal",function(){$(this).remove()});
      });
    });
    
    $('#options span').live('click',function(){
      $('#options ul').toggle('fast');
    });
    
    $('#trash').live('mouseenter mouseleave', function(event) {
      switch(event.type){
        case 'mouseenter': if(trashHelper==1){$('#trash img').animate({height: 60, width: 50, marginTop: 90, marginLeft: 90}, "fast");} trashHelper=0; break;
        case 'mouseleave' : $('#trash img').animate({height: 30, width: 25, marginTop: 120, marginLeft: 115}, "fast",function(){trashHelper=1;}); break;
      }
    });
      
    $('#trash img').live('click',function(){
      $('.tablebox').each(function(){$(this).fadeOut("normal",function(){$(this).remove()})});
    });
    
    $('[type="checkbox"]').live('click',function(){saveProgress(); if($('#autosort:checked').val()!=null)librarySort();});
    $('#searchDel').live('click',function(){$('#search').attr('value',''); searchInLibrary();});
    
    $('#search').live('keyup focusin', function(event) {
      switch(event.type){
        case 'keyup': searchInLibrary(); break;
        case 'focusin': $('#search').attr('value',''); break;
      }
    });
    $(window).keyup(function(event){if(event.which==27){$('#search').attr('value',''); searchInLibrary();}});
    
    
    function init()
    {
      width=$(document).width();
      height=$(document).height();
      if(width>=1050)libWidth=580;
      else if(width>=900)libWidth=450;
      else if(width>=640) libWidth=306;
      else libWidth=176; 
      $('body').css({width: width, height: height});
      $('#table').css({width: (width-libWidth), height: (height-35), marginTop: 35});
      $('#library').css({height: (height-35), width: libWidth});
      $('#statusBar').css({width: (width-libWidth)});
      $('#trash').css({top: (height-180), left:(width-libWidth-155)});
      $('#search').css({width: (libWidth-146)});
      $('#trash').droppable({
        over: function(event, ui){
          $('#trash img').animate({height: 100, width: 85, marginTop: 50, marginLeft: 50}, "fast"); trashHelper=0;},
        out: function(event, ui){
          $('#trash img').animate({height: 30, width: 25, marginTop: 120, marginLeft: 115}, "fast"); trashHelper=1;},
        drop: function(event, ui){
          $(ui.helper).fadeOut("normal",function(){$(ui.helper).remove()})
          $('#trash img').animate({height: 30, width: 25, marginTop: 120, marginLeft: 115}, "fast");}
      });
      
      addLibraryContent(-1);
      $("#progress").html('progress: '+progress.length+"/"+(names.length-1));
    }
    
    function addLibraryContent(elements)
    {
      content='';
      if(elements==-1)elements=progress;
      
      for(i=0;i<elements.length;i++)
      {
        div='';
        content+=div;  
      }
      $('#library').html(content);
      
      $('.libbox').each(function(){                                             //dodawanie zawartosci do boxow
        createBoxContent(this);
      });
      $('.libbox').draggable({helper: "clone", scroll: false, 
        stop: function(event,ui){
          if((ui.offset.top < height-265) || (ui.offset.left < width-libWidth-250))
          createNewTableBox($(this).attr('rel'),ui.offset,1,1);
        }
      });
    }
    
    function createNewLibraryBox(id)
    {
      div='';
      $('#library').append(div);
      createBoxContent('.libbox:last');
      $('.libbox:last').fadeIn('slow');
      progress.push(id);
      saveProgress();
      $('.libbox:last').draggable({helper: "clone", scroll: false,
        stop: function(event,ui){
          createNewTableBox($(this).attr('rel'),ui.offset,1,1);
        }
      });
    }
    
    function createNewTableBox(id,position,lp,checkJustDropped)                                  //lp zapobiega uduszeniu sie nawzajem bliźniaków
    {
      x=position.left+lp*30;
      y=position.top+lp*40;
      if(checkJustDropped) div=''; 
      else div='';
      $('#table').append(div);
      createBoxContent('.tablebox:last');
      if(checkJustDropped){
        justDropped=$('#justDropped');
        checkConnections(justDropped);
        justDropped.removeAttr("id");  
      }
      else $('.tablebox:last').fadeIn('slow');
      
      $('.tablebox:last').draggable({scroll: false, stop: function(event, ui){checkConnections(this);}});
      //usunięcie wyszukiwania
      if($('#search').attr('value').length>0){
        addLibraryContent(-1);
        if($('#search').attr('value')!='type here to search...')$('#search').attr('value','');
      }
    }
    
    function checkConnections(el1)
    {
      if(ifLeaveTable(el1))$(el1).fadeOut("normal",function(){$(el1).remove()});
      else{
        el2=ifSex(el1);                                                           //sprawdzenie czy el1 sie z kims puscil
        kk=0;                                                                     //kolejny krasnoludek
        if(el2!=0 && el2!=-1){                                                    //jesli sie puscil
          id1=$(el1).attr('rel');
          id2=$(el2).attr('rel');
          children=sex(id1,id2);                                                  //sprawdzamy czy się przynajmniej dobrze zabezpieczyl
          len=children.length;
          if(len>0){                                                              //jezeli jednak nie
            position=$(el1).offset();
            for(ii=0;ii<len;ii++){
                kk++;
                if(kk==1)removeParents(el1,el2);
                createNewTableBox(children[ii],position,ii,0);                    //to tworzymy wszystkie jego dzieci
                if(!include(progress,children[ii])){
                  createNewLibraryBox(children[ii]);
                }
            }
            if($('#autosort:checked').val()!=null)librarySort();
          }  
        }
      }
    }
    
    function ifSex(element)
    {
      x1=$(element).css("left").replace("px", "");
      y1=$(element).css("top").replace("px", "");
      ret=0;
      $('.tablebox').each(function(){
        if(this!=element && $(this).attr("id")!="justDropped"){
          x2=$(this).css("left").replace("px", "");
          y2=$(this).css("top").replace("px", "");
          
          if(Math.abs(x2-x1)<50 && Math.abs(y2-y1)<50){  
            if(ret==0)ret=this;                                                 //jezeli nic juz wczesniej nie zwracal to zwroc
            else ret=-1;                                                        //inaczej powiedz ze za duzo
          }
        }
      });
      return ret;
    }
    
    function ifLeaveTable(el)
    {
      x=parseInt($(el).css("left").replace("px", ""))+50;
      y=parseInt($(el).css("top").replace("px", ""))+55;
      b=20;
      if(x=width-libWidth || y<b+35 || height-y < b) return 1;
      else return 0; 
    }
    
    function sex(mother, daddy)
    {
      ret=new Array();
      
      if(mother<daddy){id1=mother; id2=daddy;}else{id2=mother; id1=daddy;}
      helper=0;
      for(i=0;i<connections1.length;i++)if(connections1[i]==id1 && connections2[i]==id2){helper=1; break;}
      
      if(helper==0 || $('#combine:checked').val()==null)
      {  
        if(helper==0){connections1.push(id1); connections2.push(id2);}
        len=genealogy[0].length;
        for(i=0;i<len;i++)
        {
          if(genealogy[1][i]==mother)
            if(genealogy[2][i]==daddy){
              ret.push(genealogy[0][i]);
              continue;                                                          
            }
          if(genealogy[2][i]==mother)
            if(genealogy[1][i]==daddy)
              ret.push(genealogy[0][i]);
        }
      }
      return ret;
    }
    
    function removeParents(el1,el2)
    {
      $(el1).fadeOut('normal');
      $(el2).fadeOut('normal');
      setTimeout(function(){$(el1).remove(); $(el2).remove();},400);
    }
    
    function createBoxContent(el){
      id=$(el).attr('rel');
      div=''+names[id]+'';
      $(el).html(div);
    }
    
    function loadProgress()
    {
      if(!localStorage.getItem("progress"))progress=[1,2,3,4];
      else progress=localStorage.getItem("progress").split(",");
      
      if(!localStorage.getItem("connections1"))makePastConnections(0);
      else{
        connections1=localStorage.getItem("connections1").split(",");
        connections2=localStorage.getItem("connections2").split(",");
      }
      
      if(!localStorage.getItem("autosort"))$('#autosort').attr('checked','true');
      else{
        value=localStorage.getItem("autosort");
        if(value=='false')$('#autosort').removeAttr('checked');
        else $('#autosort').attr('checked','true'); 
      }
      if(!localStorage.getItem("combine"))$('#combine').removeAttr('checked');
      else{
        value=localStorage.getItem("combine");
        if(value=='false')$('#combine').removeAttr('checked');
        else $('#combine').attr('checked','true'); 
      }
    }
    
    function saveProgress()
    {
      localStorage.setItem("progress",progress);
      $("#progress").html('progress: '+progress.length+"/"+(names.length-1));
      
      localStorage.setItem("connections1",connections1);
      localStorage.setItem("connections2",connections2);
      
      localStorage.setItem("autosort",$("#autosort").attr("checked"));
      localStorage.setItem("combine",$("#combine").attr("checked"));
    }
    
    function resetProgress()
    {
      if(confirm("You mean seriously?!")==true){
        progress=[1,2,3,4];
        connections1=[];
        connections2=[];
        saveProgress();
        addLibraryContent(-1);
        $('.tablebox').remove();
      }
    }
    
    function include(arr, obj){
      for(j=0; j<arr.length; j++){
        if (arr[j] == obj)return true;
      }
    }
    
    function librarySort()
    {
      tab = new Array();
      k=0;
      for(i=0; i<progress.length;i++)tab[i]=names[progress[i]];
      tab.sort();
      for(i=0;i<tab.length;i++){
        for(j=0;j<names.length;j++)if(names[j]==tab[i])k=j;
        progress[i]=k;
      }
      for(i=0; i<progress.length;i++)if(progress[i]<5){progress.splice(i,1); i--;}
      progress.unshift(1,2,3,4);
      saveProgress();
      addLibraryContent(-1);
    }
    
    function makePastConnections(gen)
    {
      if(gen==0)xmlReadOldGenealogy();
      else{
        for(i=0;i<gen[0].length;i++){
          if(include(progress,gen[0][i])){
            if(gen[1][i]<gen[2][i]){id1=gen[1][i]; id2=gen[2][i];} else{id2=gen[1][i]; id1=gen[2][i];}
            connections1.push(id1);
            connections2.push(id2);
          }
        }
        saveProgress();   
      }
    }    
    
    function searchInLibrary()
    {
      newLibContent = new Array();
      tekst=$('#search').attr('value');
      if(tekst.length>0){
        for(i=0;i<progress.length;i++){
           if(names[progress[i]].slice(0,tekst.length)==tekst) newLibContent.push(progress[i]);
        }
        addLibraryContent(newLibContent);
      }
      else addLibraryContent(-1);
    }
    
    function devMode(state){
      if(state=='on'){
        $('#dev').fadeIn('normal');
      }
      else if(state=='off'){
        $('#dev').fadeOut('normal');
      }
    }
   
  
   
    @font-face {
      font-family: 'CabinRegular';
      src: url('fonts/Cabin-Regular-webfont.woff') format('woff'),
           url('fonts/Cabin-Regular-webfont.ttf') format('truetype'),
           url('fonts/Cabin-Regular-webfont.svg#CabinRegular') format('svg');
      font-weight: normal;
      font-style: normal;
    } 
  
    body,html{
      background:#000;
      margin:0;
      overflow:hidden;
      -webkit-user-select:none;
      font-family:CabinRegular,'Lucida Grande','Lucida Grande Unicode',Helvetica,Arial,Verdana,Sans-Serif;
    }
  
    .box{
      width:100px;
      height:110px;
      cursor:move;
      background:rgba(255,255,255,0.7);
      z-index:10;
      -webkit-border-radius:10px;      
    }
    
    .boxContent{
      width:100px;
      height:110px;
      text-align:center;
      font-family:CabinRegular,Arial,Sans-Serif;
      color:#666;
      font-size:12pt;
      line-height:0.95;
    }
    
    .boxImg{
      width:74px;
      height:74px;
      margin:5px 13px 0px 13px;
    }
    
    .libbox{
      z-index:20 !important;
      width:100px;
      height:110px;
    }
    
    .ui-draggable-dragging{
      z-index:20;
    }
    
    #library .box{
      margin:40px 0 0 30px;
      float:left;
    }     
    
    #table .box{
      position:absolute;
    }
    
    #table{
      float:left;
      background:#111;
    }
    
    #library{
      width:450px;       
      padding-top:25px;
      padding-bottom:10px;
      float:left;
      background:#333;
      overflow-y:scroll;
      overflow-x:hidden;
    }
    
    #statusBar{
      width:100%;
      height:35px;
      position:absolute;
      top:0;
      background:#ddf;
      z-index:100;
    }
    
    .statusBarChild{
      height:35px;
      float:left;
    }
    
    #suggest{
      padding-top:8px;
    }
    
    #suggest a{
      text-decoration:none;
      color:#333;
      text-shadow: 1px 1px #ccc
    }    
    #options{
      float:right;
      margin:7px 10px 0 0;
      width:90px;
      height:28px;
    }
    
    #options span{
      width:70px;
      padding:4px 10px;
      font-size:12px;
      border-radius:5px;
      background:#333;
      color:#fff;
      cursor:pointer;
    }
    
    #options img{
      position:relative;
      top:3px;
      left:3px;
    }
    
    #options ul{
      list-style:none;
      width:350px;
      margin:0; /* correct in document.ready */
      padding:15px 10px;
      background:#333;
      font-size:12px;
      color:#fff;
      border-radius:5px 0 5px 5px;
      display:none;
      position:absolute;
    }
    
    #options li{
      margin:3px 0;
    }
    
    #progress{
      height:27px;
      float:right;
      font-size:16px;
      font-weight:normal;
      color:#333;
      margin:8px 20px 0 0;
      text-shadow: 1px 1px #ccc
    }
    
    #clearTable, #share{
      display:none;
    }
    
    #trash{
      width:140px;
      height:165px;
      position:absolute;
      z-index:5;
      cursor:pointer;
    }
    
    #trash img{
      width:25px;
      height:30px;
      margin: 120px 0px 0px 110px;
    }
    
    p{
      color:#fff;
      position:fixed;
      top:50;
      left:50;
    }

    #resetProgressBut{
      background:#ccc;
      border-radius:5px;
      border:0;
      padding:4px 10px;
      color:#333;
      margin-top:5px;
      cursor:pointer;
    }
    
    #search{
      height:22px;
      border-radius:10px 0 0 10px;
      border:1px solid #999;
      padding:5px 10px;
      float:left;
      outline: none;
      font-family:Helvetica,Arial,Sans-Serif;
      font-size:13pt;
      font-weight:bold;
      color:#999;
    }
    
    #searchDel{
      float:left;
      background:#999;
      border-radius:0 10px 10px 0;
      color:#fff;
      width:34px;
      height:34px;
      cursor:pointer;
    }
    
    #dev{
      display:none;
    }
  
  
    
    Suggest new elements!
    
      Options 
      
        
          
          Automatically sort elements alphabetically
        
        
          
          Don't combine elements thet were already combined
        
        
          
        
      
    
    share
    kill all
    progress: 4/200
  
  
    
   
  
    
      
      
    
    
   
  waterfireearthair
  
    
    
      
    
   
  
  
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-1421335-29']);
    _gaq.push(['_trackPageview']);
  
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  
   
  
  
  
  var clicky_site_ids = clicky_site_ids || [];
  clicky_site_ids.push(66435176);
  (function() {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.src = '//static.getclicky.com/js';
    ( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
  })();