<?xml version="1.0" encoding="iso-8859-1"?>
<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>CrankBerry Blog &#187; Javascript</title>
	<atom:link href="http://www.crankberryblog.com/category/scripts-and-programming/javascript-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.crankberryblog.com</link>
	<description>Sharing ideas on web design, development and the internet economy</description>
	<lastBuildDate>Thu, 22 Apr 2010 21:46:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Awesome image cropper/thumbnail maker script &#8211; Modified Marquee Tool</title>
		<link>http://www.crankberryblog.com/2010/awesome-image-cropperthumbnail-maker-script-modified-marquee-tool</link>
		<comments>http://www.crankberryblog.com/2010/awesome-image-cropperthumbnail-maker-script-modified-marquee-tool#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:59:31 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Thumbnail]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=344</guid>
		<description><![CDATA[As I'm recoding my portfolio right now, I thought to myself - how great would it be to have a thumbnail maker tool. Some PHP or Javascript solution to crop images dynamically without the use of Photoshop. I would hate to fire up Photoshop every time I want to upload something. I'm sure you've all been there before. Anyways I landed upon a script that suited my need exactly. The <a href="http://marqueetool.net/">Rectangle Marquee Tool</a>. The tool looks great but was a bit confusing for me to get working and based on the comment for a few others too. Now I've also done some slight PHP modification to get the script working to my needs and generating the correct thumbnails. 

See what I'm mumbling on about right here:
<strong><a href="http://www.crankberryblog.com/demo/marqueetool/">Demonstration of Marquee Tool</a></strong>


<img src="http://www.crankberryblog.com/images/thumbnail-cropper-script.jpg" />]]></description>
			<content:encoded><![CDATA[<p>As I&#039;m recoding my portfolio right now, I thought to myself &#8211; how great would it be to have a thumbnail maker tool. Some PHP or Javascript solution to crop images dynamically without the use of Photoshop. I would hate to fire up Photoshop every time I want to upload something. I&#039;m sure you&#039;ve all been there before. Anyways I landed upon a script that suited my need exactly. The <a href="http://marqueetool.net/">Rectangle Marquee Tool</a>. The tool looks great but was a bit confusing for me to get working and based on the comment for a few others too. Now I&#039;ve also done some slight PHP modification to get the script working to my needs and generating the correct thumbnails. </p>
<p>See what I&#039;m mumbling on about right here:<br />
<strong><a href="http://www.crankberryblog.com/demo/marqueetool/">Demonstration of Marquee Tool</a></strong></p>
<p><img src="http://www.crankberryblog.com/images/thumbnail-cropper-script.jpg" /></p>
<p>Once again I&#039;d like to clarify that I did not make the Rectangular Marquee Tool, it was written by Sergey Koksharov using certain functions of the Prototype/Scriptaculous framework. I&#039;m merely just doing some tweaks to make it work better in my circumstance. So all credits goes to Sergey and the Scriptaculous team.</p>
<p>My modification will allow you to do certain things such as:</p>
<ul>
<li>Define a input image dynamically</li>
<li>Define the output image dynamically</li>
<li>Generate a final output image</li>
</ul>
<p>I believe the PHP included in the original script was a bit dated so it wasn&#039;t working on my machine and servers that&#039;s why I made my own version.</p>
<p>So to start off you need to download the required files from: <a href="http://marqueetool.net/download/">here</a>. Then you need to extract the files into a scripts folder or whichever you prefer just remember to rename the source path after. The real files you need are:</p>
<ul>
<li>marker.css</li>
<li>prototype_reduced.js</li>
<li>rectmarquee.js</li>
</ul>
<p>Once you&#039;ve got the files extract them to the proper folders and create fresh PHP file to work with. This is the file your script will run from. I&#039;ll break down my code into chunks for you to understand, but I&#039;ll go in order so if you copy each chunk and paste them in the same order it should work. That is if you&#039;re reading this instruction right ;)</p>
<h3>Before the HTML</h3>
<p>So this piece of code starts off your whole document even before the HTML code. There&#039;s only two codes you need to modify which is the $img_src (original file) and $img_dst (final thumbnail file).</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span></p>
<p><span class="co1">//Source Image to Crop From</span><br />
<span class="re0">$img_src</span> = <span class="st0">&#039;img/&#039;</span>;</p>
<p><span class="co1">//Thumbnail Location</span><br />
<span class="re0">$img_dst</span> = <span class="st0">&#039;img/&#039;</span>;</p>
<p><span class="co1">//If you want to feed this dynamically you can use</span><br />
<span class="co1">//$_GET tags or draw them in through a database</span></p>
<p><span class="co1">//Some coding here not just for looks.</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$img_src</span>!=<span class="st0">&#034;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Check if Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Image Dimension</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$img_src</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Not A Valid Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_error</span> = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Getting Image Dimension</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_dim</span> = <a href="http://www.php.net/getimagesize"><span class="kw3">getimagesize</span></a><span class="br0">&#40;</span><span class="re0">$img_src</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Verfiy This Is An Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_verify</span> = @imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$img_src</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>!<span class="re0">$img_verify</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_error</span> = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Getting Dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_w</span> = imagesx<span class="br0">&#40;</span><span class="re0">$img_verify</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$img_h</span> = imagesy<span class="br0">&#40;</span><span class="re0">$img_verify</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$img_error</span> == <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#039;Not a valid image&#039;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exit"><span class="kw3">exit</span></a>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></div>
<h3>The HTML and HEAD Tags</h3>
<p>This is the code to begin your HTML tag and your chunk of HEAD tag. Note that if you didn&#039;t place your files in the same location you have to change the source path.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;html&gt;<br />
&lt;head&gt;</p>
<p>&lt;link rel=<span class="st0">&quot;stylesheet&quot;</span> type=<span class="st0">&quot;text/css&quot;</span> href=<span class="st0">&quot;css/marker.css&quot;</span> /&gt;</p>
<p>&lt;script type=<span class="st0">&quot;text/javascript&quot;</span> src=<span class="st0">&quot;scripts/prototype_reduced.js&quot;</span>&gt;&lt;/script&gt;<br />
&lt;script type=<span class="st0">&quot;text/javascript&quot;</span> src=<span class="st0">&quot;scripts/rectmarquee.js&quot;</span>&gt;&lt;/script&gt; </p>
<p>&lt;/head&gt;</p></div>
<h3>Your BODY and Closing HTML Tag</h3>
<p>So all that&#039;s left is the BODY tag. There&#039;s really no modification you need to do here except for the (don&#039;t paste this in your code in order):</p>
<div class="dean_ch" style="white-space: wrap;">coords: <span class="br0">&#123;</span>x1: <span class="nu0">0</span>, y1: <span class="nu0">0</span>, width: <span class="nu0">100</span>, height: <span class="nu0">50</span><span class="br0">&#125;</span></div>
<p>This line defines where the crop box starts and how big it should be. You can play around with it if you want. Anyways here&#039;s the coding (do paste this in).</p>
<div class="dean_ch" style="white-space: wrap;">&lt;body&gt;</p>
<p>&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt; &nbsp;<br />
<span class="kw2">var</span> MarqueeTool;</p>
<p><span class="kw2">function</span> onMarqueeUpdate<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> coords = MarqueeTool.getCoords<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#039;coord_x&#039;</span><span class="br0">&#41;</span>.value = coords.x1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#039;coord_y&#039;</span><span class="br0">&#41;</span>.value = coords.y1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#039;coord_w&#039;</span><span class="br0">&#41;</span>.value = coords.width;<br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span class="br0">&#40;</span><span class="st0">&#039;coord_h&#039;</span><span class="br0">&#41;</span>.value = coords.height;<br />
<span class="br0">&#125;</span></p>
<p>
<span class="kw2">function</span> onWindowLoad<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MarqueeTool = <span class="kw2">new</span> Marquee<span class="br0">&#40;</span><span class="st0">&#039;sampleid&#039;</span>, <span class="br0">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; preview: <span class="st0">&#039;preview&#039;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: <span class="st0">&#039;#000&#039;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; opacity: <span class="nu0">0.45</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; coords: <span class="br0">&#123;</span>x1: <span class="nu0">0</span>, y1: <span class="nu0">0</span>, width: <span class="nu0">100</span>, height: <span class="nu0">50</span><span class="br0">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; MarqueeTool.setOnUpdateCallback<span class="br0">&#40;</span>onMarqueeUpdate<span class="br0">&#41;</span>;</p>
<p><span class="br0">&#125;</span> </p>
<p>Event.observe<span class="br0">&#40;</span>window, <span class="st0">&#039;load&#039;</span>, onWindowLoad<span class="br0">&#41;</span>; </p>
<p><span class="kw2">&lt;/script&gt;</span> </p>
<p>&lt;div style=<span class="st0">&quot;width: &lt;?php echo $img_w; ?&gt;; height: &lt;?php echo $img_h; ?&gt;; position: relative;&quot;</span>&gt;<br />
&nbsp; &nbsp; &lt;img src=<span class="st0">&quot;&lt;?php echo $img_src; ?&gt;&quot;</span> alt=<span class="st0">&quot;&quot;</span> id=<span class="st0">&quot;sampleid&quot;</span> /&gt; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &lt;div id=<span class="st0">&quot;preview&quot;</span> style=<span class="st0">&quot;position: absolute; right: 10px; bottom: 10px; border: 2px solid #FFF;&quot;</span>&gt;&lt;/div&gt; <br />
&lt;/div&gt;</p>
<p>&lt;form name=<span class="st0">&quot;coordsform&quot;</span> action=<span class="st0">&quot;crop.php&quot;</span> target=<span class="st0">&quot;_blank&quot;</span> method=<span class="st0">&quot;get&quot;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;img&quot;</span> value=<span class="st0">&quot;&lt;?php echo $img_src; ?&gt;&quot;</span> /&gt;<br />
&nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;img_dst&quot;</span> value=<span class="st0">&quot;&lt;?php echo $img_dst; ?&gt;&quot;</span> /&gt;<br />
&nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;x&quot;</span> value=<span class="st0">&quot;5&quot;</span> id=<span class="st0">&quot;coord_x&quot;</span> /&gt;<br />
&nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;y&quot;</span> value=<span class="st0">&quot;0&quot;</span> id=<span class="st0">&quot;coord_y&quot;</span> /&gt;<br />
&nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;w&quot;</span> value=<span class="st0">&quot;0&quot;</span> id=<span class="st0">&quot;coord_w&quot;</span> /&gt;<br />
&nbsp; &nbsp; &lt;input type=<span class="st0">&quot;hidden&quot;</span> name=<span class="st0">&quot;h&quot;</span> value=<span class="st0">&quot;0&quot;</span> id=<span class="st0">&quot;coord_h&quot;</span> /&gt;</p>
<p>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &lt;input name=<span class="st0">&quot;submit&quot;</span> type=<span class="st0">&quot;submit&quot;</span> value=<span class="st0">&quot;Make Thumbnail&quot;</span>&gt;<br />
&lt;/form&gt; </p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</div>
<p>Now we&#039;re just about complete here. All this tool does right now is let you select an area to crop. To actually make the thumbnail you need the assistant of PHP (you can do it in JS but I prefer PHP). You need to have the GD library enabled in order for this to work. </p>
<p>At this point you need to create your last file which is named crop.php. All you need in crop.php is this:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> </p>
<p><span class="co1">//Variables</span><br />
<span class="re0">$img_w</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;w&#039;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$img_h</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;h&#039;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$img_x</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;x&#039;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$img_y</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;y&#039;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$img_src</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;img&#039;</span><span class="br0">&#93;</span>;<br />
<span class="re0">$img_dst</span> = <span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#039;img_dst&#039;</span><span class="br0">&#93;</span>;</p>
<p><span class="co1">//There&#039;s a Set Thumb</span><br />
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$img_w</span>&gt;<span class="nu0">0</span> &amp;&amp; <span class="re0">$img_h</span>&gt;<span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create New Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$new_img</span> = imagecreatetruecolor<span class="br0">&#40;</span><span class="re0">$img_w</span>, <span class="re0">$img_h</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Loading The Original Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$old_img</span> = imagecreatefromjpeg<span class="br0">&#40;</span><span class="re0">$img_src</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Copying Image</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imagecopy<span class="br0">&#40;</span><span class="re0">$new_img</span>, <span class="re0">$old_img</span>, <span class="nu0">0</span>, <span class="nu0">0</span>, <span class="re0">$img_x</span>, <span class="re0">$img_y</span>, <span class="re0">$img_w</span>, <span class="re0">$img_h</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span class="kw3">header</span></a><span class="br0">&#40;</span><span class="st0">&quot;Content-Type: image/jpeg&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; @imagejpeg<span class="br0">&#40;</span><span class="re0">$new_img</span>, <span class="re0">$img_dst</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; imagejpeg<span class="br0">&#40;</span><span class="re0">$new_img</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Destroy the Old Images</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imagedestroy<span class="br0">&#40;</span><span class="re0">$old_img</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; imagedestroy<span class="br0">&#40;</span><span class="re0">$new_img</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></div>
<p>That&#039;s it, and everything should work like planed. I&#039;ve tested this script out a few times but if anything doesn&#039;t work just let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2010/awesome-image-cropperthumbnail-maker-script-modified-marquee-tool/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Browser Friendly Div Tabs Script</title>
		<link>http://www.crankberryblog.com/2009/cross-browser-friendly-div-tabs-script</link>
		<comments>http://www.crankberryblog.com/2009/cross-browser-friendly-div-tabs-script#comments</comments>
		<pubDate>Sat, 14 Nov 2009 01:32:23 +0000</pubDate>
		<dc:creator>Jerry Low</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.crankberryblog.com/?p=287</guid>
		<description><![CDATA[For some reason modern designers and developers love to use tabs. Maybe they keep things organize and clean all in one page. Here's a incredibly simple cross browser compatible Javasript tabs script. The final result will look like the one below.

<img src="http://www.crankberryblog.com/images/javascript-tabs.jpg" />]]></description>
			<content:encoded><![CDATA[<p>For some reason modern designers and developers love to use tabs. Maybe they keep things organize and clean all in one page. Here&#039;s a incredibly simple cross browser compatible Javasript tabs script. The final result will look like the one below.</p>
<p><img src="http://www.crankberryblog.com/images/javascript-tabs.jpg" /></p>
<p><strong>Javascript</strong></p>
<p>Include this script either as a separate file or in between the head tags.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;script type=<span class="st0">&quot;text/javascript&quot;</span>&gt;</p>
<p>
<span class="co1">//Tab Selected</span><br />
<span class="kw2">function</span> show_content<span class="br0">&#40;</span>id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Hide Content</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hide_content<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Change Tab</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; change_tab<span class="br0">&#40;</span>id<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Strip Id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> new_id = id.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">&#039;tab_&#039;</span>, <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; document.<span class="me1">getElementById</span><span class="br0">&#40;</span>new_id<span class="br0">&#41;</span>.<span class="me1">style</span>.<span class="me1">display</span> = <span class="st0">&quot;block&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> hide_content<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Hide Others</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> content_div = document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&#039;content_area&#039;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> content_inner = content_div.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">&#039;DIV&#039;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> other_div = content_inner.<span class="me1">length</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>;i &lt; other_div; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content_inner<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">style</span>.<span class="me1">display</span> = <span class="st0">&quot;none&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">function</span> change_tab<span class="br0">&#40;</span>id<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Change Others</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> tab_div = document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&#039;tab_bar&#039;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> tab_inner = tab_div.<span class="me1">getElementsByTagName</span><span class="br0">&#40;</span><span class="st0">&#039;DIV&#039;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> other_tab = tab_inner.<span class="me1">length</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i=<span class="nu0">0</span>; i &lt; other_tab; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tab_inner<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">className</span> = <span class="st0">&quot;tab_button&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Last Tab Change</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; document.<span class="me1">getElementById</span><span class="br0">&#40;</span>id<span class="br0">&#41;</span>.<span class="me1">className</span> = <span class="st0">&quot;tab_button tab_button_sel&quot;</span>;<br />
<span class="br0">&#125;</span></p>
<p>&lt;/script&gt;</p></div>
<p><strong>CSS</strong></p>
<p>This is your CSS code that needs to also go between the HEAD tags or you can have a separate file once again.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;style type=<span class="st0">&quot;text/css&quot;</span>&gt;</p>
<p>body <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; font-family<span class="re2">:Arial</span>, Helvetica, <span class="kw2">sans-serif</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">font-size</span>: <span class="re3">12px</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_area</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span>: <span class="re3">480px</span>;&nbsp; &nbsp;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_bar</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span>: <span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">333</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border-left</span>: <span class="kw2">none</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border-bottom</span>: <span class="kw2">none</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span>: <span class="kw1">left</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">clear</span>: <span class="kw1">left</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_button</span>&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border-left</span>: <span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">333</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">background</span>: <span class="re0">#E8E8E8</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">padding</span>: <span class="re3">6px</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span>: <span class="kw1">left</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">display</span>: <span class="kw2">inline</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">cursor</span>: <span class="kw2">pointer</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_button_sel</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">background</span>: <span class="kw2">none</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_button</span><span class="re2">:hover</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">background</span>: <span class="re0">#CCC</span>;&nbsp; &nbsp; &nbsp; &nbsp;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.content_area</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">padding</span>: <span class="re3">6px</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">width</span>: <span class="re3"><span class="nu0">100</span>%</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">float</span>: <span class="kw1">left</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">border</span>: <span class="re3">1px</span> <span class="kw2">solid</span> <span class="re0">#<span class="nu0">333</span></span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="re1">.tab_content</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">display</span>: <span class="kw2">none</span>;<br />
<span class="br0">&#125;</span></p>
<p>&lt;/style&gt;</p></div>
<p><strong>HTML</strong></p>
<p>This is your HTML code for the tabs, obviously you can customize this all you want to fit your content.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div class=&quot;tab_area&quot;&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;tab_bar&quot; id=&quot;tab_bar&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_button&quot; id=&quot;tab_one&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab One&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_button&quot; id=&quot;tab_two&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab Two&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_button&quot; id=&quot;tab_three&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab Three&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;content_area&quot; id=&quot;content_area&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_content&quot; id=&quot;one&quot;&gt;Content Area One&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_content&quot; id=&quot;two&quot;&gt;Content Area Two&lt;/div&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;tab_content&quot; id=&quot;three&quot;&gt;Content Area Three&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;/div&gt;<br />
&lt;/div&gt;</div>
<p>The final tweak, lastly to ensure a default tab is selected from the beginning change your opening BODY tag to the following.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;body onload=&quot;show_content(&#039;tab_one&#039;);&quot;&gt;</div>
<h3>Adding Tabs and Content</h3>
<p>Ensure that you add the same amount of tabs as content or else there won&#039;t be enough tabs per content or vice-versa.</p>
<p><strong>Adding Tabs</strong></p>
<p>To add tabs just keep copying and pasting the following lines. Ensure the number of the id counts in order from 1, 2, 3&#8230; etc. You must have tab_ in front of the number.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div class=&quot;tab_button&quot; id=&quot;tab_one&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab One&lt;/div&gt;<br />
&lt;div class=&quot;tab_button&quot; id=&quot;tab_two&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab Two&lt;/div&gt;<br />
&lt;div class=&quot;tab_button&quot; id=&quot;tab_three&quot; onclick=&quot;show_content(this.id);&quot;&gt;Tab Three&lt;/div&gt;</div>
<p><strong>Adding Contents</strong></p>
<p>Same thing with the content just keep on duplicating and name the id in sequence in terms of numbers.</p>
<div class="dean_ch" style="white-space: wrap;">&lt;div class=&quot;tab_content&quot; id=&quot;one&quot;&gt;Content Area One&lt;/div&gt;<br />
&lt;div class=&quot;tab_content&quot; id=&quot;two&quot;&gt;Content Area Two&lt;/div&gt;<br />
&lt;div class=&quot;tab_content&quot; id=&quot;three&quot;&gt;Content Area Three&lt;/div&gt;</div>
<p>If you have any questions or trouble with this script just let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.crankberryblog.com/2009/cross-browser-friendly-div-tabs-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
