<?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>Wildreason Productions</title>
	<atom:link href="http://wildreason.com/wildreason-blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://wildreason.com/wildreason-blog</link>
	<description>User friendly website design.</description>
	<lastBuildDate>Sun, 10 Apr 2011 04:34:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>WordPress network (WPMU) &#8211; wp_list_pages</title>
		<link>http://wildreason.com/wildreason-blog/2011/wordpress-network-wpmu-wp_list_pages/</link>
		<comments>http://wildreason.com/wildreason-blog/2011/wordpress-network-wpmu-wp_list_pages/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 04:34:58 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[php/mysql]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=307</guid>
		<description><![CDATA[List pages from the home blog on all network sites. I have recently setup a WordPress Network install where a feature on the website automatically creates posts for newly registered users. Users aren&#8217;t able to create posts or mange their account but they can view posts that have been created. As a part of this [...]]]></description>
			<content:encoded><![CDATA[<p>List pages from the home blog on all network sites. </p>
<p>I have recently setup a WordPress Network install where a feature on the website automatically creates posts for newly registered users. Users aren&#8217;t able to create posts or mange their account but they can view posts that have been created. </p>
<p>As a part of this I also needed to have the navigation pages from the home blog to appear on all network sites since users can&#8217;t create their own pages. </p>
<p>Uses:</p>
<p><a href="http://codex.wordpress.org/WPMU_Functions/switch_to_blog" title="Wordpress Network (WPMU) function reference: switch_to_blog()">switch_to_blog()</a><br />
<a href="http://codex.wordpress.org/WPMU_Functions/restore_current_blog" title="Wordpress Network (WPMU) function reference: restore_current_blog()">restore_current_blog()</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//theme's header.php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//temporarily switch to the home blog (1)</span>
switch_to_blog<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'show_home'</span> 	<span style="color: #339933;">=&gt;</span> 	<span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'title_li'</span>		<span style="color: #339933;">=&gt;</span>	<span style="color: #0000ff;">''</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_list_pages_root<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//continue executing the page as whatever blog was being accessed</span>
restore_current_blog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2011/wordpress-network-wpmu-wp_list_pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Free customized website setup and installed</title>
		<link>http://wildreason.com/wildreason-blog/2011/free-customized-website-setup-and-installed/</link>
		<comments>http://wildreason.com/wildreason-blog/2011/free-customized-website-setup-and-installed/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 05:03:50 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[free website]]></category>
		<category><![CDATA[web design services]]></category>
		<category><![CDATA[website designers]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=283</guid>
		<description><![CDATA[As a limited time offer &#8211; thanks to a deal with Host Gator &#8211; Wildreason Productions is able to provide a basic 2-3 page webpage with a blog and custom logo for free. All you have to do is host your website at Host Gator as a new customer. Click here to signup or get [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Click here to signup or get more information!" href="/promotion.php"><img class="aligncenter" title="Wildreason Productions Free Website Promotion" src="http://wildreason.com/images/promo_email.jpg" alt="Wildreason Productions Free Website Promotion" width="450" height="75" /></a></p>
<p>As a limited time offer &#8211; thanks to a deal with <a title="Host your website with Host Gator starting @ $3.96/mo" href="promo_signup.php">Host Gator</a> &#8211; Wildreason Productions is able to provide a basic 2-3 page webpage with a blog and custom logo for free. All you have to do is host your website at Host Gator as a new customer. Click <a title="Click here to signup or get more information!" href="/promotion.php">here</a> to signup or get more information about a <a title="Click here to signup or get more information!" href="/promotion.php">free website</a>!</p>
<h2 style="margin-left: 20px;">Website Samples</h2>
<p></p>
<div style="text-align: center;"><a href="/promotion.php" title="Get more information about your free website!"><img src="/work/thumbnail/phpThumb.php?src=/images/promo_samples/sample1.jpg&amp;w=125&amp;fltr[]=ric|10|10" alt="Website sample" />&nbsp;&nbsp;&nbsp;&nbsp;<img src="/work/thumbnail/phpThumb.php?src=/images/promo_samples/sample2.jpg&amp;w=125&amp;fltr[]=ric|10|10" alt="Website sample" />&nbsp;&nbsp;&nbsp;&nbsp;<img src="/work/thumbnail/phpThumb.php?src=/images/promo_samples/sample4.jpg&amp;w=125&amp;fltr[]=ric|10|10" alt="Website sample" />&nbsp;&nbsp;&nbsp;&nbsp;<img src="/work/thumbnail/phpThumb.php?src=/images/promo_samples/sample5.jpg&amp;w=125&amp;fltr[]=ric|10|10" alt="Website sample" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2011/free-customized-website-setup-and-installed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Capturing output in PHP and assigning it to a variable</title>
		<link>http://wildreason.com/wildreason-blog/2010/capturing-output-in-php-and-assigning-it-to-a-variable/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/capturing-output-in-php-and-assigning-it-to-a-variable/#comments</comments>
		<pubDate>Fri, 24 Dec 2010 06:49:16 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[php/mysql]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[output buffering]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=271</guid>
		<description><![CDATA[I recently started a project in WordPress that is designed to print out a lot of data into tabs, with clear separation between datasets. What this meant was a lot of PHP mixed with a lot of HTML. I think I have spoiled myself by using PEAR&#8217;s HTML_Template_IT module because I don&#8217;t design websites or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wildreason.com/wildreason-blog/wp-content/uploads/2010/12/php-300x240.jpg"><img src="http://wildreason.com/wildreason-blog/wp-content/uploads/2010/12/php-300x240.jpg" alt="" title="Funny PHP image" width="300" height="240" class="alignleft size-medium wp-image-279" /></a>I recently started a project in WordPress that is designed to print out a lot of data into tabs, with clear separation between datasets. What this meant was a lot of PHP mixed with a lot of HTML. I think I have spoiled myself by using PEAR&#8217;s HTML_Template_IT module because I don&#8217;t design websites or applications where HTML is ever mixed with PHP. This is a topic in itself but essentially doing this allows me to write cleaner code more efficiently &#8211; ultimately saving the client money and saving myself a lot of staring trying to figure out what&#8217;s what. </p>
<p>This was my first attempt to use a template engine inside of WordPress and so far the only challenge I have encountered is the group of functions that print HTML similar to an includes statement. Included in my project are get_header() and get_footer() &#8211; native WordPress functions. Wherever in the file that these calls exist is where the output will appear. I could have done something similar to the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTML_Template_IT<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadTemplateFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tpl_project.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVariable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>But that felt cheap &#8211; as if it were a hacked version of a PHP template engine. I started looking into PHP&#8217;s ob_start() family and came up with the following solution:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$template</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTML_Template_IT<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadTemplateFile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tpl_project.html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVariable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*	This function will turn output buffering on. While 
	output buffering is active no output is sent from 
	the script (other than headers), instead the output 
	is stored in an internal buffer.
*/</span>
<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*	Gets the contents of the output buffer without clearing it. */</span>
<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">ob_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$footer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*	This function discards the contents of the topmost output
	buffer and turns off this output buffering.
*/</span>
<span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVariable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVariable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'footer'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$footer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$template</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Using PHP&#8217;s built in output buffering control I am able to capture any output and store it&#8217;s contents in a variable without it ever actually becoming output. </p>
<p>Another, more sophisticated, and probably more proper solution would be to extend WordPress&#8217;s native do_action() function to allow you to pass it a switch that instructs it to return the contents of the function as opposed to printing it out. So then you could do something like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A good idea for a WordPress plugin! <img src='http://wildreason.com/wildreason-blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Suggestions/comments always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/capturing-output-in-php-and-assigning-it-to-a-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Google TV application</title>
		<link>http://wildreason.com/wildreason-blog/2010/creating-a-google-tv-application/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/creating-a-google-tv-application/#comments</comments>
		<pubDate>Sat, 11 Dec 2010 00:21:11 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[google tv]]></category>
		<category><![CDATA[projects]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=258</guid>
		<description><![CDATA[This website is best viewed on the latest version of Google Chrome (The browser featured on Google TV devices). I had the pleasure of creating a Google TV enabled web application for a client &#8211; Q3030.com. It features keyboard navigation, automatic window resizing based on client browser-height, AJAX navigation, auto scrolling, and much more. There [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://gtv.q3030.com" title="Preview Google TV on Q3030"><img class="alignnone" title="Q3030 on Google TV Preview" src="http://i.imgur.com/oC7J5.jpg" alt="" width="586" height="292" /></a><br />
This website is best viewed on the latest version of Google Chrome (The browser featured on Google TV devices). </p>
<p>I had the pleasure of creating a Google TV enabled web application for a client &#8211; Q3030.com. It features keyboard navigation, automatic window resizing based on client browser-height, AJAX navigation, auto scrolling, and much more. </p>
<p>There are a lot of techniques that can be utilized for creating optimized displays on 720p and 1080p televisions. In the end I decided to use CSS zoom to do the resizing for the Google TV device and disable automatic zooming on the device. The biggest challenge presented was the keyboard navigation. In this particular application there are three rows you can navigate: player controls, videos, and channels. Using Javascript, I keep track of the current item the user is on in a variable. One variable stores what &#8220;tier&#8221; they are on, -1, 0, 1. Then there is a variable for each tier that indicates what position in that tier they are on. The player controls had six controls so the possible positions for that tier are 0-5. Same concept for the video and channels row.</p>
<p>When an arrow key is pressed, depending on the direction, adds or subtracts from the current position or current tier while simultaneously removing a class (CSS) from the item being navigated away from and adding a class to the item being navigated to. This class adds a glow around the element to indicate to the user where they are.</p>
<p>I then added listeners for the enter and spacebar keys. Spacebar pauses/plays the video and enter triggers a click event for whatever element they are currently on. For instance:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//down</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tier <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		tier <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.previewSelect[rel='</span><span style="color: #339933;">+</span>tier1Pos<span style="color: #339933;">+</span><span style="color: #3366CC;">']'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.show[rel='</span><span style="color: #339933;">+</span>tier2Pos<span style="color: #339933;">+</span><span style="color: #3366CC;">']'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'chanSelect'</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tier <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		imgEl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#vidControls img[rel='</span><span style="color: #339933;">+</span>tier0Pos<span style="color: #339933;">+</span><span style="color: #3366CC;">']'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		oldSrc <span style="color: #339933;">=</span> imgEl.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		newSrc <span style="color: #339933;">=</span> oldSrc<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;">'.png'</span><span style="color: #339933;">;</span>
		imgEl.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;src&quot;</span><span style="color: #339933;">,</span> newSrc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		nextEl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.previewSelect[rel='</span><span style="color: #339933;">+</span>tier1Pos<span style="color: #339933;">+</span><span style="color: #3366CC;">']'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		nextEl.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		nextEl.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseenter'</span><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><span style="color: #000066; font-weight: bold;">typeof</span> t <span style="color: #339933;">!=</span> <span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> clearTimeout<span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
		t <span style="color: #339933;">=</span> setTimeout<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>
			nextEl.<span style="color: #660066;">trigger</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseleave'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		tier <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;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is the code to monitor the down arrow key.</p>
<p>Overall, this was a fun project that taught me a lot about Javascript and user experience in the living room. Just when I think I&#8217;ve mastered a language or skill set I am presented with a challenge that shows me how much I don&#8217;t know. A gallery of TV-ready websites can be found here:</p>
<p><a href="http://www.google.com/tv/spotlight-gallery.html">Google TV Spotlight Gallery</a></pre>
<p>More of my projects can be found in my <a href="/wildreason-productions-portfolio.php" title="The portfolio of Wildreason Productions">portfolio section</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/creating-a-google-tv-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I heart CSS &#8211; a gallery of exquisite websites</title>
		<link>http://wildreason.com/wildreason-blog/2010/i-heart-css-a-gallery-of-exquisite-websites/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/i-heart-css-a-gallery-of-exquisite-websites/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 08:07:18 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[php/mysql]]></category>
		<category><![CDATA[portfolio]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=253</guid>
		<description><![CDATA[I had the pleasure of working on a new project whose purpose is to feature exquisite websites around the web. Submit your website and get a chance to be featured on the webs newest gallery exchange! It features a simple and clean layout with a powerful administration backend. Custom content management system allows administrators to [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="I Heart CSS" src="http://i.imgur.com/EuCgI.png" alt="" width="178" height="132" />I had the pleasure of working on a new project whose purpose is to feature exquisite websites around the web. Submit your website and get a chance to be featured on the webs newest gallery exchange! It features a simple and clean layout with a powerful administration backend. Custom content management system allows administrators to (submitted sites) approve, reject, edit, categorize, order, and much more. Client had simple needs that were able to be met and (hopefully!) exceeded. If you have a site you would like to submit for consideration, give a try <a title="I heart CSS - a gallery of exquisite websites" href="http://iheartcss.com">here</a>.</p>
<p><strong>Technologies used: </strong>jQuery, AJAX, Colorbox, PHP, MySQL</p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/i-heart-css-a-gallery-of-exquisite-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wildreason Productions &#8211; Site Refresh</title>
		<link>http://wildreason.com/wildreason-blog/2010/wildreason-productions-site-refresh/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/wildreason-productions-site-refresh/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 21:26:19 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[site info]]></category>

		<guid isPermaLink="false">http://wildreason.com/wildreason-blog/?p=245</guid>
		<description><![CDATA[The mission: Create a design that compliments the purpose. The purpose: create beautiful and intuitive designs. My role: freelance website design extraordinaire. Status: Complete. Suggestions, feedback, hate mail: leave a comment! Be sure to look for a feature @ CSS Showcase and CSS Breeze soon!]]></description>
			<content:encoded><![CDATA[<p><strong>The mission: </strong>Create a design that compliments the purpose.<br />
<strong>The purpose:</strong> create beautiful and intuitive designs.<br />
<strong>My role:</strong> freelance website design extraordinaire. </p>
<p>Status: <strong style="color:green">Complete.</strong><br />
<br />
Suggestions, feedback, hate mail: leave a comment!</p>
<p>Be sure to look for a feature @ <a href="http://www.css-showcase.com/">CSS Showcase</a> and <a href="http://cssbreeze.com">CSS Breeze</a> soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/wildreason-productions-site-refresh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom error handling in PHP</title>
		<link>http://wildreason.com/wildreason-blog/2010/custom-error-handling-in-php/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/custom-error-handling-in-php/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 10:22:02 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[php/mysql]]></category>
		<category><![CDATA[error reporting]]></category>
		<category><![CDATA[invalid argument supplied foreach]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php debug mode]]></category>
		<category><![CDATA[runtime error]]></category>

		<guid isPermaLink="false">http://wildreason.com/posts/?p=220</guid>
		<description><![CDATA[There are a few methods to deal with error handling in PHP. I want to talk about the method &#8220;set_error_handler&#8221;. I like this method because I occasionally forget to check that an array has more than 0 items before running a foreach on it. An error like this won&#8217;t stop the script but it does [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few methods to deal with error handling in PHP. I want to talk about the method &#8220;set_error_handler&#8221;. I like this method because I occasionally forget to check that an array has more than 0 items before running a foreach on it. An error like this won&#8217;t stop the script but it does give the user a nasty error at the top of the page that can break the styling of the page. </p>
<p>Use this with caution however, as all but the most critical errors will be bypassed. The following shows the most basic implementation of the method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$debug</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> customError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$debug</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$debug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_USER_ERROR</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;ERROR&lt;/b&gt; [<span style="color: #006699; font-weight: bold;">$errno</span>] <span style="color: #006699; font-weight: bold;">$errstr</span> n&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//optional execution code</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>			
			<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_USER_WARNING</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;WARNING&lt;/b&gt; [<span style="color: #006699; font-weight: bold;">$errno</span>] <span style="color: #006699; font-weight: bold;">$errstr</span> n&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//optional execution code</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #009900; font-weight: bold;">E_USER_NOTICE</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;b&gt;NOTICE&lt;/b&gt; [<span style="color: #006699; font-weight: bold;">$errno</span>] <span style="color: #006699; font-weight: bold;">$errstr</span> n&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//optional execution code</span>
				<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unknown error type: [<span style="color: #006699; font-weight: bold;">$errno</span>] <span style="color: #006699; font-weight: bold;">$errstr</span> n&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/* Don't execute PHP internal error handler */</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #990000;">set_error_handler</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;customError&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This can be appended at the top of one your config files and it can be extended to perform different actions on different errors. Setting $debug = true will show you a lot of interesting errors that you probably never knew was happening as a lot of insignificant errors aren&#8217;t reported at all. </p>
<p>Again, use with caution! </p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/custom-error-handling-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Super simple example of AJAX with MooTools</title>
		<link>http://wildreason.com/wildreason-blog/2010/super-simple-example-of-ajax-with-mootools/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/super-simple-example-of-ajax-with-mootools/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 17:49:25 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://wildreason.com/posts/?p=183</guid>
		<description><![CDATA[AJAX is wonderful. It allows you to make calls to the server without refreshing the page. This allows your users to have an uninterrupted experience on your application. It gives sites a feel of professionalism and makes it feel more like an actual application. And, it turns out. That with MooTools (or jQuery) writing AJAX [...]]]></description>
			<content:encoded><![CDATA[<p>AJAX is wonderful. It allows you to make calls to the server without refreshing the page. This allows your users to have an uninterrupted experience on your application. It gives sites a feel of professionalism and makes it feel more like an actual application. And, it turns out. That with MooTools (or jQuery) writing AJAX is not only fun, but it&#8217;s exceedingly easy. With a little understanding of JavaScript and the MooTools framework, you can be writing AJAX like it&#8217;s your job. And maybe it is.
<p>The following super simple AJAX example is about as barebones as it possible can. There is no error checking and the example actually does very little. It&#8217;s meant to be a framework for beginners or a reference for advanced website designers. The only thing to keep in mind when designing sites with AJAX: it doesn&#8217;t work if the user has JavaScript disabled. Therefore, a decision has to be made. Make the scripts unobtrusive &#8211; results are still obtained without JavaScript &#8211; or acknowledge that your site won&#8217;t be functional with JavaScript. It&#8217;s up to you to determine your audience and decide who to cater to. Facebook for example, doesn&#8217;t work without JavaScript.</p>
<p>This example however, still works without JavaScript. But the results are slightly different. The user navigates to demo.html when they click the link as JavaScript isn&#8217;t there to intercept the click and halt it (return false in the onclick statement). </p>
<p>A super simple, complete example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;script src=&quot;/files/mootools.1.2.3.js&quot; type=&quot;text/javascript&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: #003366; font-weight: bold;">function</span> easyAjax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  url <span style="color: #339933;">=</span> <span style="color: #3366CC;">'demo.html'</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">new</span> Request<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span> url<span style="color: #339933;">,</span>
    method<span style="color: #339933;">:</span> <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>responseText<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">//write the response to someelement</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'someelement'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span> responseText<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: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&nbsp;
&lt;p&gt;
  &lt;a href=&quot;demo.html&quot; onclick=&quot;return easyAjax()&quot;&gt;Click&lt;/a&gt;
&lt;/p&gt;
&nbsp;
&lt;div id=&quot;someelement&quot;&gt;
&nbsp;
&lt;/div&gt;
&nbsp;
&lt;/html&gt;</pre></div></div>

<p>View the <a title="View working demo of simple AJAX example" href="/demo/axax-simple-example-demo.php">working demo</a>.<br />
View the <a title="MooTools Request documentation" href="http://mootools.net/docs/core/Request/Request">MooTools request documentation</a></p>
<p>An advanced example with error checking, visual effects, and PHP integration coming soon. <img src='http://wildreason.com/wildreason-blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/super-simple-example-of-ajax-with-mootools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What you can expect from me as a client</title>
		<link>http://wildreason.com/wildreason-blog/2010/what-you-can-expect-from-me-as-a-client/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/what-you-can-expect-from-me-as-a-client/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 16:08:45 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[site info]]></category>

		<guid isPermaLink="false">http://wildreason.com/posts/?p=178</guid>
		<description><![CDATA[What type of services do you offer? We do a variety of work in the realm of design, including &#8211; but not limited to &#8211; the following: Website design &#8211; Entire website design from the ground up. Graphics, on-page SEO, layout. Professional design at a fraction of the price. Graphic design &#8211; Entire site design, [...]]]></description>
			<content:encoded><![CDATA[<h2>What type of services do you offer?</h2>
<p>			We do a variety of work in the realm of design, including &#8211; but not limited to &#8211; the following:</p>
<ol>
<li><b>Website design</b> &#8211; Entire website design from the ground up. Graphics,<br />
					on-page SEO, layout. Professional design at a fraction of the price.</li>
<li><b>Graphic design</b> &#8211; Entire site design, individual banners, icon sets,<br />
					business cards.</li>
<li><b>PHP (server-side scripting)</b> &#8211; Custome PHP design and scripting. An example of one of our PHP projects is our <a href="/favicon" title="free online favicon generator">online favicon generator</a>.</li>
<li><b>Component installation</b> &#8211; E-commerce, <a href="/posts/" title="Freelance website design blog">blog</a>, image gallery, 	<a href="/demo/admin.php" title="Example of custom content management system. User control, page management, and more">CMS</a>, media players, etc</li>
<li><b>Site redesign</b> &#8211; For sites that need to be visually refreshed, made more user-friendly, or made more search friendly.</li>
<li><b>Ongoing SEO</b> &#8211; Marketing, creating backlinks, keyword research.</li>
<li><b>MySQL Database Design</b> &#8211; Services ranging from complex relational database design, simple user management, to existing database optimization. </li>
<li><b>E-commerce</b> &#8211; Integrate an e-commerce solution on a new or existing website to offer new or existing services.</li>
</ol>
<h2>What is involved in the design process?</h2>
<p>			Typically, the following is what you can expect through the design process:</p>
<ol>
<li>Initial consultation </li>
<li>Quote and proposal (including expectations and timeframe)</li>
<li>First invoice (initial deposit)
<li>Design mock-up</li>
<li>Final invoice (remaining balance)</li>
<li>Website delivery</li>
</ol>
<h2>Does your design include SEO?</h2>
<p>	This is an important question that always needs clarification. As the designer, our responsibility to the client lies in creating a website that meets their expectations in terms of functionality and design. It also includes creating a website that is search-engine friendly. Some of the characteristics of a search-engine friendly site are:</p>
<ol>
<li><b>Code that is clean.</b> Messy code isn&#8217;t easily readable or indexed by search engines. </li>
<li><b>Properly organized layout.</b> The content of a site should be laid out similar to an English paper. Title, introduction, body, and summary. All of which includes 	proper headings and sub-headings. This is all taken into account when search engines index websites. </li>
<li><b>A discussion with the client on what keywords will be targeted for their website.</b> While we may be able to guess, it is ultimately up to the client what keywords they would like to target. We will offer input and do basic research, but it is critical that our clients (the content generators) know what keywords they are targeting. </li>
<li><b>Proper use of internal links.</b> Creating external links to your site is an important part of ongoing SEO. Creating internal links that point to important<br />
			documents on your site is an important part of creating a search-engine friendly website. The more frequently a link to a particular document appears on your site, the more important search engines believe it to be.</li>
<li><b>URL design.</b> It is not only helpful for users to know where they are by looking 	at the URL, but it also adds to keyword relevance for search engines when your document&#8217;s URL&#8217;s are descriptive.</li>
<li><b>Sitemaps.</b> Sitemaps are not only important for your users to be able to quickly navigate your site, but they are important for search engines as well. There are two types of sitemaps. A visual sitemap, like the one at the bottom of our page, and an 	XML sitemap. An XML sitemap is a structured XML file that resides at the root of your site that isn&#8217;t used by visitors. It is used by search engines to help map out your site. Both types of sitemaps are included in the design (if requested) but updates to the sitemap are part of ongoing SEO. Alternatively, we can include a self-updating sitemap for an additional charge.</li>
<li><b>Load time.</b> Page load time (database design, graphics, etc) has a small effect on search engine prioritization, but it is important nonetheless. We work to design efficient databases and graphics with short load times in order to maximize the user experience and optimize your site for search engines.</li>
</ol>
<p>	All of these things are very important in creating a search-engine friendly website. And they are all included in the design process. Ongoing SEO is another topic, and while we offer it as an additional service, it is not included in the design cost of your website. </p>
<h2>Why do you discourage Flash?</h2>
<p>	Flash is a dying technology. This is a bold statement, but it is true. And it is a dying  technology for many reasons. It is buggy, difficult to index for search engines, and doesn&#8217;t play well at all on mobile devices. While we have and can include Flash on your website, things like Flash intros and Flash slideshows are HIGHLY discouraged. Search engine optimization should take priority over flashy lights and most Flash effects can be achieved with JavaScript and/or CSS. Used sparingly, it can add a nice touch to a website. But used heavily and irresponsibly, it can drastically damage your ability to achieve high search engine rankings.</p>
<h2>What about prices?</h2>
<p>	This is a topic that comes up occasionally: why aren&#8217;t prices discussed on your website? For our studio, website creation is personal. Every project is unique, and for that reason we price each project uniquely. Pricing is guaranteed to be fair and competitive. However, we produce professional designs and layouts so if you are serious about creating a website that is ready for search engine rankings and having a personal experience throughout the process, be ready for our rates. We aren&#8217;t a hack-and-slash design studio; communication is fast, expectations are clear, and production is fast and efficient.</p>
<p>	Generally speaking, a basic, static 3-page website (home, about, contact) will range between $350-$550, depending on the amount of requirements. Blog, e-commerce, galleries, etc will typically be in addition to the initial setup fee. Prices are always flexible and we are willing to work with you for payment plans. We also offer hosting and maintenance packages that drastically reduce the initial setup fee. </p>
]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/what-you-can-expect-from-me-as-a-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Convert a decimal into a simplified fraction</title>
		<link>http://wildreason.com/wildreason-blog/2010/javascript-convert-a-decimal-into-a-simplified-fraction/</link>
		<comments>http://wildreason.com/wildreason-blog/2010/javascript-convert-a-decimal-into-a-simplified-fraction/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 23:51:15 +0000</pubDate>
		<dc:creator>David Ryder</dc:creator>
				<category><![CDATA[freelance website design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[convert decimal]]></category>
		<category><![CDATA[convert fraction]]></category>
		<category><![CDATA[decimal to fraction]]></category>
		<category><![CDATA[fraction common denominator]]></category>
		<category><![CDATA[simplify fraction]]></category>

		<guid isPermaLink="false">http://wildreason.com/posts/?p=169</guid>
		<description><![CDATA[JavaScript doesn&#8217;t have a lot of high-level mathematical functions built-in and for a project I am/was working on, I needed to change the quantities of all the ingredients in a listed recipe when a user changed the value of the &#8220;Serves&#8221; drop down box. For example: Changing the drop down to 5 would require a [...]]]></description>
			<content:encoded><![CDATA[<p>JavaScript doesn&#8217;t have a lot of high-level mathematical functions built-in and for a project I am/was working on, I needed to change the quantities of all the ingredients in a listed recipe when a user changed the value of the &#8220;Serves&#8221; drop down box. For example:<BR><br />
<BR><br />
<img src="http://img685.imageshack.us/img685/1200/ss20100716174231.png" alt="change values of HTML with SELECT box" title="change values of HTML with SELECT box"><BR><br />
<BR><br />
Changing the drop down to 5 would require a 25% increase from the ORIGINAL values, resulting in:<BR><br />
<BR><br />
<img src="http://img685.imageshack.us/img685/6493/ss20100716174305.png" alt="multiply fraction convert to decimal first" title="change values of HTML with SELECT box"><BR><br />
<BR><br />
You should note that this is not a 100% accurate conversion. For the sake of readability, I use Math.round several times. So in cases where a fraction might be 64/100 it is first rounded to 60/100, reduced to 6/10 then simplified to 3/5. So four one hundredths (.04) accuracy is lost in that conversion. If you need higher precision you can remove the round functions to produce similar results at the cost of losing readability. <BR><br />
<BR></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//function to get highest common factor of two numbers (a fraction)</span>
<span style="color: #003366; font-weight: bold;">function</span> HCF<span style="color: #009900;">&#40;</span>u<span style="color: #339933;">,</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #003366; font-weight: bold;">var</span> U <span style="color: #339933;">=</span> u<span style="color: #339933;">,</span> V <span style="color: #339933;">=</span> v
	<span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</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><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>U<span style="color: #339933;">%=</span>V<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> V
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>V<span style="color: #339933;">%=</span>U<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> U 
	<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//convert a decimal into a fraction</span>
<span style="color: #003366; font-weight: bold;">function</span> fraction<span style="color: #009900;">&#40;</span>decimal<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>decimal<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		decimal<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	whole <span style="color: #339933;">=</span> String<span style="color: #009900;">&#40;</span>decimal<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	decimal <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #339933;">+</span>String<span style="color: #009900;">&#40;</span>decimal<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color: #009900;">&#41;</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>
	num <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>z<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> z<span style="color: #339933;">&lt;</span>String<span style="color: #009900;">&#40;</span>decimal<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> z<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		num <span style="color: #339933;">+=</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	decimal <span style="color: #339933;">=</span> decimal<span style="color: #339933;">*</span>num<span style="color: #339933;">;</span>
	num <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>z<span style="color: #339933;">=</span><span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> z<span style="color: #339933;">&lt;</span>decimal<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> z<span style="color: #339933;">++</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>decimal<span style="color: #339933;">%</span>z<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> num<span style="color: #339933;">%</span>z<span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			decimal <span style="color: #339933;">=</span> decimal<span style="color: #339933;">/</span>z<span style="color: #339933;">;</span>
			num <span style="color: #339933;">=</span> num<span style="color: #339933;">/</span>z<span style="color: #339933;">;</span>
			z<span style="color: #339933;">=</span><span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">//if format of fraction is xx/xxx</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>decimal.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> 
			num.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #006600; font-style: italic;">//reduce by removing trailing 0's</span>
		decimal <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>decimal<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		num <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">//if format of fraction is xx/xx</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>decimal.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> 
			num.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		decimal <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>decimal<span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		num <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>num<span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">//get highest common factor to simplify</span>
	<span style="color: #003366; font-weight: bold;">var</span> t <span style="color: #339933;">=</span> HCF<span style="color: #009900;">&#40;</span>decimal<span style="color: #339933;">,</span> num<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//return the fraction after simplifying it</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>whole<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: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">:</span> whole<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>decimal<span style="color: #339933;">/</span>t<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #339933;">+</span>num<span style="color: #339933;">/</span>t<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://wildreason.com/wildreason-blog/2010/javascript-convert-a-decimal-into-a-simplified-fraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

