<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <!--
  Code & Design by AppGlobe
  --> 
  <ModulePrefs 
    title="AppFoyer" 
    directory_title="AppFoyer.com" 
    title_url="http://www.appfoyer.com/" 
    description="View latest Google gadgets from appfoyer.com. If you know of any quality gadgets ( perhaps you authored a few your self ), you can promote them by         submitting them to AppFoyer." 
    height="400" 
    scrolling="false" 
    screenshot="http://hosting.gmodules.com/ig/gadgets/file/113538614533289101574/appfoyer-ss.png" 
    thumbnail="http://hosting.gmodules.com/ig/gadgets/file/113538614533289101574/appfoyer-tn.png" 
    author="AppGlobe" 
    author_email="appglobe+appfoyer@gmail.com"
    author_affiliation="appfoyer.com" 
    author_link="http://www.appfoyer.com"
    author_location="Sweden"
    category="tools"> 
    <Require feature="tabs" /> 
    <Optional feature="dynamic-height" />
    <Icon>"http://www.appfoyer.com/favicon.ico"</Icon>
  </ModulePrefs>
  <UserPref name="num_entries" display_name="Number of Entries:" datatype="enum" default_value="5"> 
    <EnumValue value="5" display_value="5" />
    <EnumValue value="10" display_value="10" />
  </UserPref>
  <Content type="html" view="home, profile, canvas" preferred_height="200">
    <![CDATA[ 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
      <style type="text/css">
        .loader {
          position:absolute;
          top:2.5em;
          left:0;
        }
        a {
          color:#03c;
        }
        .tablib_table {
          border-collapse:collapse;
          font-size:90%;
        }
        .tablib_emptytab {
          border-bottom: 1px solid #aaa;
        }
        .tablib_spacertab {
          display:none;
        }
        .tablib_selected, .tablib_unselected {
          width:15em;
          max-width:49%;
        }
        .tablib_unselected {
          background: -webkit-gradient(linear,left top,left bottom,from(white),to(#F2F2F2));
          background: -moz-linear-gradient(top,white,#F2F2F2);
          border-left: 1px solid #D6D6D6;
          border-right: 1px solid #D6D6D6;
          border-top: 1px solid #D6D6D6;
          border-bottom:1px solid #aaa;
          cursor: pointer;
          color:#03c;
        }
        .tablib_selected {
          color:#000;
          font-weight: bold;
          font-weight: normal;
          background: white;
          border-left: 1px solid #AAA;
          border-right: 1px solid #AAA;
          border-top: 1px solid #AAA;
          border-bottom: 1px solid white;
          cursor: default;
        }
        .tablib_content_container {
          overflow:auto;
          height: 165px;
          font-size: 80%;
          margin-top: 1em;
        }
        .tablib_content_container_submit {
          overflow: hidden;
          height: 365px;
        }
      </style>
      <script type="text/javascript">
        /*
        Global properties
        */
        // Feed for latest gadgets
        var feedURL= "http://feeds.feedburner.com/appfoyer";  
        // User prefs
        var prefs = new gadgets.Prefs();
        var entries = prefs.getInt("num_entries");
        // Tab ID, will get a value later on
        var currentTabId = null;
        // Initializes tabs and designates the tab named "Latest Gadgets" as the tab selected by default.
        var defaultTabName = "Latest Gadgets";
        var tabs = new gadgets.TabSet(__MODULE_ID__, defaultTabName);
        
        /*
        Functions
        */
        // Initialize tabs and adjust height
        function init() {
          // Latest gadgets tab 
          tabs.addTab( defaultTabName, {            
            contentContainer: document.getElementById("latest-gadgets"),
            callback: getLatestGadgets           
          });
          // Submit gadgets tab
          tabs.addTab( "Submit Gadgets", {
            contentContainer: document.getElementById("submit-gadgets"),
            callback: loadSubmitForm
          });
          gadgets.window.adjustHeight(200);
        };
        // Callback for when 
        function loadSubmitForm( tabId ) {
          var submitGadgetsContainer = document.getElementById( "submit-gadgets" );
          submitGadgetsContainer.innerHTML = '<div class="loader"><img src="https://lh3.googleusercontent.com/_flFwRe-nB0A/TYJgTFhIAuI/AAAAAAAAANI/D5jXOBNP5Qg/loader-bar.gif" /></div><iframe id="submit-frame" frameborder="0" height="100%" width="100%" src="http://www.appfoyer.com/cms/wp-content/plugins/gadget-submission/manager_form_page.php"></iframe>';
          // Add class with styles specific for when this tab is choosen
          $('.tablib_content_container').addClass('tablib_content_container_submit');
          gadgets.window.adjustHeight(400);
          $('.loader').fadeOut(500);
          window.setTimeout(function(){$('.loader').fadeOut(500);
},1000);
        };
        // Callback that requests the feed with latest gadgets
        function getLatestGadgets( tabId ) {
          var params = {};  
          params[ gadgets.io.RequestParameters.CONTENT_TYPE ] = gadgets.io.ContentType.FEED; 
          params[ gadgets.io.RequestParameters.GET_SUMMARIES ] = true;  
          params[ gadgets.io.RequestParameters.NUM_ENTRIES ] = new Number( entries );  
          currentTabId = tabId;
          gadgets.io.makeRequest( feedURL, response, params );
        };
        // Callback that takes care of the response for the feed request
        function response( obj ) { 
          // Feed content container
          var feedContainer = document.getElementById(currentTabId);
          feedContainer.innerHTML =  '<div class="loader"><img src="https://lh3.googleusercontent.com/_flFwRe-nB0A/TYJgTFhIAuI/AAAAAAAAANI/D5jXOBNP5Qg/loader-bar.gif" /></div>';
          // obj.data contains the feed data
          var feed = obj.data;
          var html = "";
          // Access the data for each feed entry
          if ( feed.Entry ) {
          for ( var i = 0; i < feed.Entry.length; i++ ) {
            html += "<div><a target='_blank' href='" + feed.Entry[i].Link + "'>"
            + feed.Entry[i].Title
            + "</a>";
            html += "<br><i>" + feed.Entry[i].Summary + "</i></div>";
            }
          }
          // Adds feed content to the currently choosen tabs content container
          feedContainer.innerHTML = html;
          // Makes all links open in new tab/window
          var anchors = document.getElementsByTagName('a');
          for ( var i=0; i<anchors.length; i++ ) {
            anchors[i].setAttribute('target', '_blank');
          }
          // Remove the class for the styles applied when the "Submit Gadgets" -tab is choosen
          $('.tablib_content_container').removeClass('tablib_content_container_submit');
          gadgets.window.adjustHeight(200);
        };
        // Call init function 
        gadgets.util.registerOnLoadHandler( init );
      </script>
      <div id="submit-gadgets" style="display:none">
        &nbsp;
      </div>
    ]]>
  </Content>
</Module>