1. var layer_counter = 0;
  2. var layer_id = 0;
  3. var cnt = 0;
  4.  
  5. var selected = 0;
  6. var layer_group_selected = 0;
  7. var z_index = 1;
  8. var layer_selected = 0;
  9. var group_selected = new Array();
  10. var test = 0;
  11. var tabs = false;
  12.  
  13. var gcdf = {
  14.     id: null,
  15.     version: 0.2,
  16.     name: null,
  17.     resources: [],
  18.     toString: function(){
  19.         return "Id: "+this.id+", "+
  20.                "Name: "+this.name+", "+
  21.                "Version: "+this.version+", "+
  22.                "Resources: "+this.resources.length+" Nodes";
  23.     }
  24. }
  25.  
  26. var dump;
  27.  
  28. $R = $('div.resources');   
  29.  
  30. $this = { // for use for global scope;
  31.  
  32.     file_name : false,
  33.     files : null
  34.    
  35. };
  36.  
  37. $($(this)).click(function(argument) {
  38.     $(this).on('hover',function(){
  39.         $(this).click();
  40.         $("#delete")
  41.     })
  42. });
  43.  
  44. //----------------------------- New -------------------
  45. var selected_layer = "";
  46. var selected_folder = "";
  47.  
  48. var game;
  49. var backStack = [];
  50. function Sprite(data){
  51.     for (var key in data)
  52.         this[key] = data[key];
  53. }
  54. var fileCache = [];
  55. var modified = false;
  56.  
  57. function getModified(){
  58.     return modified;
  59. }
  60.  
  61. $(document).ready(function () {
  62.  
  63.     ///$.ajaxSetup({cache: false});
  64.  
  65.     $("#sidebar #sortable").sortable({
  66.         forceHelperSize: true,
  67.         forcePlaceholderSize: true,
  68.         revert: true,
  69.         revert: 150,
  70.         placeholder: "highlight panel",
  71.         axis: "y",
  72.         tolerance: "pointer",
  73.         cancel: ".content"
  74.     }).disableSelection();
  75.  
  76.     // $("#sidebar #sortable .panel").resizable({
  77.     //  cancel: ".content",
  78.     //  handles: "s"
  79.     // });
  80.  
  81.     // // TODO: layer group sortable revert glich.
  82.   //   $("#layer_groups").sortable({
  83.   //    forceHelperSize: true,
  84.     //  forcePlaceholderSize: true,
  85.     //  revert: true,
  86.     //  revert: 150,
  87.   //       placeholder: "highlight",
  88.   //       axis: "y",
  89.   //       tolerance: "pointer",
  90.   //   }).disableSelection();
  91.  
  92.  
  93.     // Make the layers draggable / resizable only once
  94.     $("#main #canvas").on("mouseover", ".layer:not(.ui-resizable)", function(event){
  95.         $(this).draggable({
  96.             snap: ".layer",
  97.             stop: function( event, ui ){
  98.                 var id = $(this).attr("data-id");
  99.                 gcdf.resources.getById(id).setCoordinates(
  100.                     $(this).position().left,
  101.                     $(this).position().top
  102.                 );
  103.                 modified = true;
  104.             }
  105.         }).resizable({
  106.             snap: ".layer",
  107.             handles: "all",
  108.             zIndex: 0,
  109.             stop: function( event, ui ){
  110.                 var id = $(this).attr("data-id");
  111.                 console.log(id);
  112.                 gcdf.resources.getById(id).setDimensions(
  113.                     $(this).width(),
  114.                     $(this).height()
  115.                 );
  116.                 modified = true;
  117.             }
  118.         });
  119.     }).on("click", '.layer', function(){
  120.    
  121.         //layer_selected = $(this);
  122.  
  123.         //Asume that something has a selected layer.
  124.         //$('.selected').removeClass('.selected');
  125.         //$('.inner_layer', this).get(0).addClass('.selected');
  126.  
  127.     });
  128.  
  129.     // Make the (LIVE) layers draggable only once
  130.     $("#live_resources").on("mouseover", '.draggable', function(event){
  131.         $(this).draggable({
  132.             cancel: "div.placeholder, input, button",
  133.             containment: "document",
  134.             scroll: false
  135.         });
  136.     });
  137.    
  138.  
  139.     x = 0;
  140.     //$('#menubar li a').each(function(){
  141.         //console.log($(this).html());
  142.     //});
  143.  
  144.     var tabCounter = 2;
  145.  
  146.     /*$('#container_id').fileTree({
  147.         root: '../ckge/',
  148.         script: './filetree/jqueryFileTree.php',
  149.         expandSpeed: 300,
  150.         collapseSpeed: 300,
  151.         multiFolder: true
  152.     }, function(file) {
  153.  
  154.         efile = file.split("/");
  155.         efile = efile[efile.length-1];
  156.  
  157.         console.log('ckge/'+file);
  158.  
  159.         var tabTitle = efile+' '+$R.find('.close-tab').outerHTML(),
  160.             tabContent = $R.find('.tabftmp').attr('src','textedit/editor.php?file=ckge/'+file).addClass("tabs-" + tabCounter).outerHTML(), //<iframe src="http://localhost/game/textedit/editor.php?file='.file.'"></iframe>',
  161.             tabTemplate = $R.find('.tabtemp').clone();
  162.        
  163.         var id = "tabs-" + tabCounter,
  164.             li = $(tabTemplate);
  165.             $(tabTemplate).find('a').attr('href','#'+id).append(tabTitle);
  166.             //$(li).hide();
  167.  
  168.         tabs.find( ".ui-tabs-nav" ).append(li);
  169.         tabs.append('<div id="'+id+'">' +tabContent+ '</div>');
  170.         tabs.tabs("refresh");
  171.  
  172.         $(".ui-tabs-nav li #ui-id-"+tabCounter).trigger('click');
  173.         tabCounter++;
  174.  
  175.     });
  176.  
  177.     $('.close-tab').on('click',function(){
  178.         var panelId = $( this ).closest( "li" ).fadeOut('fast',function(){$(this).remove()}).attr("aria-controls");
  179.         $( "#" + panelId ).fadeOut('fast', function(){
  180.             $(this).remove();
  181.             tabs.tabs("refresh");
  182.         });
  183.     });*/
  184.  
  185.     /*$('.layers').css({ss
  186.         'top': top,
  187.         'left': left = $(document).width() - $('.layers').width() - 25,
  188.     });
  189.    
  190.     $('.materials').css({
  191.         'top': top + 30 + $('.layers').height(),
  192.         'left': left,
  193.     });*/
  194.    
  195.    
  196.     //$(".materials_browser").resizable({ minHeight: 132, minWidth: 126 })
  197.        
  198.  
  199.     $(".draggable").draggable({
  200.         cancel: "div#scrolling, .content",
  201.         containment: "document"
  202.     });
  203.  
  204.     $('.resizable').resizable({
  205.         handles: "all",
  206.         zIndex: 0,
  207.         containment: "document"
  208.     });
  209.    
  210.  
  211.     // $("#game_preview, #code_editor").draggable({
  212.     //  start: function(event, ui) {  $('.iframe_fix').css('display','block');  },
  213.     //  stop: function(event, ui) { $('.iframe_fix').css('display','none');  }
  214.     // });
  215.  
  216.     $("#code_editor").resizable({
  217.         resize: function(event, ui) { editor.resize(); }
  218.     });
  219.  
  220.     $("#sidebar #layers").on("click", ".layer", function(e){
  221.  
  222.         $(".layer.selected").removeClass("selected");
  223.         $(this).addClass('selected');
  224.  
  225.         var classes = $(this).attr("class");
  226.             classes = classes.split(" ");
  227.         selected_layer = "."+classes[1];
  228.         e.stopPropagation();
  229.  
  230.     });
  231.  
  232.     $("#sidebar #layers").on("click", ".folder", function(e){
  233.  
  234.         $(".folder.selected").removeClass("selected");
  235.         $(this).addClass('selected');
  236.  
  237.         var classes = $(this).attr("class");
  238.             classes = classes.split(" ");
  239.         selected_folder = "."+classes[1];
  240.         e.stopPropagation();
  241.  
  242.     });
  243.    
  244.     $("#tabs").tabs();
  245.     $(document).on('dragstart', "img", function(event) {
  246.         event.preventDefault();
  247.     });
  248.  
  249.     $(window).bind('beforeunload', function(){
  250.         return 'Changes have not been saved!';
  251.     });
  252.    
  253.     // $(".draglayer").draggable();
  254.     // tabs = $("#tabs").tabs();
  255. }); // Document ready // Main Meniu
  256.  
  257.  
  258. var new_game_submit = false;
  259. $("#new_game form").on("submit",function(e){
  260.  
  261.     if( new_game_submit == false ){
  262.  
  263.         new_game_submit = true;
  264.         var name = $(this).find("input[name=name]").val();
  265.  
  266.         parent = $(this).find("button")
  267.         parent.addClass("loading");
  268.  
  269.         createFolder(name,obj.id,function(result){
  270.             $("#new_game").fadeOut("fast",function(){
  271.                 $('.fader').fadeOut("fast");
  272.                 $("#new_game input[name=name]").val("");
  273.                 if(obj.children == undefined )
  274.                     obj.children = [];
  275.                 obj.children.unshift(result);
  276.                 getGames(obj);
  277.                 new_game_submit = false;
  278.                 parent.removeClass("loading");
  279.             });
  280.         });
  281.  
  282.     }
  283.  
  284.     e.preventDefault();
  285. }); // Creating a new Game
  286.  
  287.  
  288. $("#main").on("click", function(e){
  289.  
  290.     selected_folder = "";
  291.     $(".folder.selected").removeClass("selected");
  292. });
  293.  
  294.  
  295. $("#main #canvas").on("dblclick", ".layer", function(e){
  296.    
  297.     $(this).addClass("selected");
  298.     e.stopPropagation();
  299. });
  300.  
  301.  
  302. $('.new_folder').click(function(){
  303.  
  304.     dialog("Create new folder","Enter your folder name","_input", {
  305.        
  306.         'OK' : function(){
  307.            
  308.             var reply = $('.dialog_input').val();
  309.  
  310.             if( reply != null && reply != "" ){
  311.  
  312.                 var name = "fn_"+reply.split(' ').join('_');
  313.                 var parent = "";
  314.  
  315.                 if(selected_folder != "" ){
  316.                     parent = selected_folder+" .content";
  317.                 }
  318.  
  319.                 $R.find(".folder").clone()
  320.                     .addClass(name).find("h3").html(reply).end()
  321.                     .appendTo("#layer_groups "+parent);
  322.  
  323.                 $R.find(".folder_group").clone()
  324.                     .addClass(name).appendTo('#canvas '+selected_folder);
  325.  
  326.             }
  327.  
  328.         }
  329.  
  330.     });
  331. }); // Create a new folder group
  332.  
  333.  
  334. $('.new_layer').click(function(){
  335.  
  336.     dialog("Create new layer","Enter your layer name","_input", {
  337.        
  338.         'OK' : function(){
  339.            
  340.             var reply = $('.dialog_input').val();
  341.  
  342.             if( reply != null && reply != "" ){
  343.  
  344.                 var name = "ln_"+reply.split(' ').join('_');
  345.                 var parent = "";
  346.  
  347.                 if(selected_folder != "" ){
  348.                     parent = selected_folder+" .content";
  349.                 }
  350.  
  351.                 $R.find(".layer").clone()
  352.                     .addClass(name).html(reply)
  353.                     .appendTo("#layer_groups "+parent);
  354.  
  355.                 $R.find(".layers_group").clone()
  356.                     .addClass(name).appendTo('#canvas '+selected_folder);
  357.  
  358.             }
  359.  
  360.         }
  361.  
  362.     });
  363. }); // Create a new layer group
  364.  
  365.  
  366. $('#layer_groups').on('div','click', function(event){
  367.  
  368.     // Reset to make sure that not two are selected
  369.     //$('.selected').removeClass('selected');
  370.  
  371.     $(this).addClass('selected');
  372.    
  373.     console.log(this);
  374. });
  375.  
  376. $('#filebrowser').on('click','li.folder',function(e){
  377.  
  378.     var index = $(this).attr('index');
  379.     var html = "";
  380.    
  381.     if( $(this).hasClass('back') ) {
  382.      
  383.       // Set the to the old list.
  384.       game = backStack.pop();
  385.       $this.files = game;
  386.       if(backStack.length != 0){
  387.         html = "<li class='folder back'>back</li>";
  388.       }
  389.  
  390.     } else {
  391.  
  392.       // Store current level for return;
  393.       backStack.push(game);
  394.  
  395.       // Move the level up one;
  396.       game = game[index];
  397.       $this.files = game;
  398.  
  399.       // Add a default back button
  400.       html = "<li class='folder back'>back</li>";
  401.  
  402.     }
  403.  
  404.     html = html + inside(game.children);
  405.  
  406.     $('#filebrowser').html(html);
  407.     e.stopPropagation();
  408. }); // When you click on folder.
  409.  
  410.  
  411. /* Fade in any window with correct class "open"
  412.    (optional) provide "fade" to have fader
  413.    Eg: class="open test_window fader" */
  414. $("button.open, a.open").on("click", function() {
  415.    
  416.     var name = $(this).attr('class');
  417.         name = name.split(' ');
  418.  
  419.     $('#'+name[1]).center().css('z-index',z_index++).fadeIn('fast');
  420.        
  421.     if( name[2] == "fade" ){
  422.         $('.fader.panels').css('z-index',z_index-2).fadeIn('fast');
  423.     }
  424.  
  425. });
  426.  
  427. $('.list_of_games').on("click",".game",function(){
  428.     $('.selected').removeClass("selected");
  429.     $(this).addClass("selected");
  430. });
  431.  
  432. $('.list_of_games').on("dblclick",".game",function(){
  433.  
  434.     var index = $(this).attr('id');
  435.    
  436.     game = obj.children[index];
  437.     if(game.children === undefined)
  438.         game.children = [];
  439.    
  440.     $('#filebrowser').append(inside(game.children));
  441.     getImages(game.children);
  442.     getScripts(game.children);
  443.     //alert(1);
  444.  
  445.     $('#intro').fadeOut('fast');
  446.     $('#body_container').fadeIn('fast');
  447.     //$('.selected').removeClass("selected");
  448.  
  449.     //alert($(this).html());
  450.  
  451. }); // Show main panel of double click of game.
  452.  
  453. $("#canvas").on('mousemove', function(e){
  454.    
  455.     if (e.ctrlKey){
  456.  
  457.         var img = $(this).find('.loltest')
  458.        
  459.         if( img.length == 0 ){
  460.            
  461.             $('#material_placeholder img').clone()
  462.                 .addClass("loltest")
  463.                 .hide()
  464.                 .fadeIn("fast")
  465.                 .appendTo($(this));
  466.  
  467.         } else {
  468.  
  469.             if( img[0].src != $('#material_placeholder img')[0].src){
  470.                 img[0].src = $('#material_placeholder img')[0].src
  471.             }
  472.  
  473.             var offset = $(this).offset();
  474.             img.css({
  475.                 position : "absolute",
  476.                 display : "block",
  477.                 left:  (e.pageX-offset.left)-img.width()/2,
  478.                 top:   (e.pageY-offset.top)-img.height()/2,
  479.                 opacity: 0.4
  480.             })
  481.  
  482.         }
  483.  
  484.     } else {
  485.  
  486.         $(".loltest").fadeOut("fast");
  487.  
  488.     }
  489.  
  490. }); // Show a placeholder next to the mouse
  491.  
  492. $(document).on('click', '.layer', function(e){
  493.  
  494.     e.stopPropagation();
  495.     return false;
  496. });
  497.  
  498. $(document).on('dblclick', '#canvas', function(e){
  499.  
  500.     // if(selected_layer != ""){ //must have layer selected
  501.  
  502.     //  var material = $('#material_placeholder img');
  503.     //  var image_src = material.attr('src');
  504.  
  505.     //  $('.resources .layer').clone(true,true).addClass((layer_id++).toString()).css({
  506.     //      'background-image': 'url('+image_src+')',
  507.     //      'background-repeat': 'repeat',
  508.     //      'width': material.width(),
  509.     //      'height': material.height(),
  510.     //      'left':  $('#canvas').scrollLeft() + e.offsetX - (material.width()/2),
  511.     //      'top':  $('#canvas').scrollTop() + e.offsetY - (material.height()/2)
  512.     //  }).appendTo('#canvas '+selected_folder+" "+selected_layer);
  513.  
  514.     // } else dialog("Error","You must have a layer selected materials/entities.","_prompt");
  515.  
  516.     var material = $('#material_placeholder img');
  517.     var image_src = material.attr('src');
  518.  
  519.     if(image_src == "") return false; // No image provided;
  520.  
  521.     var spr = new Sprite({
  522.         id: layer_id,
  523.         link: material.attr("data-img-id"),
  524.         x: $('#canvas').scrollLeft() + e.offsetX - (material.width()/2),
  525.         y: $('#canvas').scrollTop() + e.offsetY - (material.height()/2),
  526.         width: material.attr("data-real-width"),
  527.         height: material.attr("data-real-height")
  528.     });
  529.  
  530.     $('.resources .layer').clone(true,true)
  531.         .attr('data-id',spr.id+"")
  532.         .attr('data-img-id',spr.link)
  533.         .css({
  534.             'background': 'url('+image_src+') repeat',
  535.             'width': spr.width,
  536.             'height': spr.height,
  537.             'left':  spr.x,
  538.             'top':  spr.y
  539.         })
  540.     .appendTo('#canvas');
  541.  
  542.     gcdf.resources.push(spr);
  543.     layer_id++;
  544.     modified = true;
  545.     e.stopPropagation();
  546.  
  547.    
  548. });  // Create a layer from a double click action 2.0
  549.  
  550. $('#code_sidebar').on('click','li.default',function(){
  551.  
  552.     $(".selected").removeClass("selected");
  553.     $(this).addClass("selected");
  554.  
  555.     var id = $(this).attr("data-id")
  556.     var parent = $(this);
  557.    
  558.     var data = fileCache.getById(id);
  559.     if( data !== undefined )
  560.         return editor.setValue(data["data"]);
  561.  
  562.     $(this).addClass("loading");
  563.  
  564.     $.ajax({ url: "/static/javascript/core.js", dataType:"text"})
  565.     .done(function(data){
  566.         fileCache.push({"id":id,"data":data});
  567.         parent.removeClass("loading");
  568.         editor.setValue(data);
  569.     });
  570.  
  571. });
  572.  
  573. $('#code_sidebar').on('click','li:not(.default, .selected, .loading)',function(){
  574.  
  575.     var pre_id = $(".selected").attr("data-id");
  576.     fileCache.getById(id).data = editor.getValue();
  577.  
  578.     $(".selected").removeClass("selected");
  579.     $(this).addClass("selected");
  580.  
  581.     var id = $(this).attr("data-id")
  582.     var file = game.children.getById(id);
  583.     var parent = $(this);
  584.  
  585.     var data = fileCache.getById(id);
  586.     if( data !== undefined ){  
  587.         if( parent.hasClass('unsaved') ){
  588.             editor.setValue(data["data"]);
  589.         } else {
  590.             editor.setValue(data["data"]);
  591.             parent.removeClass("unsaved");
  592.         }
  593.         return;
  594.     }
  595.  
  596.     $(this).addClass("loading");
  597.  
  598.     downloadFile(file,function(data){
  599.         fileCache.push({"id":id,"data":data});
  600.         //load_entities();
  601.         editor.setValue(data);
  602.         parent.removeClass("unsaved");
  603.         parent.removeClass("loading");
  604.     });
  605.  
  606. })
  607.  
  608. $('.new_entity').on('click',function(){
  609.     if($(this).hasClass("loading") == false){
  610.        
  611.         var parent = $(this).addClass('loading');
  612.         var name = $('#enitity_name').val();
  613.         var type = $('#enitity_type').val();
  614.         var clas = $('#enitity_class').val();
  615.  
  616.         var output = "var "+name+" ";
  617.  
  618.         switch(type){
  619.             case 'instance': output+="= new "+clas+"();\n   ";
  620.                 break;
  621.             case 'prototype': output+="= function(){\n  // Constructor\n    }\n\n   "
  622.                                             +name+".prototype = new "+clas+"();\n   ";
  623.                 break;
  624.         }
  625.  
  626.         createFile(name+".js",output,game.id,function(result){
  627.             parent.removeClass('loading');
  628.             game.children.unshift(result);
  629.             var script = getScript(result);
  630.             script.trigger('click');
  631.             $(".code_editor").trigger('click');
  632.             $(this).addClass('loading');
  633.         });
  634.     }
  635. });
  636.  
  637.  
  638. $('#code_sidebar').on('click','.delete',function(e){
  639.     var file = $(this).parent();
  640.     var id = file.attr("data-id");
  641.  
  642.     dialog("Delete","Are you sure you want to delete?","_confirm",{
  643.         'Yes' : function(){
  644.             file.addClass("loading");
  645.             deleteFile(id,function(reply){
  646.                 file.removeClass("loading");
  647.                 file.slideUp("fast",function(){$(this).remove()});
  648.                 fileCache.removeById(id);
  649.                 return true;
  650.             });
  651.             return false;
  652.         }
  653.     });
  654.  
  655.     e.stopPropagation();
  656. });
  657.  
  658.  
  659. $("#enitity_classname").on("change",function(e){
  660.  
  661.     var entity = Entities.getByName($(this).val());
  662.  
  663.     var spr = new Sprite({
  664.         id: layer_id,
  665.         link: entity.name,
  666.         x: $('#canvas').scrollLeft() + ($('#canvas').width()/2),
  667.         y: $('#canvas').scrollTop() + ($('#canvas').height()/2),
  668.         width: entity.width,
  669.         height: entity.height
  670.     });
  671.  
  672.     $('.resources .layer').clone(true,true)
  673.         .attr('data-id',spr.id+"")
  674.         .attr('data-link',spr.link)
  675.         .css({
  676.             'background-color': 'red',
  677.             'width': spr.width,
  678.             'height': spr.height,
  679.             'left':  spr.x,
  680.             'top':  spr.y
  681.         })
  682.     .appendTo('#canvas');
  683.  
  684.     gcdf.resources.push(spr);
  685.     layer_id++;
  686.     e.stopPropagation();
  687.  
  688.  
  689. });
  690.  
  691.  
  692. function fun(){
  693.     return "i just opened you...";
  694. }
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765. // Open/Close the folder
  766. $('#layers').on('dblclick', '.header', function(event){
  767.     //console.log( $(this).parentsUntil('.folder').html() );
  768.     $(this).closest('.folder').children('.content').slideToggle('fast');
  769.     $(this).children('.foldersizing').toggle();
  770. });
  771.  
  772.  
  773. $('.dropdown_logo').click(function(){
  774.    
  775.     if( $('.logo_menu_list').css('display') != "none" ){
  776.         $('.logo_menu_list').slideUp('fast');
  777.         $(this).attr('src','images/dropdown.gif');
  778.     } else {
  779.          $('.logo_menu_list').slideDown('fast');
  780.          $(this).attr('src','images/dropup.gif');
  781.     }
  782. }); // Drop down of the logos box
  783.  
  784.  
  785. //////// DEFO NEED ////////////////////////
  786.  
  787. $('div.titlebar').on('click', ".close", function(){
  788.    
  789.     var $panel = $(this).parent().parent();
  790.     $panel.fadeOut('fast');
  791.    
  792.     $('.fader').fadeOut('fast'); // fades out the bg
  793.  
  794.     /*if( $obj.hasClass('permanent') ) {
  795.         $obj.remove();
  796.     }*/
  797.  
  798.  
  799.     //var link = $(this).parent().parent().attr('class');
  800.     //  link = link.split(" ");
  801.    
  802.     //$('.'+link).fadeOut('fast'); // fades out the box
  803.     //$('#fader').fadeOut('fast'); // fades out the bg
  804.    
  805.     //if(link)
  806.  
  807.     //$(".menu [link='"+link+"']").removeClass('visable'); 
  808. }); // Close any specific open dragable box v2.0
  809.  
  810. $('.titlebar .sizing').on('click',function(){
  811.     $(this).parent().parent().find('.content').slideToggle('fast');
  812.     $(this).parent().find('.sizing').toggle();
  813. }); // Minimize/Maximise a window v2.0
  814.  
  815. $('.panel.draggable').mousedown(function(){
  816.    
  817.     $(this).css('z-index',z_index);
  818.     z_index++; //update it by 1;
  819.     return true;
  820. }); // Update the z-index of a dragable box v3.0
  821.  
  822. $('.hide_all').click(function(){
  823.    
  824.     if( !$(this).hasClass('visable') ){
  825.        
  826.         $('.window li a').each(function(index, element) {
  827.            
  828.             var link = $(element).attr('link');
  829.             $('.'+link).fadeOut('fast');
  830.             $('.window [link="'+link+'"]').removeClass('visable');
  831.            
  832.         });
  833.        
  834.     }
  835. }); // Hide all windows on screen
  836.  
  837. $(".material_browser").on('click',function(){
  838.        
  839.         $('.materials_browser').center().fadeIn('fast');
  840. }); // Show the materials window in center on button click v2.0
  841.  
  842. $('#canvas').on("click", '.remove_layer', function(e){
  843.     var id = $(this).parent().attr('data-id');
  844.     $(this).parent().fadeOut('fast',function(){
  845.         $(this).remove();
  846.     });
  847.     gcdf.resources.removeById(id);
  848.     modified = false;
  849.     e.stopPropagation();
  850. });  // Remove a specific layer from a group V2.0
  851.  
  852.  
  853. $("select#layer_groups").change(function (){
  854.    
  855.     group_selected = []; // Empty out an array *fixes mutly select bug*
  856.    
  857.     $("select#layer_groups option:selected").each(function(index,value){
  858.    
  859.         group_selected[index] = $(value);
  860.        
  861.     });
  862.  
  863. }); // Select the correct layer group(s)
  864.  
  865.  
  866. $('#resources').on('click','img',function(){
  867.  
  868.     var image_src = $(this).attr('src');
  869.     var link = $(this).attr('data-img-id');
  870.     var width = $(this).attr('data-real-width');
  871.     var height = $(this).attr('data-real-height');
  872.  
  873.     $('#material_placeholder img')
  874.         .attr('src',image_src)
  875.         .attr('title',image_src)
  876.         .attr('data-img-id',link)
  877.         .attr('data-real-height',height)
  878.         .attr('data-real-width',width);
  879.        
  880. }); // Insert a layer into a materials dialog
  881.  
  882.  
  883.  
  884.  
  885.  
  886. $('.material_add').click(function(){
  887.     var material = $('.material_img');
  888.     var image_src = material.attr('src');
  889.        
  890.     $( group_selected ).each(function(index,value){
  891.            
  892.         $('.resources .layer').clone(true,true).addClass((layer_id++).toString()).css({
  893.             'background-image': 'url('+image_src+')',
  894.             'background-repeat': 'repeat',
  895.             'width': material.width(),
  896.             'height': material.height()
  897.         }).appendTo('#canvas .layers_group.' + $(value).html());
  898.        
  899.     });
  900.    
  901. }); // Create a layer in main screen from material
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908. $('.hide_layer_group').click(function(){  
  909.  
  910.     $( group_selected ).each(function(index,value){
  911.        
  912.         $('#canvas .layers_group.' + $(value).html()).hide('slow');
  913.        
  914.     });
  915. }); // Hide one or more layer groups
  916.  
  917. $('.show_layer_group').click(function(){ // hide the perent layer
  918.  
  919.     $( group_selected ).each(function(index,value){
  920.        
  921.         $('#canvas .layers_group.' + $(value).html()).show('slow');
  922.        
  923.     });
  924. }); // Show one ore more layer groups
  925.  
  926. $(".del_layer_group").click(function(){
  927.  
  928.     $( group_selected ).each(function(index,value){
  929.  
  930.         var number_of_children = $('#canvas .layers_group.' + $(value).html() + ' div').length;
  931.        
  932.         if( number_of_children > 0 ){ // If one or more exist then promt user
  933.            
  934.             if(confirm( $(value).html()+" layer has "+number_of_children+" children layer(s). Are you sure you wan't to delete it?")){
  935.                
  936.                 $('select .layers_group.' + $(value).html()).remove();
  937.                 $('#canvas .layers_group.' + $(value).html()).remove();
  938.                 $(".aplha").val(''); // Update the alpha;
  939.                                
  940.             }
  941.            
  942.         } else { // no layers whiing a group, just delete it.
  943.            
  944.             $('select .layers_group.' + $(value).html()).remove();
  945.             $('#canvas .layers_group.' + $(value).html()).remove();
  946.             $(".aplha").val(''); // Update the alpha
  947.        
  948.         }
  949.        
  950.     });
  951. }); // Delete one or more layer groups
  952.  
  953. $("input.aplha").click(function() {
  954.    
  955.     if( group_selected.length > 0 ){
  956.        
  957.         var opacity = $(this).val();
  958.        
  959.         $( group_selected ).each(function(index,value){
  960.            
  961.             console.log($(value).html());
  962.            
  963.             $('#canvas .layers_group.'+ $(value).html()).css({ opacity: opacity/100 });
  964.            
  965.         });
  966.    
  967.     }
  968. });  // Change the alpha of the layer groups
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984. $('#save_as #scrolling table').on('click','tr',function(){
  985.     $('#save_as .input_file_name').val( $(this).find('.a').html() );
  986.     $('#save_as #scrolling table tr').removeClass('selected');
  987.     $(this).addClass('selected');
  988.    
  989. }); // Replace the file name of save as dialog
  990.  
  991. $('#open #scrolling table').on('click','tr',function(){
  992.    
  993.     $('#open .input_file_name').val( $(this).find('.a').html() );
  994.     $('#open #scrolling table tr').removeClass('selected');
  995.     $(this).addClass('selected');
  996.    
  997. }); // Replace the file name of open dialog
  998.  
  999. /*$(".layer").live('dblclick',function(){
  1000.    
  1001.     //do some when double clicked,
  1002.     var reply = prompt("width & height", parseInt($(this).css('width')) +"|"+ parseInt($(this).css('height')) );
  1003.     var size = reply.split('|');
  1004.    
  1005.     $(this).css('width' , size[0]);
  1006.     $(this).css('height', size[1]);
  1007.     $(this).css('overflow', 'hidden');
  1008.    
  1009.     //alert(reply[0]+" - "+reply[1]);
  1010.    
  1011. }); // Double click a layer*/
  1012.  
  1013.  
  1014.  
  1015. /*$(".layer").on("click", function(){
  1016.    
  1017.     layer_selected = $(this);
  1018.    
  1019.     $(".layer_propertie.name").val( "Top: "+parseInt($(this).css('top')) +", Left:"+parseInt($(this).css('left')) );
  1020.    
  1021.     if( $(this).hasClass("collidable") ) {
  1022.        
  1023.         $(".layer_propertie.collidable").attr("checked","checked");
  1024.    
  1025.     }else $(".layer_propertie.collidable").removeAttr("checked");
  1026.    
  1027.     $(".layer_propertie.width").val( $(this).width() );
  1028.     $(".layer_propertie.height").val( $(this).height() );
  1029.    
  1030.     //alert(10);
  1031.    
  1032. }); */ // Click on a layer*/
  1033.  
  1034. $('.tools img').click( function(){
  1035.    
  1036.     $('.tools img').each(function(index, element) {
  1037.        
  1038.         $(element).removeClass('tool_selected');
  1039.        
  1040.     });
  1041.    
  1042.     $(this).addClass('tool_selected');
  1043.    
  1044. });
  1045.  
  1046. $('.btn_export_code').click(function(){
  1047.  
  1048.     var output = $('div.export select').attr('value'); //raw | game
  1049.    
  1050.     switch(output){
  1051.    
  1052.         case 'raw': $('div.export textarea').val( output_level_data() );
  1053.             break;
  1054.            
  1055.         case 'raw_2' : $('div.export textarea').val( output_tidy_level_data() );
  1056.             break;
  1057.            
  1058.         case 'raw_3' : $('div.export textarea').val( beautify_level_data($('div.export textarea').val()) );
  1059.             break;
  1060.            
  1061.         case 'raw_4' : $('div.export textarea').val( uglify_level_data($('div.export textarea').val()) );
  1062.             break;
  1063.            
  1064.         case 'game': $('div.export textarea').val( output_game_code() );
  1065.             break;
  1066.        
  1067.     }
  1068.  
  1069.     if( $('div.export textarea').html() == "" ){
  1070.          $('div.export textarea').html("Nothing was outputted");
  1071.     }
  1072.    
  1073. }); // Export Actual Code
  1074.  
  1075.  
  1076. /*$('#canvas .droppable').droppable({drop:
  1077.     function( event, ui ) {
  1078.            
  1079.         var id   = ui.draggable.attr('id');
  1080.            
  1081.         var div = $('.update_container').clone();
  1082.         div.find('.in_name').val( ui.draggable.find('div').html() );
  1083.         div.find('.in_desc').val( ui.draggable.attr('description') );
  1084.         div.attr('class', 'uc_1 hidden');
  1085.            
  1086.         $(this).html( div ).attr('class','asd');
  1087.         $('.uc_1').slideDown('fast');
  1088.            
  1089.     }
  1090. }); *///????????????????
  1091.  
  1092. $(".layer_propertie").click(function(){
  1093.    
  1094.     if( $(".layer_propertie.collidable").attr('checked') ) {
  1095.        
  1096.         $(layer_selected).addClass("collidable");
  1097.        
  1098.     }
  1099.    
  1100.     else $(layer_selected).removeClass("collidable");
  1101.    
  1102. }); // Layer Properties settings
  1103.  
  1104.  
  1105. $('.menu_item').hover(
  1106.   function () {
  1107.     $(this).parent().find('>ul').fadeIn('fast');
  1108.   }
  1109. );
  1110.  
  1111. $('#menubar li')
  1112.     .mouseleave(
  1113.         function () {
  1114.             $(this).find('ul').fadeOut(0);
  1115.         }
  1116.     )
  1117.     .click(function(){
  1118.         $(this).find('ul').fadeOut(0); 
  1119. });
  1120.  
  1121.  
  1122. $(".setting").click(function(){
  1123.    
  1124.     var setting = $(this).attr('name');
  1125.     var boolean = ($(this).attr('checked'))? 1 : 0 ;
  1126.     var value = $(this).val();
  1127.    
  1128.     switch(setting){
  1129.        
  1130.         case 'disable':
  1131.             if(boolean) $('.live_draggable').liveDraggable({ disabled: true });
  1132.             else $('.live_draggable').liveDraggable({ disabled: false });
  1133.             console.log(setting+" "+boolean+" "+value);
  1134.             break;
  1135.    
  1136.         case 'snap':
  1137.             if(boolean) $('.live_draggable').liveDraggable({snap: true});
  1138.             else $('.live_draggable').liveDraggable({snap: false});
  1139.             console.log(setting+" "+boolean+" "+value);
  1140.             break;
  1141.        
  1142.         case 'grid':
  1143.             $('.live_draggable').liveDraggable({grid: value});
  1144.             console.log(setting+" "+boolean+" "+value);
  1145.             break; 
  1146.            
  1147.         case 'snapmode':
  1148.             $('.live_draggable').liveDraggable({snapMode: value});
  1149.             console.log(setting+" "+boolean+" "+value);
  1150.             break; 
  1151.            
  1152.         case 'snaptolerance':
  1153.             $('.live_draggable').liveDraggable({snapTolerance: value});
  1154.             console.log(setting+" "+boolean+" "+value);
  1155.             break; 
  1156.            
  1157.         case 'delay':
  1158.             $('.live_draggable').liveDraggable({delay: value});
  1159.             console.log(setting+" "+boolean+" "+value);
  1160.             break;
  1161.            
  1162.     }
  1163.    
  1164. });  // Setting options varables
  1165.  
  1166.  
  1167. function  beautify_level_data(output) {
  1168.  
  1169.     data = output.split('|');
  1170.     layers = data[0].split(',');
  1171.     resources = data[1].split(',');
  1172.     links = data[2].split(',');
  1173.    
  1174.     var test = "";
  1175.     var length = layers.length;
  1176.     for ( var i=0; i<length; ++i ){
  1177.         test += layers[i]+",\n";
  1178.     }
  1179.    
  1180.     test = test.slice(0, -2) + '|\n\n';
  1181.    
  1182.     var length = resources.length;
  1183.     for ( var i=0; i<length; ++i ){
  1184.         test += resources[i]+",\n";
  1185.     }
  1186.    
  1187.     test = test.slice(0, -2) + '|\n\n';
  1188.    
  1189.     var length = links.length;
  1190.     for ( var i=0; i<length; ++i ){
  1191.         test += links[i]+",\n";
  1192.     }
  1193.    
  1194.     test = test.slice(0, -2);
  1195.    
  1196.     return test;
  1197.    
  1198. }
  1199.  
  1200. function uglify_level_data(output) {
  1201.    
  1202.     return output.replace(/(\r\n|\n|\r)/gm,"");
  1203.    
  1204. }
  1205.  
  1206. $(document).keydown(function(e){
  1207.  
  1208.     //alert(e.keyCode);
  1209.     var selected = layer_selected;
  1210.  
  1211.     if(selected != 0){
  1212.      
  1213.       switch(e.keyCode){
  1214.         case 65: //this is left! (a)aa
  1215.          
  1216.             $(selected).css('left',parseInt($(selected).css('left'))-1);
  1217.            
  1218.           break;
  1219.         case 87: //this is up! (w)
  1220.          
  1221.             $(selected).css('top',parseInt($(selected).css('top'))-1);
  1222.          
  1223.           break;
  1224.         case 68: //this is right (d)
  1225.        
  1226.             $(selected).css('left',parseInt($(selected).css('left'))+1);
  1227.          
  1228.           break;
  1229.        
  1230.         case 83: //this is down! (s)
  1231.        
  1232.             $(selected).css('top',parseInt($(selected).css('top'))+1);
  1233.          
  1234.           break;
  1235.          
  1236.         case 67: //dublicate object
  1237.            
  1238.             console.log('.'+$("select option:selected").val());
  1239.            
  1240.             $(selected).clone().appendTo( '#canvas .group#'+$("select option:selected").val() );
  1241.          
  1242.          break;
  1243.          
  1244.       }
  1245.      
  1246.        
  1247.       console.log($(selected).css('left'),(selected).css('top'));
  1248.      
  1249.     }
  1250.  
  1251. });
  1252.  
  1253.  
  1254. function validAuth(){
  1255.     if(obj.length == 0){ //Nothing in the google drive that bellongs to this app. Create folder.
  1256.         createFolder("obj",null,function(result){
  1257.             $("#intro .content").fadeToggle('fast');
  1258.             obj = result;
  1259.             obj.children = [];
  1260.             console.log(result);
  1261.         });
  1262.     } else {
  1263.         getGames(obj);
  1264.         $("#intro .content").fadeToggle('fast');
  1265.     }
  1266. }
  1267.  
  1268. function invalidAuth(){
  1269.     $('.revalidate').fadeIn("fast");
  1270.     //authButton.style.display = 'block';
  1271.     $(".revalidate_btn").click(function(e) {
  1272.         e.preventDefault();
  1273.         gapi.auth.authorize(
  1274.             {'client_id': CLIENT_ID, 'scope': SCOPES, 'immediate': false},
  1275.             handleAuthResult);
  1276.     });
  1277. }
  1278.  
  1279. function getGames(data){
  1280.  
  1281.     var index;
  1282.     var length = 0;
  1283.     //console.log(data);
  1284.     if(data.children){
  1285.         length = data.children.length;
  1286.     }
  1287.     $(".list_of_games").html("");  //Clearn;
  1288.     for (index = 0; index < length; ++index) {
  1289.         $R.find(".game").clone()
  1290.             .attr("id",index).html(data.children[index]["title"])
  1291.             .attr("title",data.children[index].id.split('0BwoqcQo3Edp3')[1])
  1292.             .appendTo(".list_of_games");
  1293.     }
  1294.  
  1295. }
  1296.  
  1297. function getImages(data){
  1298.  
  1299.     for (i in data) {
  1300.         if( (/image/i).test(data[i].mimeType) ){
  1301.             $R.find(".resource").clone()
  1302.                 .find("img")
  1303.                     .attr("src",data[i]["webContentLink"])
  1304.                     .attr("data-img-id",data[i]["id"])
  1305.                     .attr("data-real-width",data[i]["imageMediaMetadata"]["width"])
  1306.                     .attr("data-real-height",data[i]["imageMediaMetadata"]["height"])
  1307.                 .end().appendTo("#resources .content");
  1308.         }
  1309.     }
  1310.  
  1311. }
  1312.  
  1313. function getScripts(data){
  1314.  
  1315.     for (i in data) {
  1316.         if( data[i].fileExtension === "js" ){
  1317.             $R.find(".script")
  1318.                 .clone()
  1319.                 .prepend(data[i]["title"])
  1320.                 .attr("data-id",data[i]["id"])
  1321.                 .appendTo("#code_sidebar ul")
  1322.                 //.trigger("click");
  1323.         }
  1324.     }
  1325.  
  1326. }
  1327.  
  1328. function getScript(data){
  1329.  
  1330.     return $R.find(".script")
  1331.             .clone()
  1332.                 .html(data["title"])
  1333.                 .attr("data-id",data["id"])
  1334.             .hide()
  1335.             .insertAfter("#code_editor .default")
  1336.             .fadeIn("fast");
  1337.  
  1338. }
  1339.  
  1340. function getImage(data){
  1341.  
  1342.     if( (/image/i).test(data.mimeType) ){
  1343.        
  1344.         getMeta(data.id,function(meta){
  1345.             $R.find(".resource").clone()
  1346.                 .find("img")
  1347.                     .attr("src",meta["webContentLink"])
  1348.                     .attr("data-img-id",meta["id"])
  1349.                     .attr("data-real-width",meta["imageMediaMetadata"]["width"])
  1350.                     .attr("data-real-height",meta["imageMediaMetadata"]["height"])
  1351.                 .end()
  1352.                 .hide()
  1353.                 .prependTo("#resources .content")
  1354.                 .fadeIn("fast");
  1355.         });
  1356.  
  1357.     }
  1358.    
  1359. }
  1360.  
  1361.  
  1362.  
  1363.  
  1364. $(".alist_of_games").on("contextmenu",".game",function(e) {
  1365.     e.preventDefault();
  1366.     alert(1);
  1367.     // create and show menu
  1368. });
  1369.  
  1370. function inside(events){
  1371. temp = "";
  1372. var len = events.length;
  1373. for (i=0;i<len;i++) {
  1374.   var type = "";
  1375.   if (events[i].mimeType=="application/vnd.google-apps.folder"){
  1376.     type = "folder";
  1377.   } else type = "file";
  1378.  
  1379.   temp += "<li id='"+events[i].id+"' class='"+type+"' index='"+i+"''>&nbsp;&nbsp;"+events[i].title+ "</li>";
  1380. }
  1381. return temp;
  1382. }
  1383.  
  1384. // var timeout;
  1385. // var saving = false;
  1386. // var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  1387. //  lineNumbers: true,
  1388. //  matchBrackets: true,
  1389. //  onChange: function(cm){
  1390. //      if(saving) return true;
  1391. //      $('#modified').fadeIn('slow');
  1392. //      clearTimeout(timeout);
  1393. //      timeout = setTimeout(function(){
  1394. //          saving = true;
  1395. //          $('#modified').fadeOut('fast', function(){
  1396. //              $.ajax({
  1397. //                  type: "POST",
  1398. //                  url: "./../save_edited_file.php",
  1399. //                  data: { file:"<?php echo $_GET['file']?>" ,data: cm.getValue() }
  1400. //              }).done(function(html) {
  1401. //                  console.log(html);
  1402. //                  $('#saved').fadeIn('slow').delay(300).fadeOut('fast', function(){saving = false});
  1403. //              });
  1404. //          });
  1405. //      }, 2000);
  1406. //  }
  1407. // });
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413. (function ($) {
  1414.     $.fn.getimage = function () {
  1415.         image = $(this).css('background-image');
  1416.         image = image.split('/');
  1417.         return image[image.length-1].slice(0, -1)
  1418.     };
  1419. }(jQuery));
  1420.  
  1421.  
  1422. Array.prototype.getById = function(id) {
  1423.     for(i in this)
  1424.         if ( this[i].id == id ) return this[i];
  1425. }
  1426.  
  1427. Array.prototype.updateById = function(id,data) {
  1428.     for(i in this)
  1429.         if ( this[i].id == id ) return this[i]=data;
  1430. }
  1431.  
  1432. Array.prototype.getByName = function(name) {
  1433.     for(i in this)
  1434.         if ( this[i].name == name ) return this[i];
  1435. }
  1436.  
  1437. Array.prototype.removeById = function(id) {
  1438.     for(i in this)
  1439.         if ( this[i].id == id ) return this.splice(i,1);
  1440. }
  1441.  
  1442. Sprite.prototype.setCoordinates = function(x, y) {
  1443.     this.x = x;
  1444.     this.y = y;
  1445. }
  1446.  
  1447. Sprite.prototype.setDimensions = function(width, height) {
  1448.     this.width = width;
  1449.     this.height = height;
  1450. }
  1451.  
  1452.  
  1453. $('#dropfile').on('dragleave',function(e) {
  1454.     e.preventDefault();
  1455.     e.stopPropagation();
  1456.     $("#dropfile").fadeOut("fast");
  1457.     //console.log("dragenter");
  1458. });
  1459.  
  1460. $('div#dropfile').on('dragover',function(e) { e.preventDefault(); e.stopPropagation(); });
  1461. $('div#dropfile').on('dragenter',function(e) { e.preventDefault(); e.stopPropagation(); });
  1462.  
  1463. $(document).on('dragover','#body_container',function(e) {
  1464.     e.preventDefault();
  1465.     e.stopPropagation();
  1466.     $("#dropfile").fadeIn("fast");
  1467.     //console.log("dragenter");
  1468. });
  1469.  
  1470. $(document).on('dragover','#body_container',function(e) {e.preventDefault(); e.stopPropagation();});
  1471.  
  1472. $('div#dropfile').on('drop',function(e){
  1473.     $("#dropfile").fadeOut("fast");
  1474.     if(e.originalEvent.dataTransfer){
  1475.         if(e.originalEvent.dataTransfer.files.length) {
  1476.             e.preventDefault();
  1477.             e.stopPropagation();
  1478.  
  1479.             var files = e.originalEvent.dataTransfer.files;
  1480.             var total = e.originalEvent.dataTransfer.files.length;
  1481.             var index = 0; // Store the index
  1482.             var store = function() {
  1483.  
  1484.                 var info = $('#n_info')
  1485.                     .find("b").html(index+1+"/"+total).end()
  1486.                     .find("p").html(files[index].name).end();
  1487.  
  1488.                 if (typeof FileReader !== "undefined" && (/image/i).test(files[index].type)) {
  1489.                     var img = info.find("img.inf_prev")[0];
  1490.                     reader = new FileReader();
  1491.                     reader.onload = (function (theImg) {
  1492.                             return function (evt) {
  1493.                                 theImg.src = evt.target.result;
  1494.                             };
  1495.                         }(img));
  1496.                     reader.readAsDataURL(files[index]);                
  1497.                
  1498.                 } else { info.find("img.inf_prev")[0].src = ""; }
  1499.  
  1500.                 info.fadeIn("fast");
  1501.                
  1502.                 insertFile(files[index],game.id,function(result){
  1503.                     console.log(result);
  1504.                     game.children.unshift(result);
  1505.                     getImage(result);
  1506.                     index++;
  1507.                     if(files[index]) store();
  1508.                     else info.fadeOut("fast");
  1509.                 });
  1510.                
  1511.             };
  1512.  
  1513.             store();
  1514.  
  1515.             // insertFile(files[0],function(result){
  1516.             //  console.log(result);
  1517.             // });
  1518.  
  1519.             // var reader = new FileReader();
  1520.             //  reader.readAsDataURL(files[0]);
  1521.             //console.log(reader);
  1522.         }  
  1523.     }
  1524. });
  1525.  
  1526. function load_entities(){
  1527.  
  1528.     for(key in fileCache){
  1529.         eval(fileCache[key].data);
  1530.     }
  1531.  
  1532.     var ent_len = (Entities.length);
  1533.  
  1534.     $("#enitity_classname").html("");
  1535.  
  1536.     for(i=0; i<ent_len; i++){
  1537.  
  1538.       //if( /*typeof window[key] === "function" &&*/
  1539.         //window[key] instanceof Entity){
  1540.  
  1541.  
  1542.             // $R.find(".entity").clone()
  1543.             //  .find(".ent")
  1544.             //      .css({
  1545.             //          "background":"red",
  1546.             //          "width": Entities[i].width,
  1547.             //          "height": Entities[i].height,
  1548.             //      })
  1549.             //  .end()
  1550.  
  1551.             $R.find('.entity').clone()
  1552.                 .addClass(Entities[i].name)
  1553.                 .html(Entities[i].name)
  1554.                 .attr("value",Entities[i].name)
  1555.                 .attr("data-id",i)
  1556.                 .appendTo("#enitity_classname");
  1557.  
  1558.          //console.log(key + " is a function using Entity as its prototype property");
  1559.          //console.log(window[key].x);
  1560.          //console.log(window[key]);
  1561.       //}
  1562.     }
  1563.  
  1564.  
  1565. }
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573. ////////////////////////////////////////// PLUGINS //////////////////////////////////////////////////////
  1574. ////////////////////////////////////////// PLUGINS //////////////////////////////////////////////////////
  1575. ////////////////////////////////////////// PLUGINS //////////////////////////////////////////////////////
  1576.  
  1577.  
  1578. // thank you who ever live dragalbe elements
  1579. /*(function ($) {
  1580.     $.fn.liveDraggable = function (opts) {
  1581.         this.live("mouseover", function() {
  1582.             //if (!$(this).data("init")) {
  1583.                 $(this).data("init", true).draggable(opts);
  1584.             //}
  1585.         });
  1586.     return $();
  1587.     };
  1588. }(jQuery));
  1589.  
  1590. (function ($) {  // kinda dedited it my self;
  1591.     $.fn.liveResizable = function (opts) {
  1592.         this.live("mouseover", function() {
  1593.             $(this).resizable(opts);
  1594.         });
  1595.     return $();
  1596.     };
  1597. }(jQuery));
  1598.  
  1599. /// write this my self :)
  1600. (function ($) {
  1601.     $.fn.getimage = function () {
  1602.         image = $(this).css('background-image');
  1603.         image = image.split('/');
  1604.         return image[image.length-1].slice(0, -1)
  1605.     };
  1606. }(jQuery));
  1607.  
  1608.  
  1609.  
  1610.  
  1611. jQuery.fn.flashText = function () {
  1612.    
  1613.     this.css('color','#7aacff');
  1614.     this.fadeOut('fast').fadeIn('slow');
  1615.     this.fadeOut('fast').fadeIn('slow').queue(function () {
  1616.         $(this).css('color','#808080');
  1617.         $(this).dequeue();
  1618.     });
  1619.        
  1620. }; */
  1621.  
  1622.  
  1623.  
  1624. //(function(a){function f(b,c,d){var e=a.ui.resizable.prototype[b];a.ui.resizable.prototype[b]=function(){if(d)d.apply(this,arguments);e.apply(this,arguments);if(c)c.apply(this,arguments)}}function e(a){return parseInt(a.css("margin-top"),10)||0}function d(a){return parseInt(a.css("margin-left"),10)||0}function c(a){return a.sort(function(a,b){return!a?1:!b?-1:Math.abs(a)-Math.abs(b)})[0]}function b(a,b,c){return Math.abs(a)<c?-a:Math.abs(b)<c?-b:0}a.extend(a.ui.resizable.prototype.options,{snapTolerance:20,snapMode:"both"});a.ui.plugin.add("resizable","snap",{start:function(){var b=a(this),c=b.data("resizable"),f=c.options.snap;c.ow=c.helper.outerWidth()-c.size.width;c.oh=c.helper.outerHeight()-c.size.height;c.lm=d(b);c.tm=e(b);c.coords=[];a(typeof f=="string"?f:":data(resizable)").each(function(){if(this==c.element[0]||this==c.helper[0])return;var b=a(this),f=b.position(),g=f.left+d(b),h=f.top+e(b);c.coords.push({l:g,t:h,r:g+b.outerWidth(),b:h+b.outerHeight()})})},resize:function(){var d=[],e=[],f=[],g=[],h=a(this).data("resizable"),i=h.axis.split(""),j=h.options.snapTolerance,k=h.options.snapMode,l=h.position.left+h.lm,m=l-j,n=h.position.top+h.tm,o=n-j,p=l+h.size.width+h.ow,q=p+j,r=n+h.size.height+h.oh,s=r+j;a.each(h.coords,function(){var c=this,h=Math.min(q,c.r)-Math.max(m,c.l),t=Math.min(s,c.b)-Math.max(o,c.t);if(h<0||t<0)return;a.each(i,function(a,i){if(k=="outer"){switch(i){case"w":case"e":if(h>j*2)return;break;case"n":case"s":if(t>j*2)return}}else if(k=="inner"){switch(i){case"w":case"e":if(h<j*2)return;break;case"n":case"s":if(t<j*2)return}}switch(i){case"w":d.push(b(l-c.l,l-c.r,j));break;case"n":e.push(b(n-c.t,n-c.b,j));break;case"e":f.push(b(p-c.l,p-c.r,j));break;case"s":g.push(b(r-c.t,r-c.b,j))}})});if(g.length)h.size.height+=c(g);if(f.length)h.size.width+=c(f);if(d.length){var t=c(d);h.position.left+=t;h.size.width-=t}if(e.length){var t=c(e);h.position.top+=t;h.size.height-=t}}});f("_mouseStop",null,function(){if(this._helper){this.position={left:parseInt(this.helper.css("left"),10)||.1,top:parseInt(this.helper.css("top"),10)||.1};this.size={width:this.helper.outerWidth(),height:this.helper.outerHeight()}}});f("_mouseStart",function(){if(this._helper){this.size={width:this.size.width-(this.helper.outerWidth()-this.helper.width()),height:this.size.height-(this.helper.outerHeight()-this.helper.height())};this.originalSize={width:this.size.width,height:this.size.height}}});f("_renderProxy",function(){if(this._helper){this.helper.css({left:this.elementOffset.left,top:this.elementOffset.top,width:this.element.outerWidth(),height:this.element.outerHeight()})}});var g=a.ui.resizable.prototype.plugins.resize;a.each(g,function(a,b){if(b[0]=="ghost"){g.splice(a,1);return false}});a.each(a.ui.resizable.prototype.plugins.start,function(b,c){if(c[0]=="ghost"){var d=c[1];c[1]=function(){d.apply(this,arguments);a(this).data("resizable").ghost.css({width:"100%",height:"100%"})};return false}})})(jQuery);
  1625.  
  1626. /* Query.fn.outerHTML = function(s) {
  1627.     return s
  1628.         ? this.before(s).remove()
  1629.         : jQuery("<p>").append(this.eq(0).clone()).html();
  1630. }; 
  1631.  
  1632. $('.live_draggable').liveDraggable({ snap: ".live_draggable", zIndex: 1});
  1633. //$('.draggable').dr
  1634.  
  1635. $('.live_resizable').liveResizable({ snap: true,  zIndex: 1,
  1636.     start: function(event, ui) { console.log(event,ui); },
  1637.     handles: "all"
  1638. });*/