<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Fotiweb</title>
	<link>http://www.fotiweb.com</link>
	<description>All things Foti!</description>
	<pubDate>Fri, 06 Jun 2008 21:27:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Replace Arbitrary z-index Values with Ordered Values</title>
		<link>http://www.fotiweb.com/2008/06/06/replace-arbitrary-z-index-values-with-ordered-values/</link>
		<comments>http://www.fotiweb.com/2008/06/06/replace-arbitrary-z-index-values-with-ordered-values/#comments</comments>
		<pubDate>Fri, 06 Jun 2008 21:16:11 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/2008/06/06/replace-arbitrary-z-index-values-with-ordered-values/</guid>
		<description><![CDATA[In a forum that I frequent, someone asked how they could replace their arbitrary z-index values to only the range needed to get the job done.  For example, if they had only 3 z-index values being used (&#8221;0&#8243;, &#8220;30&#8243;, &#8220;500&#8243;) they wanted this to replace them to the smallest values possible (&#8221;0&#8243;, &#8220;1&#8243;, &#8220;2&#8243;). [...]]]></description>
			<content:encoded><![CDATA[<p>In a forum that I frequent, someone asked how they could replace their arbitrary z-index values to only the range needed to get the job done.  For example, if they had only 3 z-index values being used (&#8221;0&#8243;, &#8220;30&#8243;, &#8220;500&#8243;) they wanted this to replace them to the smallest values possible (&#8221;0&#8243;, &#8220;1&#8243;, &#8220;2&#8243;).  Is this useful?  Probably not.  But here is my 20 minute solution:</p>
<pre name="code" class="php">
<div style="z-index:563">A</div>
<div>A.1</div>
<div style="z-index:2">B</div>
<div style="z-index:30">C</div>
<div style="z-index:563">D</div>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
    var i, z, a = [];
    var zIndexMap = {};
    // Get all of the elements that you want to check for z indexes. Use
    // whatever makes sense. For this demo, I\'m just getting all div elements
    var els = document.getElementsByTagName(\'div\');
    // Loop through the elements to get the z-indexes
    for (i = 0; i < els.length; i++) {
        z = YAHOO.util.Dom.getStyle(els[i], \'z-index\');
        // Check the hash map to see if this is a unique z-index, ie - one that
        // we haven\'t recorded yet.
        if (zIndexMap[\'z\' + z] === undefined) {
            // We found a unique zindex so add it to our array and mark it found
            a[a.length] = parseInt(z, 10);
            zIndexMap[\'z\' + z] = 1;
        }
    }    
    // Sort our array numerically
    // Before sort:
    alert(\'Our unique z-indexes, unsorted:\n\' + a);
    function numberorder(a, b) { return a - b; }
    a.sort(numberorder);
    // after sort:    
    alert(\'Our unique z-indexes, sorted:\n\' + a);
    // Loop through the array and record the index value (i) as the new value
    // that the hash map points to for this old z-index.  For example, if the
    // first item in the array contains "563", then our zIndexMap["z563"] = 0.
    for (i = 0; i < a.length; i++) {
        zIndexMap[\'z\' + a[i]] = i;
    }
    // Loop through the element collection again and change the z-index value
    // by using the old value to lookup the new value in the hash map
    for (i = 0; i < els.length; i++) {
        z = YAHOO.util.Dom.getStyle(els[i], \'z-index\');
        YAHOO.util.Dom.setStyle(els[i], \'z-index\', zIndexMap[\'z\' + z]);
    }
    // Verify the new z-index values
    for (i = 0; i < els.length; i++) {
        alert(YAHOO.util.Dom.getStyle(els[i], \'z-index\'));
    }
});
</script>
</script></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2008/06/06/replace-arbitrary-z-index-values-with-ordered-values/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Thanks HostMySite</title>
		<link>http://www.fotiweb.com/2008/02/03/thanks-hostmysite/</link>
		<comments>http://www.fotiweb.com/2008/02/03/thanks-hostmysite/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 22:57:52 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/2008/02/03/thanks-hostmysite/</guid>
		<description><![CDATA[This site is hosted at HostMySite.com.  Yesterday, someone suggested I could change the Permalink structure of WordPress to give the URL&#8217;s a friendlier look.  Sounded like a good idea&#8230; but when I made the change, the site broke and I had no way to fix it.  Some Googling revealed that the problem [...]]]></description>
			<content:encoded><![CDATA[<p>This site is hosted at <a href="http://www.hostmysite.com">HostMySite.com</a>.  Yesterday, someone suggested I could change the Permalink structure of WordPress to give the URL&#8217;s a friendlier look.  Sounded like a good idea&#8230; but when I made the change, the site broke and I had no way to fix it.  Some Googling revealed that the problem was that mod_rewrite must not be enabled for my site.  There should have been some kind of warning on the Permalinks page that your site might break, but there wasn&#8217;t.  <img src='http://www.fotiweb.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  Shame on you WordPress.</p>
<p>Anyway, I contacted my HostMySite and Paul H. was able to quickly make the necessary changes to get me back up and running.  A big thanks to HostMySite.  My permalinks look great now, and as always the HostMySite support folks were a great help.  Kudos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2008/02/03/thanks-hostmysite/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Global Warming = Global Warning</title>
		<link>http://www.fotiweb.com/2008/01/15/global-warming-global-warning/</link>
		<comments>http://www.fotiweb.com/2008/01/15/global-warming-global-warning/#comments</comments>
		<pubDate>Tue, 15 Jan 2008 18:39:27 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=36</guid>
		<description><![CDATA[I finally got around to renting the DVD &#8220;An Inconvenient Truth.&#8221;  It was really an eye opener, and quite interesting.  A major ecological change might be closer at hand than you think.  I am definitely going to try and do my part to reduce my Carbon Footprint.  I&#8217;ve started by switching [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to renting the DVD &#8220;<em>An Inconvenient Truth</em>.&#8221;  It was really an eye opener, and quite interesting.  A major ecological change might be closer at hand than you think.  I am definitely going to try and do my part to reduce my Carbon Footprint.  I&#8217;ve started by switching my light bulbs to energy efficient bulbs, and making changes around the house.  There&#8217;s still a lot more that we can do.</p>
<p>For more information, visit: <a href="http://www.climatecrisis.net">http://www.climatecrisis.net</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2008/01/15/global-warming-global-warning/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Snowy Backgrounds</title>
		<link>http://www.fotiweb.com/2007/12/07/snowy-backgrounds/</link>
		<comments>http://www.fotiweb.com/2007/12/07/snowy-backgrounds/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 18:00:25 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=14</guid>
		<description><![CDATA[This was sitting in my &#8220;waiting to be published&#8221; stuff for a LONG time.  I meant to clean it up and include the images I used in my original example, but I never got around to it, so I&#8217;m just going ahead and publishing it &#8220;as is&#8221;.   
I decided to create a [...]]]></description>
			<content:encoded><![CDATA[<p>This was sitting in my &#8220;waiting to be published&#8221; stuff for a LONG time.  I meant to clean it up and include the images I used in my original example, but I never got around to it, so I&#8217;m just going ahead and publishing it &#8220;as is&#8221;.  <img src='http://www.fotiweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I decided to create a new way to do snowy backgrounds.  I say &#8216;new&#8217;, but surely I&#8217;m not the first person ever to do it this way.  So, new to me anyway.  Below is the process I took&#8230; a sort of tutorial for anyone interested.  It&#8217;s important to note that you could apply this to any/every page on a site, simply by putting the script in an external file and linking it in, calling the init method with the id of a container element, and as long as the path to the images is accessible from each page.  Feel free to use this in any way you like (including the images).  There are a couple of style rules that were required for this to work (particularly with IE).</p>
<p>First, I decided that I wanted a &#8220;layered&#8221; snowy effect.  The &#8220;closest&#8221; layer would have the largest flakes, the next layer would have smaller flakes, and the next layer would have even smaller flakes.  Each layer is going to fall at a slightly different rate, which is more realistic to what falling snow looks like.</p>
<p>So first I created the closest image.  It&#8217;s 800&#215;600, has a transparent background, and the flakes are just white circles.  I made this using <a href="http://www.gimp.org/">GIMP</a> in about 2 minutes.  It&#8217;s nothing fancy, just random dots.  I made it really tall and wide to try and hide the pattern when this repeats.  This first image is <em>snow0.gif</em>.</p>
<p>Next, I needed smaller flakes for the next layer.  I just scaled the first image down to 400&#215;300 and saved it as <em>snow1.gif</em>.</p>
<p>For the last level, I again just scaled the image down to 200&#215;150 and saved it as <em>snow2.gif</em>.</p>
<p>Next, I dynamically created the &#8220;layers&#8221; using JavaScript.  Each layer is a div element.  Each layer is absolutely positioned to fill the entire width and height.  The images are applied as background images to the layers, and the layers are given different z-indexes, so the &#8216;closer&#8217; layers are on top of the others.  With the attached images, it probably doesn&#8217;t matter much.<br />
But if your snow flakes had some sort of border or different coloring, you would be able to see the larger flakes falling in front of the smaller flakes.</p>
<p>Because I&#8217;m using absolute positioning, I needed to also adjust the content of my pages to also be absolutely positioned, so it could sit on top of my snow.  I&#8217;m not nuts about that, and if I really wanted to, I might be able to come up with a solution that didn&#8217;t use absolute positioning and instead just copied the main body content into one of the snow layers (with each layer nested in another layer).  But, hey, this was just for fun.  <img src='http://www.fotiweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Finally, I setup an interval to adjust the background postition of each layer, which is what gives it a &#8220;falling snow&#8221; effect.  I currently have it set at every 175ms, but you can adjust it as you like for a balance of performance and appearance (I wouldn&#8217;t go above 500 though as it will look too choppy). With each interval, it&#8217;s not doing anything too intensive. It&#8217;s basically just adjusting the background position and setting the style for each layer.  But even so, it will rev up CPU cycles as you set a smaller<br />
interval.</p>
<p>Below is the sample page.  Enjoy.</p>
<div style="overflow:scroll; width: 400px;">
<pre name="code" class="html">
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
  &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset:utf-8&quot;&gt;
  &lt;title&gt;Snow Example&lt;/title&gt;
  &lt;style type=&quot;text/css&quot;&gt;
body {
    background: #ccc;   /* Need some color other than white to see the snow */
    margin: 0;          /* Need to remove margin and padding for IE */
    padding: 0;
    height: 100%;       /* Need a defined height on the body so IE fills page */
}

/* These styles have nothing to do with functionality and can be deleted */
#container {
    margin: 2em;
    border: 3px solid black;
    background: #fff;
    padding: 2em;
    font-family: arial,sans-serif;
}
  &lt;/style&gt;

&lt;!-- Optional: put this in an external script file --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
/**
 * Setup a namespace.  I've chosen FOTI, as that's unlikely to conflict with
 * any other global methods.
 */
var FOTI = function() {
    // Create the 'background' container objects
    var snow = [ document.createElement(&quot;div&quot;),
                 document.createElement(&quot;div&quot;),
                 document.createElement(&quot;div&quot;) ];
    // Define a counter that will be incremented with each movement of snow
    var inc = 0;
    // Variable to hold the number of snow layers
    var n = 0;
    // Variable to hold the different style settings
    var styleRules = [ &quot;background-position:0px 0px&quot;,
                       &quot;background-image:none&quot;,
                       &quot;z-index:0&quot;,
                       &quot;background-repeat:repeat&quot;,
                       &quot;position:absolute;&quot;,
                       &quot;top:0&quot;,
                       &quot;left:0&quot;,
                       &quot;height:100%&quot;,
                       &quot;width:100%&quot;,
                       &quot;padding:0&quot;,
                       &quot;margin:0&quot; ];
    // Variable to hold instances of the style setting for each layer
    var styleInstances = [];
    // A small array copying method
    function copyStyles( arr ) {
        var that = [];
        for( var i = 0; i &lt; arr.length; i++)
        {
            that[i] = arr[i];
        }
        return that;
    }

    return {
        /**
         * Our snow initialization method.  Note, this assumes GIF images.
         * @param {String} container The id of the container element which will
         *         be absolutely positioned on top of our snowy background.
         * @param {String} pattern The pattern of the files to be used for the
         *         background images.  For example, if &quot;snow&quot; is passed as the
         *         value, then snow0.gif, snow1.gif, etc. will be the files
         * @param {String} imgExt The file extension of the images to be used.
         *         If no value is passed, the default &quot;gif&quot; will be used.
         *         used.
         * @dependency For each layer created, there must be an image named
         *         snowX.gif, where X is the layer number (starting at 0).
         */
        initSnow : function(container, pattern, imgExt) {
            var b = document.getElementsByTagName(&quot;body&quot;);
            var c = document.getElementById(container);
            var pattern = pattern || &quot;snow&quot;;
            var imgExt = imgExt || &quot;gif&quot;;

            if( !c ) { return; } // No container means no snow for you!

            n = snow.length;

            for( var i = 0; i &lt; snow.length; i++ )
            {
                // Customize the styles for each snow layer
                styleRules[1] = &quot;background-image:url(&quot; + pattern + i + &quot;.&quot; + imgExt + &quot;)&quot;;
                styleRules[2] = &quot;z-index:&quot; + (n - i);
                styleInstances[i] = copyStyles(styleRules);

                // Set the style attribute for the layer
                FOTI.domSetAttribute( snow[i], &quot;style&quot;, styleInstances[i].join(&quot;;&quot;) );

                // Insert the layer into body. Doesn't matter where since
                // we're absolutely positioning them.
                b[0].appendChild(snow[i]);
            }

            // Adjust the container style to be 'above' our snow layers
            FOTI.domSetAttribute( c, &quot;style&quot;, &quot;position: absolute; top: 0; left: 0; z-index: &quot; + (n+1) );

            // Set the snow in motion!
            setInterval(&quot;FOTI.fall()&quot;,175);
        },

        /**
         * Adjust the snowy background images to give the appearance of falling
         * snow.
         */
        fall : function() {
            // Increment the counter
            inc++;
            for( var i = 0; i &lt; n; i++ )
            {
                // Adjust the background position for this layer
                styleInstances[i][0] = &quot;background-position:&quot; + (2 * inc) + &quot;px&quot; + (2 * (inc * (n-i))) + &quot;px&quot;;
                FOTI.domSetAttribute( snow[i], &quot;style&quot;, (styleInstances[i]).join(&quot;;&quot;) );
            }
        },

        /**
         * Helper function to set an attribute on an element.
         */
        domSetAttribute : function( el, attr, val ) {
            var attrNode = el.getAttributeNode(attr);
            if (attrNode)
            {
                // IE is giving me problems with this.
                // Member not found.  I hate you IE!
                //attrNode.value = val;
                if( attr != &quot;style&quot; )
                {
                    attrNode.value = val;
                }
                else
                {
                    el.style.cssText = val;
                }
            }
            else
            {
                el.setAttribute(attr, val);
            }
        }
    };
}();
// Once the page is loaded, start the snow machine!
window.onload = function(){FOTI.initSnow(&quot;container&quot;,&quot;snow&quot;,&quot;gif&quot;);};
&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;container&quot;&gt;
      Let it snow!
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/12/07/snowy-backgrounds/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Happy Thanksgiving</title>
		<link>http://www.fotiweb.com/2007/11/21/happy-thanksgiving/</link>
		<comments>http://www.fotiweb.com/2007/11/21/happy-thanksgiving/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 19:41:36 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=33</guid>
		<description><![CDATA[This year, I&#8217;m thankful for&#8230;

A baby on the way
My lovable dog
Friends and family
A wonderful job

But most importantly, I&#8217;m thankful for my amazing wife, Laura.  Love you babe!  
]]></description>
			<content:encoded><![CDATA[<p>This year, I&#8217;m thankful for&#8230;</p>
<ul>
<li>A baby on the way</li>
<li>My lovable dog</li>
<li>Friends and family</li>
<li>A wonderful job</li>
</ul>
<p>But most importantly, I&#8217;m thankful for my amazing wife, Laura.  Love you babe!  <img src='http://www.fotiweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/11/21/happy-thanksgiving/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why I am Starting to Hate Comcast</title>
		<link>http://www.fotiweb.com/2007/11/14/why-i-am-starting-to-hate-comcast/</link>
		<comments>http://www.fotiweb.com/2007/11/14/why-i-am-starting-to-hate-comcast/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 20:46:41 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=32</guid>
		<description><![CDATA[I&#8217;ve had pretty good service with Comcast for years, but over the past 12 months or so I&#8217;ve become increasingly unhappy with them.  This week they&#8217;ve really pissed off a lot of users.
It seems that Comcast disabled the serial (aka &#8220;data&#8221;) port on their cable modems for users in the New England area (and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had pretty good service with <a href="http://www.comcast.com" rel="nofollow">Comcast</a> for years, but over the past 12 months or so I&#8217;ve become increasingly unhappy with them.  This week they&#8217;ve really pissed off a lot of users.</p>
<p>It seems that Comcast disabled the serial (aka &#8220;data&#8221;) port on their cable modems for users in the New England area (and possibly some other areas).  For many customers, this means nothing.  However, <a href="http://www.tivo.com">TiVo</a> users who had their TiVo connected to their cable box serial port (for changing channels) were suddenly left with no way to change the channel.  Is this Comcast&#8217;s way of trying to force TiVo users to switch to Comcast&#8217;s DVR?  Was this an intentional change or was it an accident?  Their tech support has not been helpful, acting somewhat clueless about the issue.  Though, finally, they seem to be acknowledging that they&#8217;re receiving a lot of complaints and are &#8220;looking into it.&#8221;</p>
<p>In the mean time, TiVo users can switch to a different cable (the less reliable IR cable) if they can find them (I was fortunate and knew exactly where mine were).  Those who don&#8217;t have them can buy them online (and I would guess at a local electronics store).</p>
<p>I hope Comcast fixes this problem.  If they don&#8217;t, rather than buy Comcast&#8217;s DVR, I&#8217;d be more likely to move away from Comcast entirely (I&#8217;d love to get <a href="http://www.verizonfios.com">FiOS</a> when it&#8217;s available in my area).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/11/14/why-i-am-starting-to-hate-comcast/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript Namespaces</title>
		<link>http://www.fotiweb.com/2007/10/31/javascript-namespaces/</link>
		<comments>http://www.fotiweb.com/2007/10/31/javascript-namespaces/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 22:17:49 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=28</guid>
		<description><![CDATA[Note: The code in this posting has been strongly influenced by the Yahoo UI Library (an EXCELLENT library).  I&#8217;ve made some modifications, but in many cases my code was functionally equivalent (if not identical) to the code in the library.
&#8220;Who&#8221; Should Do This
Everyone writing JavaScript.
&#8220;What&#8221; Is This
Creating a single global JavaScript object that will [...]]]></description>
			<content:encoded><![CDATA[<p>Note: The code in this posting has been strongly influenced by the <a href="http://developer.yahoo.com/yui/">Yahoo UI Library</a> (an EXCELLENT library).  I&#8217;ve made some modifications, but in many cases my code was functionally equivalent (if not identical) to the code in the library.</p>
<h3>&#8220;Who&#8221; Should Do This</h3>
<p>Everyone writing JavaScript.</p>
<h3>&#8220;What&#8221; Is This</h3>
<p>Creating a single global JavaScript object that will contain all of your JavaScript.</p>
<h3>&#8220;Where&#8221; Should This Live</h3>
<p>The primary namespace should be in its own script file.</p>
<h3>&#8220;When&#8221; Should I Do This</h3>
<p>Any time you write JavaScript.</p>
<h3>&#8220;Why&#8221; Should I Do This</h3>
<p>Avoid conflicts with other scripts.<br />
Create code that is more manageable and portable.<br />
Better memory management via scoped objects.</p>
<h3>&#8220;How&#8221; Should I Do This</h3>
<p>First, <strong>choose a name that represents your root/base namespace</strong>.  It should be short in length, but unique enough that it won&#8217;t conflict with other global variables.  Your name (or organization name), abbreviation of the name, or an acronym is a good place to start.</p>
<p>For example, if your organization was &#8220;ACME, Inc.&#8221;, you might use &#8220;<em>ACME</em>&#8221; as your namespace name.  If you are an individual developer, you might choose your initials.  For my examples, I&#8217;m going to use &#8220;<em>FOTI</em>&#8221; as the namespace name.  Note, I&#8217;m using all UPPERCASE letters to define my namespace.  This convention seems to be the norm, and I like it because I think there is less chance for global conflicts this way (it also makes more sense for those who use initials).</p>
<p>To create the namespace, lets start with the following in a file of its own (obviously, replace all instances of FOTI with your own namespace):<br />
<strong>foti.js</strong></p>
<pre name="code" class="js">
if ((typeof FOTI == "undefined") || (null == FOTI)) {
    /**
     * The FOTI object is the global (namespace) object used by the FOTI
     * JavaScript Library.  All FOTI objects reside within this object scope.
     */
    var FOTI = {};
}
</pre>
<p>This checks to see if a global FOTI object already exists, and creates a new empty object if it does not.  This is the base from which all of our work will reside.  Note that I&#8217;ve chosen the method of checking if the variable FOTI is undefined (meaning declared but not assigned, or simply not declared) or null (meaning it has been declared and assigned, but now contains a null value).  Essentially, I&#8217;m checking to make sure that I have a valid object that I can add methods and properties to.</p>
<p>Next we&#8217;ll want to add the ability to create additional inner namespaces.  For example, I may want the following namespaces:<br />
FOTI.util<br />
FOTI.page<br />
FOTI.widget<br />
FOTI.widget.controls</p>
<p>In order to facilitate this, I&#8217;m going to add a method to our global object for creating nested namespaces.  This is based off of the <a href="http://developer.yahoo.com/yui/">Yahoo UI Library</a>&#8217;s <a href="http://developer.yahoo.com/yui/yahoo/">YAHOO</a> object, but I&#8217;ve taken a slightly different approach.  My method will take a single argument, which is a string or an array of strings (allowing for multiple namespaces to be created at the same time).  Here&#8217;s that method:</p>
<pre name="code" class="js">
/**
 * Create the specified namespace(s)
 * @static
 * @param  {String | Array} s Namespaces to create
 * @return {Object}  A reference to the last
 * namespace object created or an empty global
 * object if the namespace couldn't be created
 */
FOTI.namespace = function(s) {
    var a, o, i, j, d;
    // Determine if s is string or array and
    // force it to an array
    if (typeof s === 'string') {
        a = [s];
    }
    else if (s.length !== undefined) {
        a = s;
    }
    else {
        // Neither a string or an array was passed in, so exit
        return {};
    }
    for (i = 0; i &lt; a.length; i++) {
        d = a[i].split(".");
        o = FOTI;
        // FOTI is implied, so it is ignored if it is included
        for (j = (d[0] == "FOTI") ? 1 : 0; j &lt; d.length; j++) {
            o[d[j]] = o[d[j]] || {};
            o = o[d[j]];
        }
    }
    return o;
};
</pre>
<p>Now we&#8217;ve got a nice way to setup multiple namespaces contained within our global FOTI namespace.  So I&#8217;m going to add a self-invoking anonymous function that will create some default namespaces:</p>
<pre name="code" class="js">
(function() {
    FOTI.namespace(["util", "page", "widget.control"]);
})();
</pre>
<p>Great!  Now, how can we put this to use?<br />
One use for this is to contain the scripts for our individual pages within our global object.  This will help prevent conflicts with other scripts.  So lets start by creating an empty HTML page.  This is going to be our &#8220;home&#8221; page:</p>
<pre name="code" class="php">
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset:utf-8"&gt;
  &lt;title&gt;Home&lt;/title&gt;
  &lt;script type="text/javascript" src="http://yui.yahooapis.com/2.3.1/build/yahoo-dom-event/yahoo-dom-event.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/inc/js/foti/foti.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/inc/js/foti/page/home.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="container"&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>You&#8217;ll note that I&#8217;ve included the <a href="http://developer.yahoo.com/yui/">Yahoo UI Library</a>&#8217;s yahoo-dom-event script.  That&#8217;s because the exceptional DOM and Event handling Utilities give me a lot of bang for my buck.  I&#8217;m going to use the Yahoo Event Utility extensively.</p>
<p>Next, lets create the stub for our home page&#8217;s main script.  This is going to be a singleton (only 1 instance of this script will ever be needed) so you&#8217;ll note that I&#8217;m assigning the result of a self-invoking function to the FOTI.page.home property.  I use the YUI Event Utility to call the init method when the page has loaded, and I&#8217;m giving FOTI.page.home the scope for &#8216;this&#8217;:</p>
<pre name="code" class="js">
FOTI.page.home = function() {
    return {
        init : function() {
            alert(this.greeting);
        },
        greeting : "Welcome!"
    };
}();
YAHOO.util.Event.on(window, 'load', FOTI.page.home.init, FOTI.page.home, true);
</pre>
<p>There you have it.  We&#8217;ve created our Global namespace object (FOTI), we added a sub-namespace object (page) which has a property (home) that contains an instance of an object for our current page&#8217;s scripts (this object has the properties init and greeting).  We can add all of our page-specific scripts to this object and we&#8217;ve avoided conflicts with all other global objects by containing them in our nice and neat namespaces.</p>
<p>Well, that&#8217;s all for now. I could probably continue to elaborate, clean up, and expand this example.  But this post is getting pretty long as it is.  Enjoy. <img src='http://www.fotiweb.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/10/31/javascript-namespaces/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Syntax Highlighting</title>
		<link>http://www.fotiweb.com/2007/10/31/syntax-highlighting/</link>
		<comments>http://www.fotiweb.com/2007/10/31/syntax-highlighting/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 21:07:01 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=30</guid>
		<description><![CDATA[I&#8217;m about to roll out some design changes which include a nifty &#8220;Syntax Highlighter&#8221;.  Code examples will now be much nicer looking.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m about to roll out some design changes which include a nifty <a href="http://code.google.com/p/syntaxhighlighter/">&#8220;Syntax Highlighter&#8221;</a>.  Code examples will now be much nicer looking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/10/31/syntax-highlighting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Trash Management</title>
		<link>http://www.fotiweb.com/2007/10/24/trash-management/</link>
		<comments>http://www.fotiweb.com/2007/10/24/trash-management/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 18:53:03 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=29</guid>
		<description><![CDATA[There&#8217;s been a lot of news in the past year about global warming, carbon footprints, and being environmentally friendly.  I&#8217;ve never considered myself an environmentalist, but lately I&#8217;ve felt as though I&#8217;d like to do more for the environment.  I should be able to train myself to use better habits, which I can [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s been a lot of news in the past year about global warming, carbon footprints, and being environmentally friendly.  I&#8217;ve never considered myself an environmentalist, but lately I&#8217;ve felt as though I&#8217;d like to do more for the environment.  I should be able to train myself to use better habits, which I can then pass on to my children.  If everyone did this, the world would be a cleaner place.</p>
<p>My town dump requires us to sort our trash.  We recycle glass, cans, milk jugs, paper, scrap metal, etc.  But the hard part is how to manage all of these different types of trash at home.  How should one store all of these different types of trash?  I&#8217;d like to see someone invent a super trash management system (probably comprised of several smaller waste baskets, each in their own cabinet), that could store different trash types:</p>
<ul>
<li>Glass</li>
<li>Soda Cans (redeemable)</li>
<li>Cans/foil</li>
<li>Paper</li>
<li>Cardboard</li>
<li>Gallon Jugs</li>
<li>Plastics (redeemable)</li>
<li>Batteries</li>
<li>Bio-waste (food, etc.)</li>
<li>Other trash</li>
</ul>
<p>Can you think of any other items that would be good to sort?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/10/24/trash-management/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parents Getting Domain Names For Newborns</title>
		<link>http://www.fotiweb.com/2007/08/23/parents-getting-domain-names-for-newborns/</link>
		<comments>http://www.fotiweb.com/2007/08/23/parents-getting-domain-names-for-newborns/#comments</comments>
		<pubDate>Thu, 23 Aug 2007 15:29:51 +0000</pubDate>
		<dc:creator>Peter Foti</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.fotiweb.com/?p=25</guid>
		<description><![CDATA[I read an article on CNN today about parents registering domain names and setting up GMail and Hotmail email accounts for newborns when they&#8217;re born.  I think that&#8217;s a great idea&#8230; setting aside a little bit of cyberspace realty.
]]></description>
			<content:encoded><![CDATA[<p>I read an <a href="http://www.cnn.com/2007/TECH/08/22/kids.domains.ap/index.html?eref=rss_tech">article</a> on CNN today about parents registering domain names and setting up GMail and Hotmail email accounts for newborns when they&#8217;re born.  I think that&#8217;s a great idea&#8230; setting aside a little bit of cyberspace realty.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fotiweb.com/2007/08/23/parents-getting-domain-names-for-newborns/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
