<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Emanuele Feronato &#187; Javascript</title>
	<atom:link href="http://www.emanueleferonato.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Thu, 11 Mar 2010 00:11:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create a dynamic content animated footer ad for your site in just 9 jQuery lines &#8211; 17 lines version</title>
		<link>http://www.emanueleferonato.com/2010/03/10/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-9-jquery-lines-17-lines-version/</link>
		<comments>http://www.emanueleferonato.com/2010/03/10/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-9-jquery-lines-17-lines-version/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 17:35:09 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2510</guid>
		<description><![CDATA[Some days ago I showed you how to create a dynamic content animated footer ad for your site in just 9 jQuery lines.
Now it&#8217;s time to write eight more lines to add two important features:
The first, as suggested in a comment, is allowing to set a delay before the ad appears.
The second is using a [...]]]></description>
			<content:encoded><![CDATA[<p>Some days ago I showed you how to <a href="http://www.emanueleferonato.com/2010/03/03/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-15-jquery-lines/">create a dynamic content animated footer ad for your site in just 9 jQuery lines</a>.</p>
<p>Now it&#8217;s time to write eight more lines to add two important features:</p>
<p>The first, as suggested in a comment, is allowing to set a delay before the ad appears.</p>
<p>The second is using a cookie to let the ad appear only once in a session. This means if you refresh the page, the ad won&#8217;t appear again, until you close the browser window and open it again.</p>
<p><a href="http://www.emanueleferonato.com/stuff/triqui_ad/index2.html" target = "_blank">This is what we&#8217;ll get</a>&#8230; the ad appears after three seconds, and only once in a session.</p>
<p>Now let&#8217;s see the new lines added:<span id="more-2510"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$.<span style="color: #660066;">delay</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>time<span style="color: #339933;">,</span>ret_function<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>timer<span style="color: #339933;">:</span>setTimeout<span style="color: #009900;">&#40;</span>ret_function<span style="color: #339933;">,</span>time<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> delayed_start <span style="color: #339933;">=</span> <span style="color: #CC0000;">3000</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> path_to_dynamic_file <span style="color: #339933;">=</span> <span style="color: #3366CC;">'ajax.php'</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cookie</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;triqui_ad&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		document.<span style="color: #660066;">cookie</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;triqui_ad=1&quot;</span><span style="color: #339933;">;</span>
		$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>cache<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">wrap</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;triqui_container&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> delayed_start <span style="color: #339933;">=</span> $.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span>delayed_start<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span>path_to_dynamic_file<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &amp;bull; &lt;a id=&quot;triqui_ad_close&quot;&gt;Close&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad_close'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		   			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		  		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><strong>Lines 3-6</strong>: Declaring a new jQuery function called <code>delay</code>, that&#8217;s just a callback after a given amount of milliseconds. </p>
<p><strong>Line 8</strong>: Variable storing the number of milliseconds to wait before showing the ad</p>
<p><strong>Line 9</strong>: Variable storing the path to the dynamic file</p>
<p><strong>Line 10</strong>: Checking if I have a cookie called <code>triqui_ad</code>. The statement is true if I don&#8217;t have it.</p>
<p><strong>Line 11</strong>: Creating a cookie called <code>triqui_ad</code>. Since there is not an expiration date, it will expire when the user will close the browser.</p>
<p><strong>Line 14</strong>: The entire function explained in <a href="http://www.emanueleferonato.com/2010/03/03/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-15-jquery-lines/">part 1</a> is executed only after the preset delay.</p>
<p>And that&#8217;s it&#8230; any idea for additional features?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/03/10/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-9-jquery-lines-17-lines-version/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create a dynamic content animated footer ad for your site in just 9 jQuery lines</title>
		<link>http://www.emanueleferonato.com/2010/03/03/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-15-jquery-lines/</link>
		<comments>http://www.emanueleferonato.com/2010/03/03/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-15-jquery-lines/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 21:50:49 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2460</guid>
		<description><![CDATA[Have you ever seen those ads sliding up from the bottom of your page when you are visiting a website? We are going to create a simple one in just 9 jQuery lines.
Moreover, with this script you will need to add just one line to your site to display the ad.
Just to make it easier [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever seen those ads sliding up from the bottom of your page when you are visiting a website? We are going to create a simple one in just 9 <a href="http://jquery.com/" target  "_blank">jQuery</a> lines.</p>
<p>Moreover, with this script you will need to add just one line to your site to display the ad.</p>
<p>Just to make it easier to understand, I am showing you for free the principles some &#8220;companies&#8221; <a href="http://www.google.com/webhp?hl=en#hl=en&#038;source=hp&#038;q=footer+ad&#038;rlz=1R2GZAZ_enIT351&#038;aq=f&#038;aqi=g10&#038;aql=&#038;oq=&#038;fp=f15a301262521d7" target = "_blank">sell at more than $40</a>. According to such sites, ads like the one we are about to make should increase your conversions, have more readers sign up to your newsletter, and make you live in harmony. All in one-</p>
<p>Unfortunately, I am only showing you how to create such ad in a bunch of jQuery lines.</p>
<p>This is what we are going to make: <a href="http://www.emanueleferonato.com/stuff/triqui_ad/" target = "_blank">Watch the example</a>.</p>
<p>Ready for the recipe? Here we go:</p>
<p><strong>A web page</strong></p>
<p>Obviously, you need a webpage. Any webpage will fit, as long as you include</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;triqui_ad&quot;&gt;&lt;/div&gt;</pre></div></div>

<p>just before the <code>&lt;/body&gt;</code> tag.</p>
<p><strong>jQuery</strong></p>
<p>Then it&#8217;s time to add the power of jQuery to the page: insert this script between <code>&lt;head&gt;</code> and <code>&lt;/head&gt;</code><span id="more-2460"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>cache<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">wrap</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;triqui_container&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ajax.php'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' &amp;bull; &lt;a id=&quot;triqui_ad_close&quot;&gt;Close&lt;/a&gt; '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_ad_close'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
   			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#triqui_container'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><strong>Line 1</strong>: loading the latest jQuery version. I am loading it directly from Google to get the latest stable version with no stress for my server.</p>
<p><strong>Line 3</strong>: Function to be executed when the document DOM is fully loaded.</p>
<p><strong>Line 4</strong>: Disabling the cache when using Ajax calls. That&#8217;s why when you reload the page in the <a href="http://www.emanueleferonato.com/stuff/triqui_ad/" target = "_blank">example</a>, you always get the current timestamp</p>
<p><strong>Line 5</strong>: I had to add this line because I wanted the final user to type in as less code as possible, so at the moment you just have to add</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;triqui_ad&quot;&gt;&lt;/div&gt;</pre></div></div>

<p>while the &#8220;real&#8221; code should be</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id = &quot;triqui_container&quot;&gt;&lt;div id=&quot;triqui_ad&quot;&gt;&lt;/div&gt;&lt;/div&gt;</pre></div></div>

<p>Using <code>wrap</code> you will (guess what?) wrap an HTML structure around the selected element.</p>
<p><strong>Line 6</strong>: This is the most important line. I am loading the result of the Ajax call made on the <code>ajax.php</code> file. This means I am printing inside the <code>div</code> everything <code>ajax.php</code> will echo. In my case, it will print the current date since this is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Hello, I am a dynamic content created on &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'l jS \of F Y h:i:s A'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>As you can imagine, <code>load</code> loads data from the server and place the returned HTML into the matched element. The only issue is it caches the result, that&#8217;s why I disabled it at <strong>line 4</strong></p>
<p><strong>Line 7</strong>: Here I am showing the content of the div containing the ad. When you&#8217;ll look at the css, you&#8217;ll find there was a <code>display:none</code> to keep it hidden until the script is ready to work.</p>
<p><strong>Line 8</strong>: Time to slide in the ad</p>
<p><strong>Line 9</strong>: Appending a link to close the ad</p>
<p><strong>Line 10</strong>: Triggering the link used to close the ad</p>
<p><strong>Line 11</strong>: Sliding away the ad when the user clicks on the link</p>
<p><strong>CSS</strong></p>
<p>And finally it&#8217;s time to stylize the ad.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#triqui_container</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#triqui_ad</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e5e5e5</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#triqui_ad_close</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>You can custom the stylesheet as you want as long as you set <code>display:none</code> to the ad and <code>position:fixed</code> and <code>bottom:0</code> to the container.</p>
<p>Have fun&#8230; would you like more options?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/03/03/create-a-dynamic-content-animated-footer-ad-for-your-site-in-just-15-jquery-lines/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Placing ads before a game loads with jQuery</title>
		<link>http://www.emanueleferonato.com/2009/12/30/placing-ads-before-a-game-loads-with-jquery/</link>
		<comments>http://www.emanueleferonato.com/2009/12/30/placing-ads-before-a-game-loads-with-jquery/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 11:50:08 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Monetize]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2143</guid>
		<description><![CDATA[When you run a Flash game portal or a Flash game official site, you normally place ads everywhere hoping someone will notice it.
Obviously the most interesting place where to place ads is already taken by the game itself, so we are going to create a javascript preloader that will show an ad for 15 seconds [...]]]></description>
			<content:encoded><![CDATA[<p>When you run a Flash game portal or a Flash game official site, you normally place ads everywhere hoping someone will notice it.</p>
<p>Obviously the most interesting place where to place ads is already taken by the game itself, so we are going to create a javascript preloader that will show an ad for 15 seconds before the game starts loading.</p>
<p>In order to do it, you need <a target = "_blank" href="http://jquery.com/">jQuery</a> and <a href="http://code.google.com/p/swfobject/" target ="_blank">swfobject</a></p>
<p>Now let&#8217;s suppose the game has to be embedded in a <code>div</code> called <code>the_game</code>, just like I did in my <a target = "_blank" href="http://www.barbalance-game.com/">BarBalance official site</a>.</p>
<p>Just create the <code>div</code> this way:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id = &quot;the_game&quot;&gt;
	&lt;h1&gt;BarBalance game is loading&lt;/h1&gt;
	&lt;SCRIPT language=&quot;Javascript&quot;&gt;
	var cpmstar_rnd=Math.round(Math.random()*999999);
	var cpmstar_pid=10016;
	document.writeln(&quot;&lt;SCR&quot;+&quot;IPT language='Javascript' src='http://server.cpmstar.com/view.aspx?poolid=&quot;+cpmstar_pid+&quot;&amp;script=1&amp;rnd=&quot;+cpmstar_rnd+&quot;'&gt;&lt;/SCR&quot;+&quot;IPT&gt;&quot;);
	&lt;/SCRIPT&gt;
&lt;/div&gt;</pre></div></div>

<p>I used some SEO like an <code>h1</code> tag and relevant content, and a <a href="http://www.cpmstar.com/" target = "_blank">CPMStar</a> because it&#8217;s animated and we suppose won&#8217;t bore the player during the 15 seconds.</p>
<p>If you don&#8217;t have a CPMStar account, feel free to use my code :)</p>
<p>Then the jQuery part:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function(){
		setTimeout(function(){
			$(&quot;#the_game&quot;).fadeOut(2000,function(){
				swfobject.embedSWF(&quot;barbalance.swf&quot;, &quot;the_game&quot;, &quot;640&quot;, &quot;480&quot;, &quot;9.0.0&quot;);
			}); 
		},15000);
	}); 
&lt;/script&gt;</pre></div></div>

<p>It&#8217;s just a 15000 milliseconds timeout fading out with a callback replacing the existing content with the Flash game.</p>
<p>Look at  <a target = "_blank" href="http://www.barbalance-game.com/">BarBalance official site</a> to see it working.</p>
<p>I can&#8217;t wait to know this ad eCPM&#8230; did you already use something similar?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/12/30/placing-ads-before-a-game-loads-with-jquery/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JQuery powered lights off effect</title>
		<link>http://www.emanueleferonato.com/2009/10/12/jquery-powered-lights-off-effect/</link>
		<comments>http://www.emanueleferonato.com/2009/10/12/jquery-powered-lights-off-effect/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 14:58:07 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Css]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1735</guid>
		<description><![CDATA[A couple of days ago a fan of my Facebook page asked me for a script to make the effect you see on this page.
Obviously simply reverse-engineering the script wouldn&#8217;t be enough for me, so I decided to create a lights off effect that make any content in a given div remain highlighted while the [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago a fan of <a target = "_blank" href="http://www.facebook.com/pages/Emanuele-Feronato/50374255154">my Facebook page</a> asked me for a script to make the effect you see on <a href="http://test.jackread.co.uk/LightsOff/lightsoff.htm" target = "_blank">this page</a>.</p>
<p>Obviously simply reverse-engineering the script wouldn&#8217;t be enough for me, so I decided to create a lights off effect that make <strong>any</strong> content in a given <code>div</code> remain highlighted while the rest of the page fades to black (or to any color).</p>
<p>I used <a target = "_blank" href="http://jquery.com/">JQuery</a> to manage the fade effect because it&#8217;s the best Javascript library available at the moment.</p>
<p>As a developer, I also tried MooTools and scriptaculous but believe me <a target = "_blank" href="http://jquery.com/">JQuery</a> is some steps ahead.</p>
<p>Now let&#8217;s see this script:<span id="more-1735"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
     &lt;head&gt;
          &lt;title&gt;Emanuele Feronato's lights off effect&lt;/title&gt;
          &lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
          &lt;script&gt;
               $(document).ready(function(){
                    $(&quot;#the_lights&quot;).fadeTo(1,0);
                    $(&quot;#turnoff&quot;).click(function () {
                         $(&quot;#the_lights&quot;).css({'display' : 'block'});
                         $(&quot;#the_lights&quot;).fadeTo(&quot;slow&quot;,1);
                    });
                    $(&quot;#soft&quot;).click(function () {
                         document.getElementById(&quot;the_lights&quot;).style.display=&quot;block&quot;;
                         $(&quot;#the_lights&quot;).fadeTo(&quot;slow&quot;,0.8);
                    });
                    $(&quot;#turnon&quot;).click(function () {
                         document.getElementById(&quot;the_lights&quot;).style.display=&quot;block&quot;;
                         $(&quot;#the_lights&quot;).fadeTo(&quot;slow&quot;,0);
                    });
               });
          &lt;/script&gt;
          &lt;style&gt;
               html{
                    width:100%;
                    height:100%;
                    margin:0px;
               }
               #the_lights{
	              background-color:#000;
	              height:100%;
	              width:100%;
	              position:absolute;
	              top:0;
	              left:0;
	              display:none;
               }
               #standout{
                    padding:5px;
                    background-color:white;
                    position:relative;
                    z-index:1000;
               }
          &lt;/style&gt;
     &lt;/head&gt;
&lt;body&gt;
     &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas scelerisque libero euismod nulla porttitor egestas. Nulla fermentum facilisis sagittis. Vestibulum commodo pretium diam, vitae scelerisque lectus bibendum nec. Curabitur a metus est. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed nunc dolor, pretium eget venenatis ut, condimentum at sem. Vivamus rhoncus ullamcorper turpis. Aliquam sit amet risus diam, vel mattis est. Quisque sodales eros id nulla rhoncus posuere. Nullam accumsan lorem quis dolor tempor congue. Vivamus ligula augue, commodo malesuada tempor non, tristique id enim. Sed dapibus sagittis porttitor. Suspendisse faucibus scelerisque eros, ac hendrerit orci scelerisque sit amet.&lt;/p&gt;
     &lt;div id = &quot;standout&quot;&gt;&lt;p&gt;Everything inside this div will remain highlighted&lt;/p&gt;&lt;div id = &quot;turnoff&quot;&gt;Lights off&lt;/div&gt;&lt;div id = &quot;soft&quot;&gt;Soft lights&lt;/div&gt;&lt;div id = &quot;turnon&quot;&gt;Lights on&lt;/div&gt;&lt;/div&gt;
     &lt;p&gt;Vestibulum interdum, odio ut congue imperdiet, justo ligula bibendum nisl, ac placerat orci eros nec tortor. Maecenas rhoncus felis vitae elit consectetur vitae mattis metus tincidunt. Donec nec ipsum quis tellus posuere ultricies. Ut tempus tortor nec sem blandit ut facilisis nisl scelerisque. Nulla venenatis ante sit amet nisi dictum varius. Etiam congue dui eu diam fermentum et tincidunt magna egestas. Sed tincidunt magna et metus molestie malesuada. Nam tempus dignissim porta. Vivamus iaculis, orci hendrerit condimentum viverra, eros nisl euismod arcu, nec pulvinar tellus elit eu nulla. Vestibulum mattis, ligula sit amet euismod commodo, augue lorem fermentum magna, et rhoncus nisl urna nec purus. Suspendisse potenti. Fusce fermentum orci at orci posuere ornare a imperdiet justo. In hac habitasse platea dictumst. Duis adipiscing leo nec risus varius auctor. Cras sed erat massa, quis egestas leo. Vivamus dignissim lacinia leo, ac interdum nisi facilisis eget.&lt;/p&gt;
     &lt;div id=&quot;the_lights&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>The <code>div</code> is the one called <code>standout</code> at <strong>line 48</strong> and it has nothing special but a background color (it can&#8217;t be transparent) and a z-index along with a relative position (<strong>lines 40-42</strong>).</p>
<p>Obviously the z-index should be higher than the rest of the elements.</p>
<p>The other interesting <code>div</code> is <code>the_lights</code> (<strong>line 50</strong>), a black div covering all the page, initially invisible (<strong>lines 30-36</strong>). Playing with its transparency will simulate the lights effect</p>
<p>Now it&#8217;s all a matter of JQuery:</p>
<p><strong>Line 7</strong>: Listening for the document to be ready</p>
<p><strong>Line 8</strong>: Once it&#8217;s ready, the first thing is setting <code>the_lights</code> alpha to zero. I don&#8217;t set it from CSS but use <code>fadeTo</code> because I need to initialize the fading process. The entire lights out effect is just playing with <code>the_lights</code> and some tweening.</p>
<p><strong>Line 9</strong>: Here I am listening for the <code>turnoff</code> div to be clicked</p>
<p><strong>Line 10</strong>: Showing <code>the_lights</code> div&#8230; this is the same thing as<br />
<code>document.getElementById('the_lights').style.display='block'</code></p>
<p><strong>Line 11</strong>: Fading the black div to full opacity.</p>
<p>This will give the &#8220;lights out effect&#8221;</p>
<p>Try the <a href="/stuff/lightsoff/" target = "_blank">example at this page</a> will show you the effect&#8230; click on &#8220;lights on&#8221;, &#8220;lights off&#8221; or &#8220;soft lights&#8221; and see what happens.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/10/12/jquery-powered-lights-off-effect/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Interesting jQuery effect</title>
		<link>http://www.emanueleferonato.com/2009/05/25/interesting-jquery-effect/</link>
		<comments>http://www.emanueleferonato.com/2009/05/25/interesting-jquery-effect/#comments</comments>
		<pubDate>Mon, 25 May 2009 20:47:52 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1265</guid>
		<description><![CDATA[You know I am trying to use Gallery theme for triqui.com
Yesterday I played a bit with the theme and I completely screwed everything&#8230; something like &#8220;how to destroy a complex theme in a matter of minutes&#8221;.
Then I decided to code something similar by myself. That&#8217;s the only way I know to custom everything whenever I [...]]]></description>
			<content:encoded><![CDATA[<p>You know I am trying to use <a href="http://www.emanueleferonato.com/2009/05/11/gallery-free-wordpress-theme-good-start-for-a-wp-arcade-site/">Gallery</a> theme for <a href="http://www.triqui.com/" target ="_blank">triqui.com</a></p>
<p>Yesterday I played a bit with the theme and I completely screwed everything&#8230; something like &#8220;how to destroy a complex theme in a matter of minutes&#8221;.</p>
<p>Then I decided to code something similar by myself. That&#8217;s the only way I know to custom everything whenever I want.</p>
<p>One of the best features of Gallery theme is the slider effect, so I played a bit with <a href="http://jquery.com/" target = "_blank">jQuery</a> until I achieved something similar.</p>
<p>I have to say I tried to make it with <a href="http://script.aculo.us/" target ="_blank">Scriptaculous</a> but for these simple effects nothing beats jQuery in my opinion.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE HTML <span style="color: #003366; font-weight: bold;">PUBLIC</span> <span style="color: #3366CC;">&quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;</span> <span style="color: #3366CC;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
          $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#block&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;marginTop&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;-30px&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;linear&quot;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseout</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;slow&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#block&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;marginTop&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0px&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;fast&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span> 
     #container<span style="color: #009900;">&#123;</span>
          border<span style="color: #339933;">:</span>1px solid black<span style="color: #339933;">;</span>
          width<span style="color: #339933;">:</span>100px<span style="color: #339933;">;</span>
          height<span style="color: #339933;">:</span>100px<span style="color: #339933;">;</span>
          overflow<span style="color: #339933;">:</span>hidden<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     #block<span style="color: #009900;">&#123;</span>
          padding<span style="color: #339933;">:</span>0px
     <span style="color: #009900;">&#125;</span>
     #text<span style="color: #009900;">&#123;</span>
          font<span style="color: #339933;">:</span>normal 10px verdana<span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>div id <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;container&quot;</span><span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;block&quot;</span><span style="color: #339933;">&gt;</span>
               <span style="color: #339933;">&lt;</span>img src <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;image.png&quot;</span><span style="color: #339933;">&gt;</span>
               <span style="color: #339933;">&lt;</span>div id <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span><span style="color: #339933;">&gt;</span>
                    Not the classic <span style="color: #3366CC;">&quot;Lorem Ipsum&quot;</span>
               <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
          <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><strong>Line 6</strong>: importing jQuery library</p>
<p><strong>Line 8</strong>: we can call it a listener for the document to be ready. When it&#8217;s ready, it executes the function</p>
<p><strong>Line 9</strong>: fading the content of the <code>text</code> element to transparent. This way I am starting with a transparent text. Obviously I can set this from the css declaration, but I wanted to do it with jQuery because it&#8217;s cool :)</p>
<p><strong>Line 10</strong>: this is a listener for the <code>container</code> element. Listens for the mouse to be over it.</p>
<p><strong>Line 11</strong>: stopping previous animations and moving the <code>block</code> element (the image with the text) up by 25 pixels and once the animation finishes, fades in the <code>text</code> element. This replicates the <a href="http://www.emanueleferonato.com/2009/05/11/gallery-free-wordpress-theme-good-start-for-a-wp-arcade-site/">Gallery</a> rollover effect, and I can display text on multiple rows. The <code>overlow:hidden</code> style at <strong>line 24</strong> gives the feeling the image is sliding like a garage door and not simply moving.</p>
<p>Do not use relative positioning in <code>block</code> element or it won&#8217;t work on IE7 (yet anohter IE7 bug&#8230;)</p>
<p><strong>Line 13</strong>: listener for the mouse leaving the <code>container</code> element</p>
<p><strong>Line 14</strong>: fading away <code>text</code> element and moving the <code>block</code> element to its original position</p>
<p>And this is the result. As you can see it&#8217;s pretty similar to the original <a href="http://www.emanueleferonato.com/2009/05/11/gallery-free-wordpress-theme-good-start-for-a-wp-arcade-site/">Gallery</a> effect.</p>
<p><iframe src = "/stuff/jquery/index.html" frameborder="0"></iframe></p>
<p>Move the mouse on the image and see</p>
<p><a href="/stuff/jquery/jquery.zip">Download the source code</a> with jQuery compressed library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/05/25/interesting-jquery-effect/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GameJS and gameQuery: two javascript libraries for game developers</title>
		<link>http://www.emanueleferonato.com/2009/03/05/gamejs-and-gamequery-two-javascript-libraries-for-game-developers/</link>
		<comments>http://www.emanueleferonato.com/2009/03/05/gamejs-and-gamequery-two-javascript-libraries-for-game-developers/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:00:09 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Game design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=1024</guid>
		<description><![CDATA[During late 90&#8217;s web games as we know them did not exist.
At that time Javascript was the only language used to make some simple browser games.
Years passed, and Flash became the leading tool to make Flash games. Anyway, I want to point you to two javascript libraries made for game developers.
While you can&#8217;t obviously compare [...]]]></description>
			<content:encoded><![CDATA[<p>During late 90&#8217;s web games as we know them did not exist.</p>
<p>At that time Javascript was the only language used to make some simple browser games.</p>
<p>Years passed, and Flash became the leading tool to make Flash games. Anyway, I want to point you to two javascript libraries made for game developers.</p>
<p>While you can&#8217;t obviously compare the games you can make to modern Flash action games, I am sure you can code some decent puzzle games. Some months ago I made a <a href="http://www.emanueleferonato.com/2007/09/08/javascript-sokoban-game-script/">Sokoban prototype using Javascript</a> and the game worked pretty well, being Javascript only.</p>
<p><strong><a href="http://www.tommysmind.com/gamejs/" target = "_blank">GameJS: A 2d game development framework in JavaScript by Tommy Maintz</a></strong></p>
<p>It&#8217;s a Javascript port of the <a href="http://www.xna.com/" target="_blank">Microsoft XNA Framework</a> using <a target ="_blank" href="https://developer.mozilla.org/en/Canvas_tutorial">Canvas</a> as the rendering device.</p>
<p>As the author says, &laquo; Obviously JavaScript and Canvas isnâ€™t the best combination to write browser games with. Flash will be the best platform for this for a long time. But this was all about fun, experimenting with new HTML features and learning game development. In Tetris a high FPS isnâ€™t really important, but with a filled game field, which already is 10 x 18 textures every frame, I still managed to get 25fps in FF and Chrome. This means that if you would use the framework to write games like Pacman and Super Mario, you would probably get 50+ fps on a decent computer, since they both probably have less then half the amount of textures at the same time on the screen. &raquo;</p>
<p>Read more information at the <a href="http://www.tommysmind.com/gamejs/" target = "_blank">official page</a>, where you can play Tetris.</p>
<p>I have to say, at the moment the game is giving me an error, but yesterday I managed to play from another computer.</p>
<p><img src="/images/javalibs01.jpg" alt="" /></p>
<p><strong><a href="http://gamequery.onaluf.org/" target = "_blank">gameQuery: a Javascript game engine with jQuery</a></strong></p>
<p>gameQuery is a <a href="http://jquery.com/" target = "_blank">jQuery</a> plug-in to help make javascript games easier to develop by adding some simple mechanism and commodity.</p>
<p>It&#8217;s still in a very early stage of development and may change a lot in the versions to come.</p>
<p>There is an interesting game (with a detailed tutorial) you can play: a <a target = "_blank" href="http://en.wikipedia.org/wiki/Money_Idol_Exchanger">Money Idol Exchange</a> clone called <strong>Mechalchemist</strong></p>
<p><img src="/images/javalibs02.jpg" alt="" /></p>
<p>I think it would be interesting to develop a Javascript game, maybe to be embedded as a Facebook application&#8230; yes&#8230; I am playing with FB&#8230; stay tuned&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2009/03/05/gamejs-and-gamequery-two-javascript-libraries-for-game-developers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Developing hex map concept</title>
		<link>http://www.emanueleferonato.com/2008/10/22/developing-hex-map-concept/</link>
		<comments>http://www.emanueleferonato.com/2008/10/22/developing-hex-map-concept/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 19:36:20 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Game design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Users contributions]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=591</guid>
		<description><![CDATA[Some months ago I released some tutorials about hexagonal tiles (and I developed an Halloween game based upon Hex maps creation and rollover and Finding adjacent cells in an hex map 1 and 2).
Later, Douglas Huskins told me 10 years ago he wrote a collection of functions that would help a person navigate hex maps. [...]]]></description>
			<content:encoded><![CDATA[<p>Some months ago I released some tutorials about <a href="http://www.emanueleferonato.com/2008/04/16/understanding-hexagonal-tiles/">hexagonal tiles</a> (and I developed an Halloween game based upon <a href="http://www.emanueleferonato.com/2008/04/20/hex-maps-creation-and-rollover/">Hex maps creation and rollover</a> and <a href="http://www.emanueleferonato.com/2008/04/23/finding-adjacent-cells-in-an-hex-map/">Finding adjacent cells in an hex map 1</a> and <a href="http://www.emanueleferonato.com/2008/04/27/finding-adjacent-cells-in-an-hex-map-part-2/">2</a>).</p>
<p>Later, <strong>Douglas Huskins</strong> told me <strong>10 years ago</strong> he wrote a collection of functions that would help a person navigate hex maps. The functions included:  Identifying the adjacent hexes, identifying the shortest path between two hexes, the relative position of a hex from the perspective of another hex and the distance between two hexes.</p>
<p>This can be really useful to make some strategy games.</p>
<p>Unfortunately most of the work seems to be lost, but Douglas still wants to share the concept with us, so he is rewriting it in Javascript.</p>
<p>Read what he says:</p>
<p>&laquo; I could not find my electronic copy of the source files.</p>
<p>All I have are some old Visual Basic printouts that lacked much documentation.  I have recoded it into Javascript and need to test it.</p>
<p>However, here are two of the functions: Move and Range.</p>
<p>The hex map layout this code works for is based on a hex map with the points laying horizontally.  The top and bottom of a hex are flat.</p>
<p>Hexes are numbered such that the first set of digits represent the column number and the second half of the hex number&#8217;s digits represent the row number.</p>
<p>A typical hex number would be 0132. That would be a hex in the leftmost column and would be the 32nd hex down from the top.</p>
<p>This type of map comes in two flavors. The way to identify the two types of layouts is to compare 0101 with 0201. If 0101 is above 0201, then it is referred to as &#8220;Odd Column Up&#8221;.</p>
<p>The code is able to support either flavor. There is a variable set at the top of the file (mapOddUp) which will let the code switch between the two layouts.</p>
<p>The unit (ship/car/etc) that sits in a hex will face one of the hex sides. The faces are numbered clockwise using either 0-5 or 1-6. Again, the code supports both numbering systems by treating 0 and 6 as the same direction (straight up). There is a variable at the top of the file (mapIsUp0) that determines which facing number system to use.</p>
<p>The code has the ability to change the map size. There are max and min values that can be set.</p>
<p>If you have any questions, please let me know. I will convert the remaining functions next week. After that, I will properly test everything and add a simple interface for it. In the meantime, this should help you create hex based games. &raquo;</p>
<p>Here it is the source code:<span id="more-591"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
HEX MAP LOGIC
This code was developed and written by Douglas Huskins.
&nbsp;
Permission is granted to anyone to use in any program, provided this comment block remains intact
as is AND credit is given to Douglas Huskins for the hex map logic.  Additionally, the person must 
send Douglas Huskins an email stating how and in what it will be used in.  The email address is a dot com
domain named &quot;huskins&quot;.  The username (before the at symbol) is &quot;doug&quot;.  If you cannot figure out how to
email Douglas Huskins, then a voice mail message at 925-957-0109 will work as well.
*/</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Valid move orders are L(eft), R(ight), F(orward), B(ack), W(ait)</span>
<span style="color: #006600; font-style: italic;">// If this needs to be added to, MoveStep() needs the new orders as well.</span>
<span style="color: #003366; font-weight: bold;">var</span> AcceptableOrders <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;LRFBW&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Configure the size and layout of the hex map.</span>
<span style="color: #003366; font-weight: bold;">var</span> mapOddUp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// If hex 0101 is above hex 0201, then set to true, else set to false.</span>
<span style="color: #003366; font-weight: bold;">var</span> mapIsUp0 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Is the &quot;up&quot; facing hex side zero or six? If zero, then true. If 6 then false.</span>
<span style="color: #003366; font-weight: bold;">var</span> mapMinCol <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> mapMaxCol <span style="color: #339933;">=</span> <span style="color: #CC0000;">99</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> mapMinRow <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> mapMaxRow <span style="color: #339933;">=</span> <span style="color: #CC0000;">99</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Create an array to store the Row, Column, Facing of each unit.</span>
<span style="color: #006600; font-style: italic;">// The first element is the unit number.  The second element is the hex information.</span>
<span style="color: #006600; font-style: italic;">// Unit zero is reserved for the functions.  The first game piece is stored in UnitArray[1][x].</span>
<span style="color: #003366; font-weight: bold;">var</span> UnitArray <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">21</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">// Max of 20 units (ships, cars, whatever the game is about)</span>
                                    <span style="color: #006600; font-style: italic;">// The second attribute is broken down as follows.</span>
                                    <span style="color: #006600; font-style: italic;">// 0: Hex Column</span>
                                    <span style="color: #006600; font-style: italic;">// 1: Hex Row</span>
                                    <span style="color: #006600; font-style: italic;">// 2: Hex Facing</span>
                                    <span style="color: #006600; font-style: italic;">// 3: Unit Type (not needed in this code)</span>
                                    <span style="color: #006600; font-style: italic;">// 4: Unit Status (not needed in this code)</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> DisplayHex<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #339933;">,</span>booWithFace<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Use this to print a string version of the hex number (with leading zeros, if needed.)</span>
    <span style="color: #006600; font-style: italic;">// If booWithFace is true, then include the facing after a colon.  Otherwise show only the hex number.</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexCol <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    HexCol <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0000000000&quot;</span> <span style="color: #339933;">+</span> HexCol<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexRow <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    HexRow <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;0000000000&quot;</span> <span style="color: #339933;">+</span> HexRow<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> LabelLength<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapMaxRow <span style="color: #339933;">&gt;</span> mapMaxCol<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        LabelLength <span style="color: #339933;">=</span> mapMaxRow <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        LabelLength <span style="color: #339933;">=</span> mapMaxCol <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexFace <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    HexFace <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;:&quot;</span> <span style="color: #339933;">+</span> HexFace<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>booWithFace <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        HexFace <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> HexCol.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">*</span> LabelLength.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> HexRow.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">*</span> LabelLength.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> HexFace<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> MoveUnit<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #339933;">,</span>MoveOrders<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This function is the main entry for moving a unit.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>MoveOrders.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// First off, were the MoveOrders properly written?</span>
        <span style="color: #006600; font-style: italic;">// The function CheckAllOrders() will determine if the orders, as a whole are acceptable.</span>
        <span style="color: #006600; font-style: italic;">// Perhaps the game does not allow two turns back to back.</span>
        <span style="color: #003366; font-weight: bold;">var</span> booValidOrders <span style="color: #339933;">=</span> CheckAllOrders<span style="color: #009900;">&#40;</span>MoveOrders<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> NextMove<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&lt;</span> MoveOrders.<span style="color: #660066;">length</span> <span style="color: #339933;">&amp;&amp;</span> booValidOrders<span style="color: #009900;">&#41;</span> 
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// Parse the next move from the orders and execute it.</span>
            NextMove <span style="color: #339933;">=</span> MoveOrders.<span style="color: #660066;">toUpper</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">charAt</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>NextMove.<span style="color: #660066;">IndexOf</span><span style="color: #009900;">&#40;</span>AcceptableOrders<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// Make the move and return the results in Unit[0][x]</span>
                MoveStep<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #339933;">,</span> NextMove<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #006600; font-style: italic;">// This function call CheckValidMove() will test if the specific orders were a valid move.</span>
            <span style="color: #006600; font-style: italic;">// The function is currently empty and will return a valid move reply.</span>
            <span style="color: #006600; font-style: italic;">// If the map needs to limit access between two hexes, then the function can be modified.</span>
&nbsp;
&nbsp;
            <span style="color: #006600; font-style: italic;">// If the move is valid and the unit did not leave the map then process it.            </span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>CheckValidMove<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> mapMinCol <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> mapMaxCol <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;=</span> mapMinRow <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> mapMaxRow<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span> 
            <span style="color: #009900;">&#123;</span>
                booValidOrders <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #006600; font-style: italic;">// Increment and repeat for next orders.</span>
            i<span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> FindRange<span style="color: #009900;">&#40;</span>Unit1<span style="color: #339933;">,</span> Unit2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This function returns the number of hexes between the two units.</span>
    <span style="color: #006600; font-style: italic;">// The return value is simply the number of hexes (not the number of orders it takes).</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Are the two hexes above or below each other?</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Are the two hexes on the same line (same Row)</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Okay, then find the deltas for row and column.</span>
    <span style="color: #003366; font-weight: bold;">var</span> DeltaCol <span style="color: #339933;">=</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> DeltaRow <span style="color: #339933;">=</span> Math.<span style="color: #660066;">abs</span><span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// So, are the two hexes adjacent?  Just need to look at the two unchecked hexes.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp <span style="color: #339933;">&amp;&amp;</span> IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp <span style="color: #339933;">&amp;&amp;</span> IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">==</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// At this point, we know the two units are at least two hexes away from each other.</span>
    <span style="color: #006600; font-style: italic;">// To simplify, we will assign LeftHex and RightHex to the values of the Unit Numbers.</span>
    <span style="color: #006600; font-style: italic;">// This way, all math is done from the leftmost hex.</span>
    <span style="color: #003366; font-weight: bold;">var</span> LeftHex<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> RightHex<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>Unit1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;</span> UnitArray<span style="color: #009900;">&#91;</span>Unit2<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        LeftHex <span style="color: #339933;">=</span> Unit1<span style="color: #339933;">;</span>
        RightHex <span style="color: #339933;">=</span> Unit2<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        LeftHex <span style="color: #339933;">=</span> Unit2<span style="color: #339933;">;</span>
        RightHex <span style="color: #339933;">=</span> Unit1<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// The next step is to figure out if it is easier to go across then vertical or the other way around.</span>
    <span style="color: #006600; font-style: italic;">// To be more clear:  We will calculate the distance along the spine of the hexes.</span>
    <span style="color: #006600; font-style: italic;">// The question is when we get to the point we leave the spine, do we go vertically or horizontally.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&gt;</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// RightHex is above and to the right of LeftHex.</span>
        <span style="color: #006600; font-style: italic;">// For every two hexes travelled, it will add 2 to the column value and subtract 1 from the row.</span>
        <span style="color: #006600; font-style: italic;">// Next question is: Is the RightHex above the heading 1 spine?</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">&lt;</span> DeltaRow<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// RightHex is above the heading 1 spine.  The distance is calculated by figuring out the</span>
            <span style="color: #006600; font-style: italic;">// row value after moving along heading 1 until the columns match.</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #006600; font-style: italic;">// In this case we will safely undershoot.</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #006600; font-style: italic;">// In this case, we may overshoot by one hex if we don't adjust for it.</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">// Same as above, however with mapOddUp set to false.</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// RightHex is on or below the heading 1 spine but above the midline.  Distance is calculated by</span>
            <span style="color: #006600; font-style: italic;">// figuring out the column value after moving along heading 1 until the rows match.</span>
            <span style="color: #000066; font-weight: bold;">return</span> DeltaRow <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> DeltaRow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// RightHex is below and to the right of LeftHex.</span>
        <span style="color: #006600; font-style: italic;">// For every two hexes travelled, it will add 2 to the column value and add 1 to the row.</span>
        <span style="color: #006600; font-style: italic;">// Next question is: Is the RightHex above the heading 2 spine?</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">&lt;</span> DeltaRow<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// The RightHex is above the heading 2 spine, but below the midline.</span>
            <span style="color: #000066; font-weight: bold;">return</span> DeltaRow <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> DeltaRow<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">// The RightHex is below the heading 2 spine and to the right of LeftHex.</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapOddUp<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>UnitArray<span style="color: #009900;">&#91;</span>LeftHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">return</span> DeltaCol <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>DeltaCol <span style="color: #339933;">/</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> UnitArray<span style="color: #009900;">&#91;</span>RightHex<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This section is for the custom validation code.</span>
<span style="color: #006600; font-style: italic;">// Modify this code as needed to address unique issues with the game orders or board.</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> CheckAllOrders<span style="color: #009900;">&#40;</span>MoveOrders<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Here is where you can validate the overall orders before they are processed.</span>
    <span style="color: #006600; font-style: italic;">// If you have some reason to not like the way the orders are written, write the code here.</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Set the value to false if you want to invalidate the entire collection of orders.</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> CheckValidMove<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Here is where you can control how the internal portion of the map is designed.</span>
    <span style="color: #006600; font-style: italic;">// If you want to limit access between two hexes, then you can check for them here.</span>
    <span style="color: #006600; font-style: italic;">// UnitArray[UnitNumber] is the starting hex.  UnitArray[0] is the ending hex.</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Set the value to false if you want to invalidate the move, otherwise return with a true.</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Below this point are the support functions to manage the above functions.</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This function returns a true if the Hex's current row is even.</span>
    <span style="color: #006600; font-style: italic;">// It is used by MoveStep() to determine the next hex.</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>HexCol <span style="color: #339933;">%</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> MoveStep<span style="color: #009900;">&#40;</span>UnitNumber<span style="color: #339933;">,</span> NextOrder<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexCol <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexRow <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> HexFace <span style="color: #339933;">=</span> UnitArray<span style="color: #009900;">&#91;</span>UnitNumber<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>NextOrder<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;L&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapIsUp0<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>HexFace <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace<span style="color: #339933;">--;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>HexFace <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace <span style="color: #339933;">=</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace<span style="color: #339933;">--;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;R&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>mapIsUp0<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>HexFace <span style="color: #339933;">==</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace<span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>HexFace <span style="color: #339933;">==</span> <span style="color: #CC0000;">6</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066; font-weight: bold;">else</span>
                <span style="color: #009900;">&#123;</span>
                    HexFace<span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;F&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>HexFace<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;B&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>HexFace<span style="color: #009900;">&#41;</span> 
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">--;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">:</span>
                    HexCol<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>IsColEven<span style="color: #009900;">&#40;</span>HexCol<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> mapOddUp <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
                    <span style="color: #009900;">&#123;</span>
                        HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #009900;">&#125;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">:</span>
                    HexRow<span style="color: #339933;">++;</span>
                    <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;W&quot;</span><span style="color: #339933;">:</span>
            <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Now return the results in the &quot;zero&quot; element of the Unit Array</span>
    UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> HexCol<span style="color: #339933;">;</span>
    UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> HexRow<span style="color: #339933;">;</span>
    UnitArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> HexFace<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This should help you all in the creation of a strategy game&#8230; at least it&#8217;s helping me&#8230;</p>
<p>Someone out there willing to translate it into AS3?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2008/10/22/developing-hex-map-concept/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Complete Javascript popup opener</title>
		<link>http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/</link>
		<comments>http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 15:38:31 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/</guid>
		<description><![CDATA[Opening popups in JS is simple, but sometimes in the same page we need to open popups with different features. There are several scripts in the net doing this task but, as usual, none of them seemed to fit my needs
I decided to code a complete javascript popup opener in order to have one function [...]]]></description>
			<content:encoded><![CDATA[<p>Opening popups in JS is simple, but sometimes in the same page we need to open popups with different features. There are several scripts in the net doing this task but, as usual, none of them seemed to fit my needs</p>
<p>I decided to code a complete javascript popup opener in order to have one function that I can use in any situation.</p>
<p>These are the customizable parameters of your popup:</p>
<p><strong>url</strong>: the string representing the url of the page you want to open in the popup. Default value: this page.</p>
<p><strong>width</strong>: popup width, in pixels. If you enter a value between 0 and 1, it will be parsed as a % of screen width. For example, if you enter 0.5, it will be parsed as 50% of screen width. Default value: half of the screen width.</p>
<p><strong>height</strong>: popup height, in pixels. If you enter a value between 0 and 1, it will be parsed as a % of screen height. For example, if you enter 0.5, it will be parsed as 50% of screen height. Default value: half of the screen height.</p>
<p><strong>xpos</strong>: x position of the upper left corner of the popup. It can be an integer or &#8220;left&#8221; or &#8220;right&#8221;. If you enter &#8220;left&#8221; your popup will appear in the leftmost part of the screen, if you enter &#8220;right&#8221; your popup will appear in the rightmost part of the screen. Default value: the one that will center the popup horizontally<span id="more-131"></span></p>
<p><strong>ypos</strong>: y position of the upper left corner of the popup. It can be an integer or &#8220;top&#8221; or &#8220;bottom&#8221;. If you enter &#8220;top&#8221; your popup will appear in the topmost part of the screen, if you enter &#8220;bottm&#8221; your popup will appear in the bottommost part of the screen. Default value: the one that will center the popup vertically</p>
<p><strong>xoffset</strong>: an integer representing amount of pixels, positive or negative, that will place the popup respectively to the left or to the right from its horizontal position. Default value: 0</p>
<p><strong>yoffset</strong>: an integer representing the amount of pixels, positive or negative, that will place the popup respectively up or to the down from its vertical position. Default value: 0</p>
<p><strong>name</strong>: window name, passed as a string. Default value: &#8220;propup&#8221;</p>
<p><strong>scrollbars</strong>: can be &#8220;yes&#8221; or &#8220;no&#8221;, defining if the popup window will have scrollbars. Default value: no</p>
<p><strong>resizable</strong>: can be &#8220;yes&#8221; or &#8220;no&#8221;, defining if the popup window can be resized. Default value: no</p>
<p><strong>status</strong>: can be &#8220;yes&#8221; or &#8220;no&#8221;, defining if the popup window will show the status bar. Default value: no</p>
<p><strong>locat</strong>: can be &#8220;yes&#8221; or &#8220;no&#8221;, defining if the popup window will have the location bar. Default value: no</p>
<p><strong>toolbar</strong>: can be &#8220;yes&#8221; or &#8220;no&#8221;, defining if the popup window will have the toolbar. Default value: no</p>
<p>Let&#8217;s examine the script:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> propup <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	o.<span style="color: #660066;">url</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">url</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/'</span><span style="color: #339933;">:</span> o.<span style="color: #660066;">url</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">width</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> screen.<span style="color: #660066;">width</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">width</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">height</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> screen.<span style="color: #660066;">height</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">height</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">*=</span>screen.<span style="color: #660066;">width</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">&lt;=</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">&gt;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">*=</span>screen.<span style="color: #660066;">height</span><span style="color: #009900;">&#125;</span>
	o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>screen.<span style="color: #660066;">width</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">xpos</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>screen.<span style="color: #660066;">height</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">ypos</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">xoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">xoffset</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">xoffset</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">yoffset</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">yoffset</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">yoffset</span><span style="color: #339933;">;</span>
	o.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #000066;">name</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'propup'</span> <span style="color: #339933;">:</span> o.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">scrollbars</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">scrollbars</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'no'</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">scrollbars</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">resizable</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">resizable</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'no'</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">resizable</span><span style="color: #339933;">;</span>
	o.<span style="color: #000066;">status</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'no'</span> <span style="color: #339933;">:</span> o.<span style="color: #000066;">status</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">locat</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">locat</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'no'</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">locat</span><span style="color: #339933;">;</span>
	o.<span style="color: #660066;">toolbar</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">toolbar</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'no'</span> <span style="color: #339933;">:</span> o.<span style="color: #660066;">toolbar</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">xpos</span><span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;right&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">=</span> screen.<span style="color: #660066;">width</span><span style="color: #339933;">-</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">ypos</span><span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;bottom&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">=</span> screen.<span style="color: #660066;">height</span><span style="color: #339933;">-</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	o.<span style="color: #660066;">xpos</span> <span style="color: #339933;">+=</span> o.<span style="color: #660066;">xoffset</span>
	o.<span style="color: #660066;">ypos</span> <span style="color: #339933;">+=</span> o.<span style="color: #660066;">yoffset</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> scrollbarstext <span style="color: #339933;">=</span> <span style="color: #3366CC;">'scrollbars = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">scrollbars</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> resizabletext <span style="color: #339933;">=</span> <span style="color: #3366CC;">'resizable = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">resizable</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> statustext <span style="color: #339933;">=</span> <span style="color: #3366CC;">'status = '</span><span style="color: #339933;">+</span>o.<span style="color: #000066;">status</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> locationtext <span style="color: #339933;">=</span> <span style="color: #3366CC;">'location = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">locat</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> toolbartext <span style="color: #339933;">=</span> <span style="color: #3366CC;">'toolbar = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">toolbar</span><span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	features <span style="color: #339933;">=</span> scrollbarstext<span style="color: #339933;">+</span>resizabletext<span style="color: #339933;">+</span>statustext<span style="color: #339933;">;</span>
	features <span style="color: #339933;">=</span> features <span style="color: #339933;">+</span> locationtext<span style="color: #339933;">+</span>toolbartext<span style="color: #339933;">;</span>
	features <span style="color: #339933;">=</span> features <span style="color: #339933;">+</span> <span style="color: #3366CC;">'width = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">width</span><span style="color: #339933;">+</span><span style="color: #3366CC;">',height = '</span><span style="color: #339933;">+</span>o.<span style="color: #660066;">height</span><span style="color: #339933;">;</span>
	features <span style="color: #339933;">=</span> features <span style="color: #339933;">+</span> <span style="color: #3366CC;">',top = '</span> <span style="color: #339933;">+</span> o.<span style="color: #660066;">ypos</span><span style="color: #339933;">;</span>
	features <span style="color: #339933;">=</span> features <span style="color: #339933;">+</span> <span style="color: #3366CC;">',left = '</span> <span style="color: #339933;">+</span> o.<span style="color: #660066;">xpos</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> win <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	win <span style="color: #339933;">=</span> window.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">url</span><span style="color: #339933;">,</span> o.<span style="color: #000066;">name</span><span style="color: #339933;">,</span> features<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Line 1</strong>: Function declaration, with only one parameter. That&#8217;s possible because I am passing  a Javascript object structure into a function as an argument. It&#8217;s a very good technique mostly because it allows flexibility in the order you will pass the arguments, and provides flexibility on optional arguments too. You will understand this technique later, when I will explain how to call the function.</p>
<p><strong>Line 2</strong>: I am using a ternary operator to set a default value of &#8220;url&#8221; if the user did not specify it when called the function. Basically this line can be translated into:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> o.<span style="color: #660066;">url</span> <span style="color: #339933;">==</span>  <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	o.<span style="color: #660066;">url</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	o.<span style="color: #660066;">url</span> <span style="color: #339933;">=</span> o.<span style="color: #660066;">url</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Where the &#8220;else&#8221; statement is pretty useless. We can say that <strong>line 2</strong> assigns a default value to &#8220;url&#8221; if not provided by the user</p>
<p><strong>Line 3</strong>: Assigns a default value to &#8220;width&#8221; if not provided by the user. In this case the default width is half of the screen width.</p>
<p><strong>Line 4</strong>: Same thing with the height</p>
<p><strong>Line 5</strong>: If width is a number between 0 and 1, then I assign to width the (width*100)% of the screen width.</p>
<p><strong>Line 6</strong>: Same thing with the height</p>
<p><strong>Line 7</strong>: Assigns a default value to &#8220;xpos&#8221; if not provided by the user</p>
<p><strong>Line 8</strong>: Same thing with &#8220;ypos&#8221;</p>
<p><strong>Line 9</strong>: Same thing with &#8220;xoffset&#8221;</p>
<p><strong>Line 10</strong>: Same thing with &#8220;yoffset&#8221;</p>
<p><strong>Line 11</strong>: Same thing with &#8220;name&#8221;</p>
<p><strong>Line 12</strong>: Same thing with &#8220;scrollbars&#8221;</p>
<p><strong>Line 13</strong>: Same thing with &#8220;resizable&#8221;</p>
<p><strong>Line 14</strong>: Same thing with &#8220;status&#8221;</p>
<p><strong>Line 15</strong>: Same thing with &#8220;locat&#8221;</p>
<p><strong>Line 16</strong>: Same thing with &#8220;toolbar&#8221;</p>
<p><strong>Line 18</strong>: Assigning 0 to xpos if xpos was &#8220;left&#8221;. In this way the popup is at the leftmost of the screen</p>
<p><strong>Line 19</strong>: Same concept with the right</p>
<p><strong>Lines 21-22</strong>: Same concept with &#8220;ypos&#8221;</p>
<p><strong>Lines 24-25</strong>: Adding the x and y offset to x and y positions</p>
<p><strong>Lines 27-31</strong>: Declaring strings according to passed arguments</p>
<p><strong>Lines 33-37</strong>: Constructing the string with popup attributes</p>
<p><strong>Lines 39-40</strong>: Calling the javascript classic window.open with all arguments. You can find more information about HTML DOM open() Method at <a target = "_blank" href="http://www.w3schools.com/htmldom/met_win_open.asp">this page</a>.</p>
<p>Now let&#8217;s see how to use this function. As I said, you can pass arguments in the order you prefer and if you even decide if passing arguments or letting the function use its default values.</p>
<p>This is the source code of a typical page using propup</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&nbsp;
&lt;head&gt;
&lt;script language = &quot;javascript&quot;&gt;
&nbsp;
var propup = function(o) {
	o.url = (typeof o.url == 'undefined') ? 'http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/' : o.url;
	o.width = (typeof o.width == 'undefined') ? screen.width/2 : o.width;
	o.height = (typeof o.height == 'undefined') ? screen.height/2 : o.height;
	if((o.width&lt;=1)&amp;&amp;(o.width&gt;0)){o.width*=screen.width}
	if((o.height&lt;=1)&amp;&amp;(o.height&gt;0)){o.height*=screen.height}
	o.xpos = (typeof o.xpos == 'undefined') ? (screen.width/2)-(o.width/2) : o.xpos;
	o.ypos = (typeof o.ypos == 'undefined') ? (screen.height/2)-(o.height/2) : o.ypos;
	o.xoffset = (typeof o.xoffset == 'undefined') ? 0 : o.xoffset;
	o.yoffset = (typeof o.yoffset == 'undefined') ? 0 : o.yoffset;
	o.name = (typeof o.name == 'undefined') ? 'propup' : o.name;
	o.scrollbars = (typeof o.scrollbars == 'undefined') ? 'no' : o.scrollbars;
	o.resizable = (typeof o.resizable == 'undefined') ? 'no' : o.resizable;
	o.status = (typeof o.status == 'undefined') ? 'no' : o.status;
	o.locat = (typeof o.locat == 'undefined') ? 'no' : o.locat;
	o.toolbar = (typeof o.toolbar == 'undefined') ? 'no' : o.toolbar;
&nbsp;
	if(o.xpos == &quot;left&quot;){o.xpos=0;}
	if(o.xpos == &quot;right&quot;){o.xpos = screen.width-o.width;}
&nbsp;
	if(o.ypos == &quot;top&quot;){o.ypos=0;}
	if(o.ypos == &quot;bottom&quot;){o.ypos = screen.height-o.height;}
&nbsp;
	o.xpos += o.xoffset
	o.ypos += o.yoffset
&nbsp;
	var scrollbarstext = 'scrollbars = '+o.scrollbars+&quot;,&quot;;
	var resizabletext = 'resizable = '+o.resizable+&quot;,&quot;;
	var statustext = 'status = '+o.status+&quot;,&quot;;
	var locationtext = 'location = '+o.locat+&quot;,&quot;;
	var toolbartext = 'toolbar = '+o.toolbar+&quot;,&quot;;
&nbsp;
	features = scrollbarstext+resizabletext+statustext;
	features = features + locationtext+toolbartext;
	features = features + 'width = '+o.width+',height = '+o.height;
	features = features + ',top = ' + o.ypos;
	features = features + ',left = ' + o.xpos;
&nbsp;
	var win = null;
	win = window.open(o.url, o.name, features);
}
&nbsp;
&lt;/script&gt;
	&lt;/head&gt;
		&lt;body&gt;
		&lt;ol&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({});&quot;&gt;Default popup&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({url:'http://www.google.com/',name:'pop1'});&quot;&gt;Opening Google&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({width:700,height:200,name:'pop2'});&quot;&gt;700x200 popup&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({width:0.3,height:200,name:'_blank'});&quot;&gt;30%x200 popup&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({xpos:'right',ypos:'bottom',name:'_blank'});&quot;&gt;Popup in the right bottom end of the screen&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({xpos:'right',xoffset:-100,name:'_blank'});&quot;&gt;Popup 100 pixels far from the right end of the screen&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({scrollbars:'yes',name:'_blank'});&quot;&gt;Popup with scrollbars&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({resizable:'yes',name:'_blank'});&quot;&gt;Resizable popup&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({status:'yes',name:'_blank'});&quot;&gt;Popup with status bar&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({locat:'yes',name:'_blank'});&quot;&gt;Popup location bar&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href = &quot;javascript:propup({toolbar:'yes',name:'_blank'});&quot;&gt;Popup with toolbar&lt;/a&gt;&lt;/li&gt;
&nbsp;
		&lt;/ol&gt;
	&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p>And this is the result:</p>
<p><iframe src="/downloads/propup.html" frameborder="0" scrolling="no" height="300" width="500"></iframe></p>
<p>As you can see, there is not limit about the number of arguments you can pass or the order you are passing arguments in.</p>
<p>Simply copy the code, use it and enjoy! Should you use this function in your site, please let me know! I would be so proud (almost&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2007/09/21/complete-javascript-popup-opener/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Javascript Sokoban game script</title>
		<link>http://www.emanueleferonato.com/2007/09/08/javascript-sokoban-game-script/</link>
		<comments>http://www.emanueleferonato.com/2007/09/08/javascript-sokoban-game-script/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 16:59:15 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/2007/09/08/javascript-sokoban-game-script/</guid>
		<description><![CDATA[I&#8217;ve always been addicted to logic games and Sokoban is one of them.
From Wikipedia: Sokoban (warehouse keeper) is a transport puzzle in which the player pushes boxes around a maze, viewed from above, and tries to put them in designated locations. Only one box may be pushed at a time, not two, and boxes cannot [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always been addicted to logic games and Sokoban is one of them.</p>
<p>From <a target = "_blank" href="http://en.wikipedia.org/wiki/Sokoban">Wikipedia</a>: Sokoban (warehouse keeper) is a transport puzzle in which the player pushes boxes around a maze, viewed from above, and tries to put them in designated locations. Only one box may be pushed at a time, not two, and boxes cannot be pulled. As the puzzle would be extremely difficult to create physically, it is usually implemented as a video game.</p>
<p>In some cases Javascript is not the ideal language to code puzzle games, because the player can read the code and have a clue about the puzzle. Just imagine a Minesweeper game in Javascript&#8230; a brief look at the code and you&#8217;ll know where the bombs are.</p>
<p>In Sokoban, reading the code is useless because you don&#8217;t play in a static level, but level changes as you move your player pushing blocks.</p>
<p>At this time the script is very essential, and contains just one level, but I am going to push (yes, talking about sokoban, I obviously &#8220;push&#8221;) the script very far away, including level editors, leagues and even more.</p>
<p>Every single line of the script will be explained, as usual, meanwhile you can watch the code from your browser.</p>
<p><iframe frameborder = "0" src="/downloads/sk.html" height="350" width="500" scrolling = "no"></iframe></p>
<p>Can you solve the level? Can you tell me where did I rip the main sprite?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2007/09/08/javascript-sokoban-game-script/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Click image and get coordinates with Javascript</title>
		<link>http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/</link>
		<comments>http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/#comments</comments>
		<pubDate>Sat, 02 Sep 2006 16:53:46 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/</guid>
		<description><![CDATA[I had to display several photos where the user can click over an interesting point and have its coordinates passed through a form.
Of course, it was a bit more complicated, but this is the code i want to share with you.
Let&#8217;s assume we have a photo like this:


Try to click on a photo now&#8230;
You pointed [...]]]></description>
			<content:encoded><![CDATA[<p>I had to display several photos where the user can click over an interesting point and have its coordinates passed through a form.<br />
Of course, it was a bit more complicated, but this is the code i want to share with you.</p>
<p>Let&#8217;s assume we have a photo like this:</p>
<form name="pointform" method="post"><script type="text/javascript" src="/scripts/point.js"></script></p>
<div id="pointer_div" onclick="point_it(event)" style = "background-image:url('/images/sun.jpg');width:500px;height:333px;"><img src="/images/point.gif" id="cross" style="position:relative;visibility:hidden;z-index:2;"></div>
<p>Try to click on a photo now&#8230;</p>
<p>You pointed on x =<br />
<input type="text" name="form_x" size="4" /> &#8211; y =<br />
<input type="text" name="form_y" size="4" /></form>
<p>If you continue to click on the photo, you will see pointer changing its position, same thing with <em>x</em> and <em>y</em> coordinates</p>
<p>How can it be done?</p>
<p>You can try this script, obviously changing path and styles according to your needs</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;script language=&quot;JavaScript&quot;&gt;
function point_it(event){
	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById(&quot;pointer_div&quot;).offsetLeft;
	pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById(&quot;pointer_div&quot;).offsetTop;
	document.getElementById(&quot;cross&quot;).style.left = (pos_x-1) ;
	document.getElementById(&quot;cross&quot;).style.top = (pos_y-15) ;
	document.getElementById(&quot;cross&quot;).style.visibility = &quot;visible&quot; ;
	document.pointform.form_x.value = pos_x;
	document.pointform.form_y.value = pos_y;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form name=&quot;pointform&quot; method=&quot;post&quot;&gt;
&lt;div id=&quot;pointer_div&quot; onclick=&quot;point_it(event)&quot; style = &quot;background-image:url('sun.jpg');width:500px;height:333px;&quot;&gt;
&lt;img src=&quot;point.gif&quot; id=&quot;cross&quot; style=&quot;position:relative;visibility:hidden;z-index:2;&quot;&gt;&lt;/div&gt;
You pointed on x = &lt;input type=&quot;text&quot; name=&quot;form_x&quot; size=&quot;4&quot; /&gt; - y = &lt;input type=&quot;text&quot; name=&quot;form_y&quot; size=&quot;4&quot; /&gt;
&lt;/form&gt; 
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Tested both on Firefox and Explorer, it seems to work well.</p>
<p>Enjoy and give me feedback.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2006/09/02/click-image-and-get-coordinates-with-javascript/feed/</wfw:commentRss>
		<slash:comments>66</slash:comments>
		</item>
	</channel>
</rss>
