<?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>Web International Awards &#187; articles</title>
	<atom:link href="http://www.webia.info/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webia.info</link>
	<description></description>
	<lastBuildDate>Tue, 09 Aug 2011 15:42:18 +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>Coding a simple slider in no time</title>
		<link>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/</link>
		<comments>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/#comments</comments>
		<pubDate>Tue, 10 May 2011 15:00:51 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[lightweight]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1879</guid>
		<description><![CDATA[

We've published a couple of articles on sliders in the past. We first had a tutorial on building a XML powered slider, then we released the source codes and demo for the xml slider and we finally released the latest revision as the xml slider plugin. Today we're going back to basics, as I am [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2011/05/simple_slider.jpg"><img src="http://www.webia.info/wp-content/uploads/2011/05/simple_slider.jpg" alt="simple slider" title="simple slider" width="540" height="250" class="alignnone size-full wp-image-1868" /></a></p>
<p>
We've published a couple of articles on sliders in the past. We first had a <a href="http://www.webia.info/articles/tutorials/make-your-own-jquery-slider-using-xml/">tutorial on building a XML powered slider</a>, then we released the <a href="http://www.webia.info/articles/tutorials/awesome-slider-demo-and-source-codes/">source codes and demo for the xml slider</a> and we finally released the latest revision as the <a href="http://products.webraptor.eu/AwesomeSlider/">xml slider plugin</a>. Today we're going back to basics, as I am going to show you how to make a rather simple, lightweight slider in no time. Here's a <a href="http://demos.webia.info/simple_slider/">demo</a> of what we're building today.
</p>
<h2>HTML structure</h2>
<p>This structure will retain and contain the actual thumbs which will be displayed as the slider's content. As you'll probably figure out, I am using the <a href="http://960.gs/">960gs</a> to keep the structural integrity as simple as possible.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;wrapper&quot; class=&quot;container_12&quot;&gt;
&nbsp;
	&lt;div id=&quot;featured-wrapper&quot; class=&quot;grid_12 all-rounded&quot;&gt;
		&lt;div class=&quot;arrowleft&quot;&gt;&amp;nbsp;&lt;/div&gt;
		&lt;div id=&quot;featured-thumb&quot; class=&quot;grid_12 alpha omega all-rounded&quot;&gt;	
			&lt;ul id=&quot;featured-thumb-list&quot;&gt;
&nbsp;
			&lt;/ul&gt;	
		&lt;/div&gt;
		&lt;div class=&quot;arrowright&quot;&gt;&amp;nbsp;&lt;/div&gt;
		&lt;div class=&quot;clear&quot;&gt;&amp;nbsp;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<p>
The <em>wrapper</em> is used to hold the entire contents of the page in the center of it. <em>featured-wrapper</em> will hold the next, previous arrows as well as the <em>featured-thumb</em> div that wraps the thumbnail list. <em>featured-thumb</em> will have overflow set to hidden so that only a couple of thumbs are shown at a time. The unordered list will be shifting left to right when users click the arrows to reveal other caricatures. Before we get there, here's the code that is used to display the thumbs. The following piece of code will be repeated inside the unordered list depending on how many thumbs we want to display.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;li class=&quot;grid_2&quot;&gt;
	&lt;a href=&quot;#&quot; class=&quot;all-rounded&quot;&gt;
		&lt;img src=&quot;thumb_featured.png&quot; width=&quot;120&quot; height=&quot;150&quot; alt=&quot;caption title&quot; class=&quot;all-rounded&quot; /&gt;
		caption title
	&lt;/a&gt;
&lt;/li&gt;</pre></td></tr></table></div>



<h2>Styling the slider with a sprinkle of css</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">207px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #6666ff;">.arrowleft</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">49px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">61px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'arrow_left.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #6666ff;">.arrowright</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">49px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">61px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-27px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'arrow_right.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">50</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">20000px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</span> li img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F1F1F1</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>



<p>
I left out the code for the grid system. What this piece of css does is it sets the width and heigh of the div that wraps the slider controls and content, it positions the arrows and displays their background images (I used background images for the arrow design). It also sets the structure and overflow of the <em>featured-thumb</em> div that wraps the list of thumbnails. Finally, it applies some basic styles to the thumbnail placeholder and the links used for each thumbnail.
</p>
<h2>jQuery functionality</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> featured_thumb<span style="color: #009900;">&#40;</span>maxwidth<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">// featured thumb functionality</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> maxwidth<span style="color: #339933;">==</span><span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>maxwidth<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>maxwidth<span style="color: #339933;">=</span><span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.arrowright'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#featured-thumb-list&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;margin-left&quot;</span><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: #009900;">&#41;</span><span style="color: #339933;">&lt;=-</span>maxwidth<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">+</span>maxwidth
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'-=160'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.arrowleft'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#featured-thumb-list&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;margin-left&quot;</span><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: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'0'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'+=160'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// end featured thumb functionality</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	featured_thumb<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">850</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
In the above javascript snippet we define a function which adds the required functionality to the slider. Its sole parameter is the <em>maxwidth</em> variable, which is the maximum width of the margin-left property which is modified to move the thumbnail inside the placeholder. So if the placeholder is 800 px in width and the <em>maxwidth</em> variable set to 850, the thumbs will move around in a 1650 box. There are two onclick events (lines 4 and 24) which basically trigger the same functionality that is applied in opposite directions (left and right). To move left, we add pixels to left margin. To move right, we subtract from the left margin.
</p>
<p>Because the margin-left attribute is defined as <em>X px;</em>, where <em>X</em> is a number, we parse this value into a float (to allow negative values also), then we round the number (to prevent anything bad going on) and compare the value with 0 or <em>maxwidth</em> depending on the direction we're headed to. If we're going left and by clicking the left arrow the margin would become greater than 0, we have reached the end of the slider and we therefor stop the animation from sliding the content even further. If you try many repeated clicks you'll  this code will even perform an effect similar to a bouncing effect. Similarly, if moving the content to the right, the margin is compared to negative <em>maxwidth</em> (<=-maxwidth). If we reach this threshold, once again we're at the end of the thumbnails box and the animation needs to be stopped to prevent moving the thumbnails further.
</p>
<p>
To conclude, I guess that in order to reduce the size of the code one can write an extra function for the <em>onclick</em> behavior and call it when needed instead of copy pasting it into each of the events and doing the minor customization I've done.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Start passenger standalone on server restart or on service failure</title>
		<link>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/</link>
		<comments>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/#comments</comments>
		<pubDate>Tue, 03 May 2011 15:00:12 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[health]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[passenger standalone]]></category>
		<category><![CDATA[phusion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1854</guid>
		<description><![CDATA[
We've had this problem with our own servers and rails apps running on Passenger standalone and turns out there are a lot of you experiencing the same problems from time to time. This short tutorial will help you solve the following problems:


How can I keep Passenger Standalone up even after a server restart?
How do I [...]]]></description>
			<content:encoded><![CDATA[<p>
We've had this problem with our own servers and rails apps running on Passenger standalone and turns out there are a lot of you experiencing the same problems from time to time. This short tutorial will help you solve the following problems:
</p>
<ol>
<li>How can I keep Passenger Standalone up even after a server restart?</li>
<li>How do I run health checks on Passenger Standalone?</li>
<li>How do I automatically restart and spawn a rails app if it crashes under Passenger Standalone?</li>
</ol>
<p>
There are a number of fixes for the above issues, but there isn't a simple one to fix all in one. Or at least I haven't come across any of them. One fix for the first problem was placing a script in <em>/etc/init</em> so that passenger would start when the server is rebooted. This however didn't fix the other two issues as it would only start Passenger when the entire server would start, meaning Passenger wouldn't be started if for example the server ran out of memory, something crashed the rails apps etc.
</p>
<p>
The best fix I could think of was creating a script that checks whether Passenger standalone is running every minute and if it isn't, then start it. This fix would work for all scenarios: server reboot, application crash. Moreover, as the script would run as a cronjob every minute, it would also perform a health check on all running apps. Here's the code for the script.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">13007</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># passenger down</span>
    <span style="color: #c20cb9; font-weight: bold;">date</span>
    . <span style="color: #ff0000;">&quot;/usr/local/rvm/scripts/rvm&quot;</span>
    rvm use 1.9.2
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>
    passenger start <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">13007</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-e</span> production <span style="color: #660033;">--user</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">13008</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># passenger down</span>
    <span style="color: #c20cb9; font-weight: bold;">date</span>
    . <span style="color: #ff0000;">&quot;/usr/local/rvm/scripts/rvm&quot;</span>
    rvm use 1.9.2
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>
    passenger start <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">13008</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-e</span> production <span style="color: #660033;">--user</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>



<p>
The above example is for a server running two apps on Passenger Standalone behind apache on ports 13007 and 13008. Replace <em>{USER} , {APP1}, {APP2}</em> with your own configuration. Once you've written your file, save it to <em>/home/{USER}/rails_apps/health_check.sh</em> and then add a cronjob to run it every minute, 5 minutes or whenever you want.
</p>
<p>
The code above checks whether there are any processes listening on the ports defined for each app. If there is a single process, the output will be written to a file which will have a file size greater than 0. If there are no processes listening on that port, the file size will be 0. The next step is to check the file size. If it is 0, our app is not running and we can start it. Simple as that. And it works for reboots, crashes, integrity and health checks and more. 
</p>
<p>
If you're wondering what's with the date command, here's the answer. In my cronjob I've set the output of the command to  <em>/home/{USER}/rails_apps/health_check.log</em>. If any app is started (meaning it was down for some reason) I will have the info and the timestamp in the log. I can then look throughout the apache / nginx / rails logs at that specific timestamp and identify the problem that caused the app to crash, if there were any bugs.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dealing with Magento&#8217;s Transactional Email preview issues</title>
		<link>http://www.webia.info/articles/tutorials/dealing-with-magentos-transactional-email-preview-issues/</link>
		<comments>http://www.webia.info/articles/tutorials/dealing-with-magentos-transactional-email-preview-issues/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 07:17:59 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[items.phtml]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[transactional email]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1853</guid>
		<description><![CDATA[


We've recently had to tackle a issue with transactional emails in Magento for a client of ours. Magento has a nice way you can configure transactional emails in admin and preview them before using them in production. However, every once in a while things start to go really wrong and the following error is well [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2011/04/magento_quick_fixes.jpg"><img src="http://www.webia.info/wp-content/uploads/2011/04/magento_quick_fixes.jpg" alt="" title="magento_quick_fixes" width="540" height="250" class="alignnone size-full wp-image-1868" /></a></p>

<p>
We've recently had to tackle a issue with transactional emails in Magento for a client of ours. Magento has a nice way you can configure transactional emails in admin and preview them before using them in production. However, every once in a while things start to go really wrong and the following error is well known throughout the Magento community:
</p>

<code>
PHP Fatal error: Call to a member function getAllItems() on a non-object in …template/email/order/items.phtml on line 38
</code>
<br />
<p>
If you look inside the code for items.phtml, on that specific line you'll find a for statement trying to loop through the items in an object that can be nil and it isn't tested for nil. I assume Magento's developers really considered that there can't be a single case when that object can be nil. Unfortunately it can and unfortunately it will throw nasty errors in the view.</p>

<h2>Attempt 1: New Order Confirmation Template settings</h2>
<p>The error may be triggered because you've missed to assign the (new) transactional email to the order in Magento's Admin section (<em>Admin >> System >> Configuration >> Sales >> Sales Emails >> New Order Confirmation Template</em>). If you get to Sales Emails tab in Magento's admin, you'll find a drop down for New Order Confirmation Template. Select the desired option then go to cache management and clear your cache. After you do these steps the previews should work just fine.</p>
<p>But what do you do if they don't work just fine?</p>
<h2>Attempt 2: copy original files from frontend</h2>
<p>It may be the case that the files required to process the preview got corrupted or messed up somehow. A fix for this issue would be to back up all the files that you have in your Magento installation <em> {root}/app/design/adminhtml/default/default/template/email/order/</em> . Once you've backed them up copy the contents of <em>/home/{user_account}/public_html/app/design/frontend/default/default/template/email/order</em> to <em>/home/{user_account}/public_html/app/design/adminhtml/default/default/template/email/order</em> and things should resume their normal behaviour. Perhaps you should once again clear your cache.</p>
<h2>Still not working?</h2>
<p>
Magento requires a lot of resources and some installations may be using Memcached. I even recommend you start using it if you don't. But when you're debugging Memcached may make you really unhappy if you forget about it. You should check if you're using Memcached or not, and if yes, you should log in to your server via ssh, then flush Memcached and voila, the transactional emails preview will work like a glove and the ugly "<em>PHP Fatal error: Call to a member function getAllItems() on a non-object in …template/email/order/items.phtml on line 38</em>
" error be gone.
</p>
<p>In order to flush Memcached you should telnet to the service. Usually it's easily done by running <em>telnet localhost 11211</em> and then <em>flush_all</em>. Once you do this you can quit telnet or just before that check your Memcached status using <em>stats</em></p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/dealing-with-magentos-transactional-email-preview-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Always ask the right questions in your webforms!</title>
		<link>http://www.webia.info/articles/usability/always-ask-the-right-questions-in-your-webforms/</link>
		<comments>http://www.webia.info/articles/usability/always-ask-the-right-questions-in-your-webforms/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 12:00:38 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user]]></category>
		<category><![CDATA[webform]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1836</guid>
		<description><![CDATA[
Before diving in into the issue, I'd like to point out this great article over Usability Post that describes a delicate issue: using verbs on labels and buttons. Applying the same idea, it's best if you asked the right questions too. You wouldn't want to confuse the users and give them headaches while answering your [...]]]></description>
			<content:encoded><![CDATA[<p>
Before diving in into the issue, I'd like to point out this great article over Usability Post that describes a delicate issue: <a href="http://www.usabilitypost.com/2008/08/30/usability-tip-use-verbs-as-labels-on-buttons/" target="_new">using verbs on labels and buttons</a>. Applying the same idea, it's best if you asked the right questions too. You wouldn't want to confuse the users and give them headaches while answering your questions. This matters on each question of you form, from the most complicated to the simple captcha questions.
</p>
<p>
So, don't ask if I am human and expect an answer other than yes or no. SDUIHA or jgV54D is not a valid answer if you asked me if I were human. Imagine you asked a Japanese what was their name and they replied Sushi. Now that wouldn't be a great start, would it? So to wrap things up, never ask anyone if they're human and expect gibberish in return. One bad example from <a href="http://www.hongkiat.com/blog/" target="_new">Hongkiat</a> is just below.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2011/02/hongkiat_bad_form_question.jpg" title="Form asking if I were human and expecting gibberish in return instead of yes or no"><img src="http://www.webia.info/wp-content/uploads/2011/02/hongkiat_bad_form_question.jpg" alt="Form asking if I were human and expecting gibberish in return instead of yes or no" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/usability/always-ask-the-right-questions-in-your-webforms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drop ftp and switch to unison</title>
		<link>http://www.webia.info/articles/drop-ftp-and-switch-to-unison/</link>
		<comments>http://www.webia.info/articles/drop-ftp-and-switch-to-unison/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 21:54:54 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[bi-directional]]></category>
		<category><![CDATA[bidirectional]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[transfer]]></category>
		<category><![CDATA[unidirectional]]></category>
		<category><![CDATA[unison]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1818</guid>
		<description><![CDATA[

This article is directed to those of you who use on a daily basis any FTP program to transfer files back and forth between computers, development and production environments and more. Doing it via FTP comes handy compared to file uploading plugin in CPanel or Plesk for example, but when it compares to rsync or [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2011/02/unison_1.jpg" title="Preview of unison"><img src="http://www.webia.info/wp-content/uploads/2011/02/unison_1.jpg" alt="Preview of unison" /></a></p>
<p>
This article is directed to those of you who use on a daily basis any FTP program to transfer files back and forth between computers, development and production environments and more. Doing it via FTP comes handy compared to file uploading plugin in CPanel or Plesk for example, but when it compares to rsync or unison, FTP seems so old and time consuming.
</p>
<h2>Not familiar with rsync or unison?</h2>
<p>
Rsync is an open source utility that provides fast incremental file transfer. You can easily use it to backup your disk, upload files onto a test server while coding them locally. There are some great things you can do with this tool:</p>
<ol>
	<li>Initiate synchronization between two folders (and their sub-structure). These folders could be a local folder of a webapp and its public server brother. It may very well be your root folder on your pc and the root folder of an external backup disk.</li>
	<li>Start modifying files in any of the two folders, then sync the other one. This can help you easily write your code locally and deploying it on the server, or backing up vital data onto an external harddisk.</li>
	<li>Restore files you've deleted or ill modified from the secondary folder (backup).</li>
</ol>
<p>
And the list doesn't stop there. The possibilities of rsync are great...up to a point. Rsync doesn't do bi-directional transfer unfortunately and this has become, to me at least, a major drawback. You'd jump to say that I've stated the exact opposite just above. Yes, you can move files both ways with rsync, but in the case you've modified some in folder1 and some files in folder2, you won't be able to sync and keep all modifications in place by using merging. You'll have to choose which modifications to let go (which is unlikely to be the case) or do the sync yourself. But then, what would be the point of using rsync as it doesn't do much good?
</p>
<p>
Fortunately, there's a better tool called Unison which does mainly the same things as rsync, but is capable of synchronizing data both ways. If you modified files in both folders, you'll keep all modifications as Unison will transfer from one point to another the most recent files. If the same file has been modified on both ends, Unison will detect the conflict and ask you how you want to proceed. Now this is a really great and powerful feature.
</p>
<h2>Now why would you drop FTP in favor of these two?</h2>
<p>
Imagine you've got a project that has more than 100 folders, more than 1000 files, and after a bugfix you've modified files in 10 directories. The average user that hasn't any system setup or repository would write down modified files, and then browse the hard drive and the FTP account and copy/paste each file one by one, or in lucky cases, multiple at a time. </p>
<p>Anyway, you'd have to be really lucky to do all files in one shot. With rsync or Unison, you'd do them all in one shot, without to much worries. Moreover, if you find yourself out of the office and need to do a quick and simple fix, you can even do it directly on the server and then sync it back to your local folder. Wouldn't this be great?
</p>
<p>Check out some more information about <a href="http://samba.anu.edu.au/rsync/">rsync</a> or <a href="http://www.cis.upenn.edu/~bcpierce/unison/">Unison</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/drop-ftp-and-switch-to-unison/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a POI map using jQuery &amp; Google Maps v3 (revised)</title>
		<link>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3-revised/</link>
		<comments>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3-revised/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 06:54:32 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[poi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1772</guid>
		<description><![CDATA[
In the first revision of this tutorial, you've asked a couple of times if it is possible to display multple POIs at the same time on the map. The answer is yes, you can!
clearOverlays() gone
The clearOverlays() function was used to actually erase all markers on the map (all POIs on the map) when you clicked [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/08/office_location.png" title="Tutorial preview"><img src="http://www.webia.info/wp-content/uploads/2010/08/office_location_small.jpg" alt="Tutorial preview" /></a></p>
<p>In the <a href="http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/">first revision of this tutorial</a>, you've asked a couple of times if it is possible to display multple POIs at the same time on the map. The answer is yes, you can!</p>
<h2>clearOverlays() gone</h2>
<p>The clearOverlays() function was used to actually erase all markers on the map (all POIs on the map) when you clicked any link in the sidebar. In order to display multiple POIs on the map, this function must not be used. Therefor, in the revised version of the POI map the function was discarded as well as its unique call in the <em>handle_clicks()</em> function.</p>
<h2>addMarker() updated</h2>
<p>
The original version of the function didn't check before appending a marker to the <em>markersArray</em> if there's already a marker with the same coordinates. That wasn't necessary because such a case wasn't possible because the<em> clearOverlays()</em> function assured there are no markers in the array when the <em>addMarker()</em> function was called. However, discarding the <em>clearOverlays() </em>function results in duplicated markers in the array each time someone clicks multiple times on the same link in the sidebar. To prevent that, we must check before adding a new marker to the array if it doesn't already exist. We do that within the <em>addMarker()</em> function:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addMarker<span style="color: #009900;">&#40;</span>m_position<span style="color: #339933;">,</span>m_title<span style="color: #339933;">,</span>m_infowindow<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> mark<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>markersArray.<span style="color: #660066;">length</span><span style="color: #339933;">!=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		duplicate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> markcopy<span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> markersCopy <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>markcopy<span style="color: #339933;">=</span>markersArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>markcopy.<span style="color: #660066;">position</span>.<span style="color: #660066;">lat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>m_position.<span style="color: #660066;">lat</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>markcopy.<span style="color: #660066;">position</span>.<span style="color: #660066;">lng</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span>m_position.<span style="color: #660066;">lng</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> duplicate <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			markersCopy.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>markcopy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		markersArray <span style="color: #339933;">=</span> markersCopy<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>duplicate<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			  	position<span style="color: #339933;">:</span> m_position<span style="color: #339933;">,</span>
			  	map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
				title<span style="color: #339933;">:</span> m_title
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			mark <span style="color: #339933;">=</span> markersArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>mark<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				infoWindow.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> stringContent <span style="color: #339933;">=</span> m_infowindow<span style="color: #339933;">;</span>
				infoWindow.<span style="color: #660066;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>infowin-overlay<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>stringContent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				overlayHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				overlayWidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span>overlayHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span>overlayWidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #009900;">&#123;</span>
		marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		  	position<span style="color: #339933;">:</span> m_position<span style="color: #339933;">,</span>
		  	map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
			title<span style="color: #339933;">:</span> m_title
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		mark <span style="color: #339933;">=</span> markersArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>mark<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			infoWindow.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> stringContent <span style="color: #339933;">=</span> m_infowindow<span style="color: #339933;">;</span>
			infoWindow.<span style="color: #660066;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>infowin-overlay<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>stringContent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			overlayHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			overlayWidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span>overlayHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span>overlayWidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>



<p>
In the above script we do the following: we first check if there's any markers in the array (line 4), and if the array is empty, we create a new marker, add it to the array and add a listener to it (lines 39 to 56). The listener is required because we need a trigger that will display the overlay window when a marker is clicked. 
</p>
<p>
If the array is not empty, we check if the current marker to be added is already in the array. That's done with the while loop between lines 9 and 13. As you can see, the <em>duplicate</em> variable is initialized to false. If there's a marker in the array with the same coordinates as the marker we're trying to add, the value is changed to true. If duplicate variable remains false after the while loop is completed, we can safely add the marker to the array as described in the previous paragraph.
</p>
<p>
Because the required changes were minor, I decided not to update the entire tutorial, but to simply release the new source codes and show you the new function that does the trick. Therefor, you can view a <a href="http://demos.webia.info/map_demo_revised/map.html">new demo of the POI map</a> script over here and download the full source code over <a href="http://demos.webia.info/map_demo_revised/source.zip">here</a>.
</p>
<p>If you enjoyed this article you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.</p>	]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3-revised/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in JSP [II]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 10:00:21 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1747</guid>
		<description><![CDATA[

Last week I started building a live news blogging system using JSP. This is a follow up tutorial I've decided to do after seeing the success of the previous series, which described how to build the same web application using php as backend.

Adding news to the database

In today's part I am going to code the [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
Last week I started <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/">building a live news blogging system using JSP</a>. This is a follow up tutorial I've decided to do after seeing the success of the previous series, which described how to build the same web application using php as backend.
</p>
<h2>Adding news to the database</h2>
<p>
In today's part I am going to code the JSP files needed to add content to the database. The same functionality has already been developed using PHP in the third part of the original tutorial series located over <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-iii/">here</a>. The PHP version contained a function that was used to generate a select field into the add news form which would contain all available news categories. Differently, I've chosen not to include such a feature in a JSP function. Instead, I've added it directly into the HTML template. Not so fancy, but it works.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;addnews.jsp&quot; method=&quot;post&quot; accept-charset=&quot;utf-8&quot; id=&quot;form-overlay&quot;&gt;
	&lt;fieldset&gt;
		&lt;label for=&quot;title&quot;&gt;Title : &lt;/label&gt;
		&lt;input type=&quot;text&quot; name=&quot;title&quot; value=&quot;&quot; id=&quot;title&quot; class=&quot;all-rounded&quot;/&gt;
		&lt;label for=&quot;formcategory&quot;&gt;Category :&lt;/label&gt;
		&lt;select name=&quot;formcategory&quot; id=&quot;formcategory&quot; length=&quot;1&quot;&gt;
			&lt;% 						
			st = new StringTokenizer(categories,&quot;-&quot;);
			query = &quot;SELECT name FROM Categories WHERE id&gt;0 ORDER BY name ASC&quot;;
			rs = statement.executeQuery(query);
			count = 0;
				while (rs.next()) 
				{
					count++;
					String name = rs.getString(&quot;name&quot;);
					if(count==1) { %&gt; &lt;option selected=&quot;selected&quot; value=&quot;&lt;%=name%&gt;&quot;&gt;&lt;%=name%&gt;&lt;/option&gt; &lt;% }
					else { %&gt; &lt;option value=&quot;&lt;%=name%&gt;&quot;&gt;&lt;%=name%&gt;&lt;/option&gt; &lt;% }
				}
			if(count==0) { %&gt; &lt;option value=&quot;none&quot;&gt;none&lt;/option&gt; &lt;% }
			%&gt;
		&lt;/select&gt;
		&lt;label for=&quot;body&quot;&gt;Body text :&lt;/label&gt;
		&lt;textarea name=&quot;body&quot; rows=&quot;8&quot; cols=&quot;40&quot; class=&quot;all-rounded&quot;&gt;&lt;/textarea&gt;
		&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Add news&quot; id=&quot;submit&quot; class=&quot;submit all-rounded&quot; /&gt;
	&lt;/fieldset&gt;
&lt;/form&gt;</pre></td></tr></table></div>



<p>
As you've seen in the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/">previous part</a>, the code on lines 8 to 10 is used to create a SQL query and run it. Lines 11/19 check if the SQL query returned an empty result. If yes, a default news category is created as the unique option; current case: <em>none</em>. If there's at least one category in the database, the code between line 12 and 17 gets the names of each category and adds each of them to the select field. The first category that's found is also pre-selected.
</p>
<h2>Processing the add news form</h2>
<p>
The form used to insert news in the database needs to be processed. The script is pretty straightforward, especially because I've already shown basic SQL queries in JSP just above ( or in the previous article in the series ). The first line of the script that processes the form is the usual line that imports all required libraries. All the following lines up to line 18 are used to create and instantiate the resources required to perform different operations on the mySQL database. Here's the full code:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
&nbsp;
	String database = &quot;lab8&quot;;
	String user = &quot;root&quot;;
	String pass = &quot;thebeastlocal&quot;;
	String table = &quot;News&quot;;
&nbsp;
	String connectionURL = &quot;jdbc:mysql://localhost:3306/&quot;+database+&quot;?user=&quot;+user+&quot;;password=&quot;+pass;
	Connection connection = null;
	Statement statement = null;
	Statement update = null;
	ResultSet rs = null;
&nbsp;
	Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
	connection = DriverManager.getConnection(connectionURL,user,pass);
	statement = connection.createStatement();
&nbsp;
	if(session.getAttribute(&quot;loggedin&quot;)!=null)
	{
		String title = &quot;&quot;;
		String formcategory = &quot;&quot;;
		String body = &quot;&quot;;
		int error = 0;
&nbsp;
		if(request.getParameter(&quot;title&quot;)!=null) title = request.getParameter(&quot;title&quot;);
		else error = 1;
		if(request.getParameter(&quot;formcategory&quot;)!=null) formcategory = request.getParameter(&quot;formcategory&quot;);
		else error = 1;
		if(request.getParameter(&quot;body&quot;)!=null) body = request.getParameter(&quot;body&quot;);
		else error = 1;
&nbsp;
		if(error==1)
		{
			response.sendRedirect(&quot;index.jsp?error=Please input information in all fields&quot;);
		}
		else
		{
			String username = (String) session.getAttribute(&quot;username&quot;);
			try
			{
				String query = &quot;INSERT // INTO News(title,body,owner,publishing_date,publishing_time,category) VALUES('&quot;+title+&quot;','&quot;+body+&quot;','&quot;+username+&quot;',NOW(),NOW(),'&quot;+formcategory+&quot;')&quot;;
				// remove // between INSERT and INTO in above line
				statement.executeUpdate(query);				
			}
			catch (Exception e)
			{
				%&gt;&lt;%=e%&gt;&lt;%
			}
			response.sendRedirect(&quot;index.jsp?msg=News added to the system.&quot;);
		}
	}
	else response.sendRedirect(&quot;index.jsp?error=You must be logged in to access this feature.&quot;);
%&gt;</pre></td></tr></table></div>



<p>
Lines 20 and 54 in the above code check if the user trying to add a news to the database is logged in, as only logged in users are allowed to add items to the database. Lines 22 to 32 are used to initialize the variables which retain information users have inserted into the form fields on the previous page. On lines 34/36 errors are checked, and if any errors are found the users are redirected to the homepage of the web app and error messages are displayed. The code on line 40 gets the username of the person trying to add a news to the database as each news has an author and we need to know the info before inserting new items in the database. The <em>try catch</em> block between lines 41 and 50 is used to add the news to the database, or if any exceptions occur, catch and display them. If everything goes as planned the code on line 51 redirects users to the homepage and triggers a success message.
</p>
<p>That's all it takes to nicely add information to a database using Java Server Pages. If you enjoyed the article, you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in JSP</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 04:24:20 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1736</guid>
		<description><![CDATA[

About 5 months ago I started a series of tutorials which described the process of building a live news blogging system in php. When the series ended, I promised that another series will follow and will describe the process of building the same web app using JSP. This article is the first of its series, [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
About 5 months ago I started a series of tutorials which described the process of <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">building a live news blogging system in php</a>. When the series ended, I promised that another series will follow and will describe the process of building the same web app using JSP. This article is the first of its series, and contains the introductory part of what's needed in this tutorial series, as well as some basic JSP code.
</p>
<p>First of all, please read the first part of the original series <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-i/">here</a> as it describes and shows the source codes for the user interface of the web application, namely HTML5, CSS and some jQuery.</p>
<p>You should also check out the second part of the original tutorial <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-part-ii/">here</a>, as this part contains the database model and some more jQuery. There's also some bits of PHP, but those aren't mandatory for today's article.</p>
<h2>login.jsp page</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
&nbsp;
	String database = &quot;lab8&quot;;
	String user = &quot;user here&quot;;
	String pass = &quot;pass here&quot;;
	String table = &quot;Users&quot;;
&nbsp;
	String connectionURL = &quot;jdbc:mysql://localhost:3306/&quot;+database+&quot;?user=&quot;+user+&quot;;password=&quot;+pass;
	Connection connection = null;
	Statement statement = null;
	Statement update = null;
	ResultSet rs = null;
&nbsp;
	Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
	connection = DriverManager.getConnection(connectionURL,user,pass);
	statement = connection.createStatement();
&nbsp;
	String username = &quot;&quot;;
	String password = &quot;&quot;;
	int error = 0;
	if(request.getParameter(&quot;username&quot;)!=null) username = request.getParameter(&quot;username&quot;);
	else error = 1;
	if(request.getParameter(&quot;password&quot;)!=null) password = request.getParameter(&quot;password&quot;);
	else error = 1;
	if(error==1)
	{
		response.sendRedirect(&quot;index.jsp?error=Please input username and password&quot;);
	}
	else
	{
			MessageDigest mdAlgorithm = MessageDigest.getInstance(&quot;MD5&quot;);
			mdAlgorithm.update(password.getBytes());
&nbsp;
			byte[] digest = mdAlgorithm.digest();
			StringBuffer hexString = new StringBuffer();
&nbsp;
			for (int i = 0; i &lt; digest.length; i++) 
			{
			    password = Integer.toHexString(0xFF &amp; digest[i]);
&nbsp;
			    if (password.length() &lt; 2) 
				{
			        password = &quot;0&quot; + password;
			    }
&nbsp;
			    hexString.append(password);
			}
&nbsp;
			password = hexString.toString();
			String query = &quot;SELECT * FROM Users WHERE username='&quot;+username+&quot;' AND password='&quot;+password+&quot;'&quot;;
			rs = statement.executeQuery(query);
			if(rs.next())
			{
				session.setAttribute(&quot;loggedin&quot;,&quot;1&quot;);
				session.setAttribute(&quot;username&quot;,username);
&nbsp;
				response.sendRedirect(&quot;index.jsp?msg=Logged in succesfully.&quot;);
			}
			else 
			{
				response.sendRedirect(&quot;index.jsp?error=Invalid login data.&quot;);
			}
	}
%&gt;</pre></td></tr></table></div>



<p>The first line of the code above contains instructions to include different libraries that will be used throughout the entire jsp file. The following four lines of code are in fact the variables that will be used to store database connection settings. In the next set of lines we create the datatypes that we will use to create an sql connection, perform sql queries and handle the results returned by the queries. On lines 16 to 18 we instantiate the mysql driver and connect to the database.</p>
<p>The instructions between lines 20 and 30 test if the visitor has inputed his username and password information in the form that send him to the login page. If the user's hasn't filled in required information, the request is denied. Lines 33 to 50 are used to encrypt the password the user typed in the login form. Passwords in the database are encrypted to ensure that, even if third parties gain access to the database, the passwords aren't exposed.</p>
<p>
The following two lines make an SQL query to check if the user credentials are valid. If they are, lines 56 to 59 are used to create required login sessions and redirect the user to the homepage, while the code on line 63 redirects the user to the homepage after an invalid login.
</p>
<h2>logout.jsp</h2>
<p>The logout process is much more simple, and the following code snippet does the trick. This snippet also contains the imports found in the login.jsp file, one line of code that destroys the session and one that redirects the user to the homepage.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="jsp" style="font-family:monospace;">&lt;%@ page import=&quot;java.sql.*&quot; import=&quot;java.util.*&quot; session=&quot;true&quot; import=&quot;Javax.servlet.http.*&quot; import=&quot;java.security.*&quot; %&gt;
&nbsp;
&lt;%
	session.removeAttribute(&quot;loggedin&quot;);
	response.sendRedirect(&quot;index.jsp?msg=Successfully logged out&quot;);
%&gt;</pre></td></tr></table></div>



<p>
While the php application also contained a functions.php file, this does not. Having that said, this is the end of the first part of the tutorial. You can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-jsp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Build a POI map using jQuery &amp; Google Maps v3</title>
		<link>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/</link>
		<comments>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 15:26:51 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[geolocation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[poi]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1706</guid>
		<description><![CDATA[UPDATE 09.09.10: This tutorial doesn't describe how to show in the same time multiple POIs on the map. If you wish a tutorial on how to display multiple POI on the map in the same time, read the revised version of the tutorial.

This is the incipient work from a bigger project that I worked on [...]]]></description>
			<content:encoded><![CDATA[<p>UPDATE 09.09.10: This tutorial doesn't describe how to show in the same time multiple POIs on the map. If you wish a tutorial on how to display multiple POI on the map in the same time, read the <a href="http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3-revised/">revised version of the tutorial</a>.</p>
<p>
This is the incipient work from a bigger project that I worked on which uses Google Maps. I decided to share it with you as it can be used in a variety of ways and places. You can use it to locate around a map your company's offices, stores, museums or any other interest points you need to present to your website's visitors.
</p>
<p>
The tutorial is fairly simple as it doesn't include advanced programming or CSS rules. Having that said, here's a screenshot of the final product.
</p>

<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/08/office_location.png" title="Tutorial preview"><img src="http://www.webia.info/wp-content/uploads/2010/08/office_location_small.jpg" alt="Tutorial preview" /></a></p>

<p>
As you can see the application, if I can call it that way, has a sidebar that contains a list of POIs (Point of Interest), a diagnosis header that displays information about what's going on and a map. Let's code the HTML structure:
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;home-wrapper&quot;&gt;
	&lt;div id=&quot;logo&quot;&gt;
		&lt;a href=&quot;http://www.webraptor.eu&quot; target=&quot;_self&quot;&gt;&lt;img src=&quot;logo.jpg&quot; width=&quot;245&quot; height=&quot;40&quot; alt=&quot;WebRaptor&quot; /&gt;&lt;/a&gt;
	&lt;/div&gt;
	&lt;div id=&quot;home-messages&quot;&gt;
		Trying to determine your location...Please allow browser to share location if prompted
	&lt;/div&gt;
	&lt;span class=&quot;clear&quot;&gt;&amp;nbsp;&lt;/span&gt;
	&lt;div id=&quot;home-sidebar&quot;&gt;
		&lt;h1&gt;Our offices locations&lt;/h1&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;40.453577,-3.68763, 
			&lt;strong&gt;Venue: &lt;/strong&gt;Estadio Santiago Bernabeu&lt;br /&gt;
			&lt;strong&gt;Address: &lt;/strong&gt;Avenida de Concha Espina; No 1; 28036; Madrid&lt;br /&gt;
			&lt;strong&gt;Phone: &lt;/strong&gt;+34 (91) 398 4300&lt;br /&gt;
			&lt;strong&gt;Fax: &lt;/strong&gt;+34 (91) 344 0695&lt;br /&gt;
			&lt;strong&gt;Email: &lt;/strong&gt;&lt;a href='mailto:realmadrid@club.realmadrid.com'&gt;realmadrid@club.realmadrid.com&lt;/a&gt;&lt;br /&gt;
			&quot; target=&quot;_self&quot;&gt;Estadio Santiago Bernabeu&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href=&quot;#&quot; rel=&quot;41.934115,12.45575, 
			&lt;strong&gt;Venue: &lt;/strong&gt;Stadio Olimpico&lt;br /&gt;
			&lt;strong&gt;Address: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Phone: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Fax: &lt;/strong&gt;&lt;br /&gt;
			&lt;strong&gt;Email: &lt;/strong&gt;&lt;a href='mailto:'&gt;&lt;/a&gt;&lt;br /&gt;
			&quot; target=&quot;_self&quot;&gt;Stadio Olimpico - Rome&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
&nbsp;
	&lt;div id=&quot;map-wrapper&quot;&gt;
		&lt;div id=&quot;map&quot;&gt;
&nbsp;
		&lt;/div&gt;	
	&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>




<p>
The role of the <em>home-wrapper</em> div is to hold the contents of the page centered in the browser window. The <em>home-messages</em> div is the one that holds the diagnosis messages in place, the <em>home-sidebar</em> div holds the POIs list while <em>map-wrapper</em> and <em>map</em> serve as a map placeholder.
</p>
<p>
As you can see, the <em>li</em> items inside the unordered list located in the sidebar contain all information that's provided for each point of interest. No external files or database queries are used. The information is contained within a <em>rel</em> attribute of the anchor tag that's inserted in each <em>li</em> item.
</p>
<p>
The above HTML code is to be placed inside the body of the page, while the following into the header, as it contains links to CSS files and javascript pointers.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;css.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; title=&quot;no title&quot; charset=&quot;utf-8&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi?key={APIKEY}&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	google.load(&quot;jquery&quot;, &quot;1.4.2&quot;);	  
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://maps.google.com/maps/api/js?sensor=true&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/OfficeLocation.js&quot; type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>



<p>
The CSS file isn't complicated at all.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
body		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Geneva</span><span style="color: #00AA00;">,</span> “Lucida Sans”<span style="color: #00AA00;">,</span> “Lucida Grande”<span style="color: #00AA00;">,</span> “Lucida Sans Unicode”<span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">62.5</span>%</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.clear</span> 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#logo</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">245px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-wrapper</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">930px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-messages</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">25px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#home-sidebar</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">243px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span> <span style="color: #933;">25px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#map-wrapper</span>		<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#map</span>			<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">645px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>	
<span style="color: #cc00cc;">#infowin-overlay</span>	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">80px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#infowin-overlay</span> strong	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
h1	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EEEEBB</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#339933</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
li a	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>



<p>
What's new in the CSS file is the <em>infowin-overlay</em> identifier used, which is nowhere to be found in our HTML file. That's due to the fact that it is the identifier of the overlay window that is displayed once a visitor clicks a POIs marker on the map. The overlay is added to the DOM by the javascript code that follows, which contains all that's required for the tutorial to be complete and working at warp speed.
</p>

<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/08/office_location_overlay.jpg" title="Map overlay preview"><img src="http://www.webia.info/wp-content/uploads/2010/08/office_location_overlay.jpg" alt="Map overlay preview" /></a></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> map<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// global var to store the google map</span>
<span style="color: #003366; font-weight: bold;">var</span> centerCoord <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">46.782101</span><span style="color: #339933;">,</span><span style="color: #CC0000;">23.643855</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// tulghesului street, Cluj-Napoca</span>
<span style="color: #003366; font-weight: bold;">var</span> centerCoord <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">40.453577</span><span style="color: #339933;">,-</span><span style="color: #CC0000;">3.68763</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Estadio Santiago Bernabeu, Madrid</span>
<span style="color: #003366; font-weight: bold;">var</span> browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// global variables used throughout the js functionality</span>
<span style="color: #003366; font-weight: bold;">var</span> markersArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> infoWindow <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">InfoWindow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> setLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// try to get user location via W3C standard Geolocation in browsers or via Google Gears</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
	    navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			blueIcon <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png&quot;</span><span style="color: #339933;">;</span>
			browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">,</span>position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>browserDetectedLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			      position<span style="color: #339933;">:</span> browserDetectedLocation<span style="color: #339933;">,</span> 
			      map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span> 
			      title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'You are here'</span><span style="color: #339933;">,</span>
			 	  icon<span style="color: #339933;">:</span> blueIcon
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Location detected. Please wait...&quot;</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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	     <span style="color: #006600; font-style: italic;">// error getting location, though supported</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be detected.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>google.<span style="color: #660066;">gears</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #006600; font-style: italic;">// if location not found using W3C standard try with Google Gears if browser supports it</span>
	<span style="color: #009900;">&#123;</span>
	    <span style="color: #003366; font-weight: bold;">var</span> geo <span style="color: #339933;">=</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beta.geolocation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    geo.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			blueIcon <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png&quot;</span><span style="color: #339933;">;</span>
			browserDetectedLocation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>position.<span style="color: #660066;">latitude</span><span style="color: #339933;">,</span>position.<span style="color: #660066;">longitude</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>browserDetectedLocation<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			      position<span style="color: #339933;">:</span> browserDetectedLocation<span style="color: #339933;">,</span> 
			      map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span> 
			      title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'You are here'</span><span style="color: #339933;">,</span>
				  icon<span style="color: #339933;">:</span> blueIcon
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Location detected. Please wait...&quot;</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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// error getting location, though supported</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be found.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #000066; font-weight: bold;">else</span>	
	<span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Browser doesn't support Geolocation</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Your location cannot be found.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> InitMap<span style="color: #009900;">&#40;</span>options<span style="color: #339933;">,</span> mapIdentifier<span style="color: #339933;">,</span> defaultLocation<span style="color: #339933;">,</span> detectLocation<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// function to initialize map</span>
	<span style="color: #003366; font-weight: bold;">var</span> settings <span style="color: #339933;">=</span> <span style="color: #006600; font-style: italic;">// json variable for default settings</span>
	<span style="color: #009900;">&#123;</span>
		zoom<span style="color: #339933;">:</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">,</span>
		center<span style="color: #339933;">:</span> defaultLocation<span style="color: #339933;">,</span>
		mapTypeId<span style="color: #339933;">:</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">MapTypeId</span>.<span style="color: #660066;">SATELLITE</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>options<span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> settings <span style="color: #339933;">=</span> options<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// if no options provided, start the map with default settings</span>
	map <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Map</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>mapIdentifier<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>defaultLocation<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>detectLocation<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> setLocation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// try to get user location via W3C standard Geolocation in browsers or via Google Gears</span>
	<span style="color: #000066; font-weight: bold;">else</span>
	<span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Click an office on the left to view its location.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> map<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> handle_clicks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-sidebar ul li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		clearOverlays<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordString <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rel'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordTitle <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> coordArray <span style="color: #339933;">=</span> coordString.<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>
		<span style="color: #003366; font-weight: bold;">var</span> update2Location <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">LatLng</span><span style="color: #009900;">&#40;</span>coordArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>coordArray<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>
		map.<span style="color: #660066;">setCenter</span><span style="color: #009900;">&#40;</span>update2Location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		addMarker<span style="color: #009900;">&#40;</span>update2Location<span style="color: #339933;">,</span>coordTitle<span style="color: #339933;">,</span>coordArray<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#home-messages'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Viewing: &quot;</span><span style="color: #339933;">+</span>coordTitle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addMarker<span style="color: #009900;">&#40;</span>m_position<span style="color: #339933;">,</span>m_title<span style="color: #339933;">,</span>m_infowindow<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	marker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">Marker</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	  	position<span style="color: #339933;">:</span> m_position<span style="color: #339933;">,</span>
	  	map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span> m_title
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #003366; font-weight: bold;">var</span> mark <span style="color: #339933;">=</span> markersArray.<span style="color: #660066;">pop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	google.<span style="color: #660066;">maps</span>.<span style="color: #660066;">event</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>mark<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		infoWindow.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> stringContent <span style="color: #339933;">=</span> m_infowindow<span style="color: #339933;">;</span>
		infoWindow.<span style="color: #660066;">setContent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;div id=<span style="color: #000099; font-weight: bold;">\&quot;</span>infowin-overlay<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">+</span>stringContent<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/div&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		overlayHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		overlayWidth <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span>overlayHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#infowin-overlay'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span>overlayWidth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	markersArray.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> clearOverlays<span style="color: #009900;">&#40;</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>markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #000066; font-weight: bold;">in</span> markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      markersArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">setMap</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009966; font-style: italic;">/* end of functions */</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#map'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// only initialize the map if map is located inside the page</span>
		map <span style="color: #339933;">=</span> InitMap<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'map'</span><span style="color: #339933;">,</span> centerCoord<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// initialize the map on default location</span>
		handle_clicks<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// click events handling by jQuery	</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
I've added comments to the most important lines of jQuery above. The <em>setLocation()</em> function tries to detect user location and center the map around his location. The <em>InitMap()</em> function is used to get the entire thing rolling, and takes a couple of arguments that allows you to set the default location displayed when the map loads, as well as to enable or disable user location tracking.
</p>
<p>
The <em>handle_clicks()</em> function is used to track clicks on the items contained in the sidebar list and move the map around on top of the clicked point of interest. <em>addMarker()</em> is used to add a marker to the map, marker which represents the location of a POI and which users can click to have a detailed overlay displayed. Finally, clear_overlays() clears existing overlays to avoid duplicated content.
</p>
<h2>Demo</h2>
<p>I've prepared a demo of the tutorial over <a href="http://demos.webia.info/map_demo/map.html">here</a>.</p>
<p>If you enjoyed this article you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.</p>	]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/jquery-articles/build-a-poi-map-using-jquery-google-maps-v3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Building a live news blogging system in php. Spiced with HTML5, CSS3 and jQuery [sources]</title>
		<link>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/</link>
		<comments>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 08:00:47 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[live news system]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1701</guid>
		<description><![CDATA[

About a month ago the huge tutorial on building a live news blogging system was completed. Today I am releasing the source codes of the tutorial so that you can finally play with the web application however you like.

Demo

You can check out the demo part of the tutorial before you download the source code. Furthermore, [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2010/03/lns_preview_full.jpg" title="Tutorial app preview"><img src="http://www.webia.info/wp-content/uploads/2010/03/lnw_preview.jpg" alt="Tutorial app preview" /></a></p>
<p>
About a month ago the huge tutorial on building a live news blogging system was completed. Today I am releasing the source codes of the tutorial so that you can finally play with the web application however you like.
</p>
<h2>Demo</h2>
<p>
You can check out the <a href="http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-demo/">demo part of the tutorial</a> before you download the source code. Furthermore, a demo of the application is available <a href="http://demos.webia.info/news_system">over here</a>.
</p>
<h2>Source code</h2>
<p>
The full source code of the tutorial is available for download <a href="http://demos.webia.info/news_system/LiveNewsSystem.zip">over here</a>.
</p>
<p>
If you liked this tutorial series, stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>, because a new series will start soon. This new series will be around coding the same webapp using JSP on Tomcat.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/tutorials/building-a-live-news-blogging-system-in-php-spiced-with-html5-css3-and-jquery-sources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

