<?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>Script Tutorials &#187; HTML/CSS | Script Tutorials | Web development</title> <atom:link href="http://www.script-tutorials.com/category/html-css/feed/" rel="self" type="application/rss+xml" /><link>http://www.script-tutorials.com</link> <description>Tutorials for Web Developers</description> <lastBuildDate>Fri, 03 Feb 2012 06:07:51 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Form Validation with Javascript and PHP</title><link>http://www.script-tutorials.com/form-validation-with-javascript-and-php/</link> <comments>http://www.script-tutorials.com/form-validation-with-javascript-and-php/#comments</comments> <pubDate>Wed, 01 Feb 2012 19:17:47 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[forms]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[validation]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1403</guid> <description><![CDATA[Form Validation with Javascript and PHP In this tutorial, I will show you how to create an attractive, pleasant to look form for your website and then I will explain you how to dynamically validate them using Javascript. We&#8217;ll also cover server-side validation with PHP to make everything 100% safe. This tutorial will help you [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/data-validation-html5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/49.png" alt="Data Validation &#8211; How to Validate Forms using HTML5" /> Data Validation &#8211; How to Validate Forms using HTML5</a></li><li> <a
href="http://www.script-tutorials.com/animated-photo-gallery-grid-with-javascript/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/54/thumb.png" alt="Animated Photo Gallery (grid) with javascript" /> Animated Photo Gallery (grid) with javascript</a></li><li> <a
href="http://www.script-tutorials.com/cross-browser-effect-of-waves-using-javascript/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/81/thumb.png" alt="Creating Cross-browser Compatible Wave Effects Using Javascript" /> Creating Cross-browser Compatible Wave Effects Using Javascript</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Form Validation with Javascript and PHP" alt="Form Validation with Javascript and PHP" src="http://www.script-tutorials.com/demos/228/thumb.png"></div><p><strong>Form Validation with Javascript and PHP</strong><br
/> <br
/>In this tutorial, I will show you how to create an attractive, pleasant to look form for your website and then I will explain you how to dynamically validate them using Javascript. We&#8217;ll also cover server-side validation with PHP to make everything 100% safe. This tutorial will help you to add more functionality to your forms which leads to better user experience and better quality of your website. You may also enhance your already existing forms by adding them some fancy effects presented in this tutorial. Let&#8217;s get started! Info: If you&#8217;d like to modify already existing form by adding some javascript to it then skip HTML and CSS part of this tutorial and go to step five. Otherwise, if you&#8217;re planning to create new form start reading here.<br
/> <span
id="more-1403"></span></p><h3>Concept</h3><p>Let&#8217;s start with some brief explanation of what are we going to do. I&#8217;m sure that you&#8217;ve seen lots of different forms and I&#8217;m sure that filling in some of them was a lot more comfortable than filling in the other ones. I&#8217;m sure that this was caused in large part by some additional scripts. We&#8217;re going to cover a few field types including standard input field, password field, repeat password field, email field, options list and a few different scripts so I&#8217;m sure that you&#8217;ll find here something useful for you. Here are a few more things to consider while creating forms:</p><ul><li>Make sure that your form is as short as possible. People don&#8217;t like wasting time on filling in complex forms. They are likely to leave the page before they take any action. It&#8217;s better to ask for less important information after user is already registered (preferably only when you really need that information).</li><li>We want it to look neat and clean.</li><li>We want it to work seamlessly and without any strange behavior or errors.</li><li>We want to reduce number of fake submissions.</li></ul><h5 style="text-align: center;"><strong><a
title="Form Validation with Javascript and PHP - demo 228" href="http://www.script-tutorials.com/demos/228/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Form Validation with Javascript and PHP - package" href="http://www.script-tutorials.com/demos/228/source.zip" target="_blank">download in package</a></strong></h5><hr
/><h3>Project</h3><p>We&#8217;re going to start with HTML and then improve it with styles and scripts. At the end we&#8217;re going to I&#8217;m going to use the following fields in my form (numbers of allowed chars are in the brackets):</p><ul><li>Name (25)</li><li>Password (25)</li><li>Password Confirmation (25)</li><li>Email (50)</li><li>Gender (boolean)</li></ul><p>This is mine schedule. I found the best way to make each part of web is to start with HTML and then improve it by adding some style and scripts but you can actually start with preparing database (you can have your own DB table structure) or PHP script (step 12) and then take care of the rest pieces. Tip: You can increase maximum size of your text fields if you really need it but honestly I think values I chose are good enough.</p><h3>Step 1 &#8211; HTML Forms</h3><p>Lets prepare new folder &#8216;templates&#8217;, where we will put all our templates. Create a new document and name it main_page.html. Now we&#8217;re going to create HTML form and place it there. As you can see below there are some comments referring to each part of my code so I believe that at this point additional explanations are superfluous. I have also created a HTML table to align all the information. Here&#8217;s the code:</p><h4>templates/main_page.html</h4><pre class="brush:html">
&lt;form action=&quot;index.php&quot; method=&quot;post&quot; id=&quot;form&quot; onsubmit=&quot;return validate_all('results');&quot;&gt;
    &lt;table cellspacing=&quot;10&quot;&gt;
        &lt;tr&gt;&lt;td&gt;Login&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;login&quot; maxlength=&quot;25&quot; id=&quot;login&quot; onKeyUp=&quot;updatelength('login', 'login_length')&quot;&gt;&lt;br /&gt;&lt;div id=&quot;login_length&quot;&gt;&lt;/div&gt; &lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Password&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;pass&quot; maxlength=&quot;25&quot; id=&quot;password&quot; onKeyUp=&quot;updatelength('password', 'pass_length')&quot;&gt;&lt;div id=&quot;pass_result&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id=&quot;pass_length&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Confirm Password&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;cpass&quot; maxlength=&quot;25&quot; id=&quot;c_password&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Gender&lt;/td&gt;&lt;td&gt;&lt;select name=&quot;gender&quot;&gt;&lt;option value=&quot;1&quot;&gt;male&lt;/option&gt;&lt;option value=&quot;0&quot;&gt;female&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;Email&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; maxlength=&quot;50&quot; id=&quot;email&quot; onKeyUp=&quot;updatelength('email', 'email_length')&quot;&gt;&lt;br /&gt;&lt;div id=&quot;email_length&quot;&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Register&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
    &lt;h3 id=&quot;results&quot;&gt;&lt;/h3&gt;
&lt;/form&gt;
</pre><p>Things to note:</p><ul><li>Don&#8217;t forget to name your text fields, otherwise you won&#8217;t be able to receive data from them later on.</li><li>Maxlength parameter reduces number of characters you can use in each text field.</li><li>Action, method and id parameters are required so place them into form tag.</li><li>You can make table border visible by placing border=&#8221;1&#8243; in table tag if you want to actually see the table.</li></ul><p>Here&#8217;s the code of second page:</p><h4>templates/step2.html</h4><pre class="brush:html">
&lt;h2&gt;{errors}&lt;/h2&gt;
&lt;form action=&quot;index.php&quot; method=&quot;post&quot;&gt;
    &lt;table cellspacing=&quot;10&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;login&quot; value=&quot;{login}&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;pass&quot; value=&quot;{pass}&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;cpass&quot; value=&quot;{cpass}&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;gender&quot; value=&quot;{gender}&quot;&gt;
        &lt;input type=&quot;hidden&quot; name=&quot;email&quot; value=&quot;{email}&quot;&gt;
        &lt;tr&gt;&lt;td&gt;&lt;span&gt;Verification code&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;input name=&quot;vcode&quot;&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td&gt;&lt;span&gt;Hint&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;i&gt;{vcode}&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Register&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
&lt;/form&gt;
</pre><p>And &#8211; last one page:</p><h4>templates/step3.html</h4><pre class="brush:html">
&lt;h1&gt;Registration complete&lt;/h1&gt;
</pre><h3>Step 2 &#8211; Adding CSS</h3><p>Now we have our HTML form but it does not look attractively yet. As you may have guessed it is time to add some CSS and make our form look a little better. Here is my example of green form definitions:</p><h4>css/main.css</h4><pre class="brush:css">
form {
    background-color: #555;
    display: block;
    padding: 15px;
}
input[type=text], input[type=password], input[type=submit] {
    -moz-border-radius: 2px;
    -ms-border-radius: 2px;
    -o-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
}
input[type=text], input[type=password], select {
    background-color: rgb(246, 254, 231);
    border-color: rgb(180, 207, 94);
    border-style: solid;
    border-width: 1px;
    font-size: 16px;
    height: 25px;
    margin-right: 10px;
    width: 200px;
}
input[type=submit]{
    cursor: pointer;
    font-size: 16px;
    height: 35px;
    padding: 5px;
}
input.wrong {
    border-color: rgb(180, 207, 94);
    background-color: rgb(255, 183, 183);
}
input.correct {
    border-color: rgb(180, 207, 94);
    background-color: rgb(220, 251, 164);
}
#pass_result {
    float: right;
}
</pre><p>Classes are named according to their further function. For example <b>.wrong</b> class will be used when text field contains wrong informations and so on. Also you should now add class parameter to each text field and elements that should have some style. To do it place <b>class=&#8221;class_name_here&#8221;</b> to <b>input</b> tags where <b>class_name_here</b> is name of class defined between <b>style</b> tags (see example if you are new to adding classes to elements). Add only <b>field</b> class to each text field, rest will be used later. I advise to modify styles a little by choosing different colors and values so that they could fulfill your requirements.</p><h3>Step 3 &#8211; Javascript</h3><p>This step will be about dynamic elements and how to use Javascript to create and then apply them wherever you would like to. After observing what some sites do I&#8217;ve noticed that there are plenty of such scripts (which I&#8217;m going to present here) recently, especially on big companies/corporations sites and popular services so I think this really make users happier and encourage them to fill forms in. Look around and check out some sign up forms (Google.com, Yahoo.com and flickr.com, ebay.com&#8230; yes, dynamic forms are almost everywhere now). Some easy to do scripts can reduce number of unnecessary clicks and let users create account (or whatever you are making form for) more quickly than before, not to mention they look much more prettily and cool. There are various places to put the javascript code as it was with CSS. It can either be written inside the <b>main_page.html</b> file using a tag or put to the other file and then include this file to <b>main_page.html</b>. Both case will use the same code to put scripts to your document. I chose second option so make separated script file (js/script.js) for our <b>main_page.html</b> file.</p><p>Each function from further steps should be placed where I made comment so between.</p><h3>Step 4 &#8211; Applying functions</h3><p>This is very important step so read it carefully. Adding javascript functions to your HTML form elements should be easy because it is very similar to adding CSS classes to them. Also to make it easier I tried to create functions from further steps alike to each other so that you can apply them almost the same way but for sure I will add some sample files each step to show you how it is made and I will write a little explanation to them. Generally if you want to add function (let&#8217;s say <b>updatelength()</b> from <b>Step 7 &#8211; Counter</b>) to <b>login</b> field you should replace:</p><pre class="brush:html">
    &lt;input type=&quot;text&quot; name=&quot;login&quot; maxlength=&quot;25&quot; id=&quot;login&quot;&gt;
</pre><p>with:</p><pre class="brush:html">
    &lt;input type=&quot;text&quot; name=&quot;login&quot; maxlength=&quot;25&quot; id=&quot;login&quot; onKeyUp=&quot;updatelength('login', 'login_length')&quot;&gt;&lt;br /&gt;&lt;div id=&quot;login_length&quot;&gt;&lt;/div&gt;
</pre><p>The only thing that has changed is <b>onKeyUp=&#8221;updatelength(&#8216;logid&#8217;, &#8216;login_length&#8217;)&#8221;</b> was added. Well, if we add something like this to our <b>input</b> we will observe what function is returning outcome in <b>div</b> tag with id &#8220;login_length&#8221;.</p><p><b>Why?</b></p><p>Because <b>updatelength()</b> function starts like this <b>&#8220;function updatelength(field, output){&#8230;&#8221;</b> (Step 7 &#8211; Counter) and that means it requires two arguments which are <b>ID OF TEXT FIELD IN HTML</b> and <b>ID OF DIV WHERE RESULT WILL BE</b>. Now it is easy, isn&#8217;t it? <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Rest of functions are similar to this one so I hope it won&#8217;t be a problem to apply it. Each one needs almost same values as arguments.<br
/> Notes:</p><ul><li>You can use more than one function to one text field by using a separator &#8220;;&#8221;. Example: <b>onKeyUp=&#8221;updatelength(&#8216;logid&#8217;, &#8216;login_length&#8217;); valid_length(&#8216;logid&#8217;, &#8216;login_o&#8217;);&#8221;</b></li><li>Look up to the source of example sites if you have any problems.</li></ul><h3>Step 5 &#8211; Counter</h3><p>So, here goes first script to improve our sign up form. It can be used in many other cases like adding a comment or posting message somewhere so you can attach it to more than one form. It will count characters we typed and tells us how many more we can write to the end of field. Short code and useful thing:</p><pre class="brush:js">
function updatelength(field, output){
    curr_length = document.getElementById(field).value.length;
    field_mlen = document.getElementById(field).maxLength;
    document.getElementById(output).innerHTML = curr_length+'/'+field_mlen;
    return 1;
}
</pre><p>Once you have placed it, you can run it using method presented in previous step (also there is example of usage described). This script checks how many characters did you use (each time you use one) and how many are allowed by text field&#8217;s <b>maxlength</b> parameter, then it changes value between the div tags. There are 2 variables called <b>&#8216;curr_length&#8217;</b> and <b>&#8216;field_mlen&#8217;</b>. First one gets and store number of characters you&#8217;ve typed (as I already wrote each time you type something in the field) and second one stores value of maxlength parameter of the field on which you are using this function. Then it simply shows both values with &#8216;/&#8217; separator in the middle. Note:</p><ul><li>I applied this script to every field</li></ul><h3>Step 6 &#8211; Password Strength</h3><p>Now it will be something which will check for how strong the password is. Scripts like this are usually not very extended so here is the basic version of it:</p><pre class="brush:js">
function check_v_pass(field, output) {
    pass_buf_value = document.getElementById(field).value;
    pass_level = 0;
    if (pass_buf_value.match(/[a-z]/g)) {
        pass_level++;
    }
    if (pass_buf_value.match(/[A-Z]/g)) {
        pass_level++;
    }
    if (pass_buf_value.match(/[0-9]/g)) {
        pass_level++;
    }
    if (pass_buf_value.length &lt; 5) {
        if(pass_level &gt;= 1) pass_level--;
    } else if (pass_buf_value.length &gt;= 20) {
        pass_level++;
    }
    output_val = '';
    switch (pass_level) {
        case 1: output_val='Weak'; break;
        case 2: output_val='Normal'; break;
        case 3: output_val='Strong'; break;
        case 4: output_val='Very strong'; break;
        default: output_val='Very weak'; break;
    }
    if (document.getElementById(output).value != pass_level) {
        document.getElementById(output).value = pass_level;
        document.getElementById(output).innerHTML = output_val;
    }
    return 1;
}
</pre><p>As a <b>&#8216;field&#8217;</b> argument we should put an ID of field to check and in <b>&#8216;output&#8217;</b> goes place where the result will be shown. Of course DON&#8217;T TYPE IT HERE but when you are using this function (here you are only creating it) so replace values only when you write <b>OnKeyUp=&quot;&#8230;</b> in your input <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Function also here contains two variables. First one called <b>&#8216;pass_level&#8217;</b> contains current password strength and it is set to 0 by default because password field is empty at the beginning. Second variable named <b>&#8216;pass_buf_value&#8217;</b> contains current value of your password field. Below those two you can see some if()-s, they are looking for some characters that may increase password strength level and if one of them find anything it updates value of <b>&#8216;pass_level&#8217;</b> variable by adding 1 to it. Of course rest of the script returns proper informations, it chooses right text depending on current <b>&#8216;pass_level&#8217;</b> value. Apply this script to your password field.</p><h3>Step 7 &#8211; Comparing passwords</h3><p>Third script compare value from password field with value from confirm password field to make user sure, he typed exactly what he wanted. Characters here are not visible so to check if user did not make any mistakes we need two different fields and both has to contain same values when typing, only then form is filled correctly:</p><pre class="brush:js">
function compare_valid(field, field2) {
    fld_val = document.getElementById(field).value;
    fld2_val = document.getElementById(field2).value;
    if (fld_val == fld2_val) {
        update_css_class(field2, 2);
        p_valid_r = 1;
    } else {
        update_css_class(field2, 1);
        p_valid_r = 0;
    }
    return p_valid_r;
}
</pre><p>Guess how to use it? Only tip I will give you is that you should use it only on the <b>compare password field</b> and nowhere else. Well, this script as you can see arrogates values of 2 fields to two different variables called <b>&#8216;fld_val&#8217;</b> and <b>&#8216;fld2_val&#8217;</b>. There is an if() construction below them which compares those two values and changes between 2 versions of style (green when everything is good and red when there are any errors).</p><h3>Step 8 &#8211; Email verification</h3><p>A bit more complicated script but usage is easy as always. Every email address must fulfill following criteria:<br
/> 1. Must have some characters at the beginning (letters or numbers (and some less important))<br
/> 2. Must have @ (at) character<br
/> 3. Must have domain name<br
/> a) Must have first word<br
/> b) Must have . (dot) character<br
/> c) Must have second word<br
/> 4. And in the event that somebody believe his email address contains big letters it must convert characters to small ones</p><pre class="brush:js">
function check_v_mail(field) {
    fld_value = document.getElementById(field).value;
    is_m_valid = 0;
    if (fld_value.indexOf('@') &gt;= 1) {
        m_valid_dom = fld_value.substr(fld_value.indexOf('@')+1);
        if (m_valid_dom.indexOf('@') == -1) {
            if (m_valid_dom.indexOf('.') &gt;= 1) {
                m_valid_dom_e = m_valid_dom.substr(m_valid_dom.indexOf('.')+1);
                if (m_valid_dom_e.length &gt;= 1) {
                    is_m_valid = 1;
                }
            }
        }
    }
    if (is_m_valid) {
        update_css_class(field, 2);
        m_valid_r = 1;
    } else {
        update_css_class(field, 1);
        m_valid_r = 0;
    }
    return m_valid_r;
}
</pre><p>Place <b>OnKeyUp=&quot;&#8230;</b> into <b>input</b> tag where email address is and create new <b>div</b> with adequate ID to make it work. This function basically looks up if the email address is typed correctly. First it arrogates value of the field to <b>&#8216;fld_value&#8217;</b> variable to work with it. Everything is supervised by 4 if() constructions. They are step by step checking if there is @ symbol (1), then if it is on the second or further position (2). At the end if there is &quot;dot&quot; character after @ symbol (3) and finally if there are any characters before and after this &quot;dot&quot; (4). If any of if()-a find error it stops script and switches to red style wrong style of field. Those if()-s are a bit complicated as you can see but finally result is same as always, it chooses between green and red style and then shows it. Second part of this script is similar to switching between two options in already explained part so it should be clear for now.</p><h3>Step 9 &#8211; Empty fields</h3><p>Short function checking if there is more than 0 characters in our inputs. If there are empty spaces somewhere we can&#8217;t create new account:</p><pre class="brush:js">
function valid_length(field) {
    length_df = document.getElementById(field).value.length;
    if (length_df &gt;= 1 &amp;&amp; length_df &lt;= document.getElementById(field).maxLength) {
        update_css_class(field, 2);
        ret_len = 1;
    } else {
        update_css_class(field, 1);
        ret_len = 0;
    }
    return ret_len;
}
</pre><p>Like usually here also we have to give a text field ID and ID of div where result of script should be as an arguments. Add this script to each field (except gender one). This one has only one interesting part to explain because rest should be clear for you already. I&#8217;m talking about this long if() construction in the third line. It first checks if value of the field has at least one character and than in its second part if it has no more than &#8216;max number&#8217; of characters. Then it just changes between two options &#8211; right and wrong.</p><h3>Step 10 &#8211; Coloring</h3><p>This one is very short and only changes mode between two classes to make better visual effects. Classes must be defined in our CSS part of document (they are if you copied definitions from step 4). I called them <b>wrong</b> and <b>correct</b>:</p><pre class="brush:js">
function update_css_class(field, class_index) {
    if (class_index == 1) {
        class_s = 'wrong';
    } else if (class_index == 2) {
        class_s = 'correct';
    }
    document.getElementById(field).className = class_s;
    return 1;
}
</pre><p>As you may have already noticed this function is ran by other ones. Previous and further scripts puts arguments here. First argument is an ID of field you are currently working with and second is number 1 or 2. This numbers are being changed depending on actual field status to let then change its style to correct one. Let&#8217;s continue to next step.</p><h3>Step 11 &#8211; Last Javascript verification</h3><p>This is the last script using javascript. It calls out every function once more for sure and returns encountered errors or allows us to continue. It does not require refreshing whole page but check form quickly after pressing &quot;Register&quot;. That&#8217;s very important script and other ones were mostly make to let this one work:</p><pre class="brush:js">
function validate_all(output) {
    t1 = valid_length('login');
    t2 = valid_length('password');
    t3 = compare_valid('password', 'c_password');
    t4 = check_v_mail('email');
    t5 = check_v_pass('password', 'pass_result');

    errorlist = '';
    if (! t1) {
        errorlist += 'Login is too short/long&lt;br /&gt;';
    }
    if (! t2) {
        errorlist += 'Password is too short/long&lt;br /&gt;';
    }
    if (! t3) {
        errorlist += 'Passwords are not the same&lt;br /&gt;';
    }
    if (! t4) {
        errorlist += 'Mail is wrong&lt;br /&gt;';
    }
    if (errorlist) {
        document.getElementById(output).innerHTML = errorlist;
        return false;
    }
    return true;
}
</pre><p>This script to work must be added to your submission form. And don&#8217;t forget to put <b>div</b> tag with &#8216;results&#8217; id somewhere so that there outcome could go (in my case it is at the bottom of form so below just made &#8216;button&#8217;). Once you press new button this function recalls other functions from previous steps and checks once more for any mistakes for sure. If everything is fine it let you create account but if something is wrong it shows errors there where you&#8217;ve placed your <b>&#8216;div&#8217;</b> with <b>&#8216;results&#8217;</b> ID. Also in this script you can define your own error messages.</p><h3>Step 12 &#8211; Final verification</h3><p>From now it will be mostly about PHP (and MySQL) so if you don&#8217;t want to make such a form on you website you can just leave it and use methods I showed in other situations <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Otherwise if you would like to store account data using MySQL database continue reading.<br
/> Javascript actually doesn&#8217;t protect our database from anything, it only makes people lifes easier <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> If we want to be sure that filled form is 100% correct we must use PHP verification before we can add anything to our database &#8211; that is because if somebody will turn javascript off still he can write whatever he want while creating account and this may make database errors occurs. To add some very simply PHP script create index.php file which will be launched after pressing &quot;Register&quot; button. Well, here&#8217;s the code you should put to your index.php file:</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

// set error reporting level
if (version_compare(phpversion(), '5.3.0', '&gt;=') == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
else
  error_reporting(E_ALL &amp; ~E_NOTICE);

session_start();
if (isset($_POST['submit'])) {

    $sLogin = escape($_POST['login']);
    $sPass = escape($_POST['pass']);
    $sCPass = escape($_POST['cpass']);
    $sEmail = escape($_POST['email']);
    $iGender = (int)$_POST['gender'];

    $sErrors = '';
    if (strlen($sLogin) &gt;= 1 and strlen($sLogin) &lt;= 25) {
        if (strlen($sPass) &gt;= 1 and strlen($sPass) &lt;= 25) {
            if (strlen($sEmail) &gt;= 1 and strlen($sEmail) &lt;= 55) {
                if ($sPass == $sCPass) {
                    if (ereg('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $sEmail)) {
                        if ($iGender == '1' xor $iGender == '0') {
                            $sVcode = escape($_POST['vcode']);
                            if (! isset($_SESSION['valdiation_code'])) {
                                // Here you can send him some verification code (by email or any another ways)
                                $sCode = uniqid(rand(), true);
                                $_SESSION['valdiation_code'] = md5($sCode);

                            } elseif (md5($sVcode) == $_SESSION['valdiation_code']) {
                                // Here you can add him to database
                                // mysql_query('INSERT INTO ....

                                // display step 3 (final step)
                                echo strtr(file_get_contents('templates/step3.html'), array());
                                exit;
                            } else {
                                $sErrors = 'Verification code is wrong';
                            }
                        } else {
                            $sErrors = 'Gender is wrong';
                        }
                    } else {
                        $sErrors = 'Email is wrong';
                    }
                } else {
                    $sErrors = 'Passwords are not the same';
                }
            } else {
                $sErrors = 'Address email is too long';
            }
        } else {
            $sErrors = 'Password is too long';
        }
    } else {
        $sErrors = 'Login is too long';
    }

    // display step 2
    $aParams = array(
        '{errors}' =&gt; $sErrors,
        '{login}' =&gt; $sLogin,
        '{pass}' =&gt; $sPass,
        '{cpass}' =&gt; $sCPass,
        '{gender}' =&gt; $iGender,
        '{email}' =&gt; $sEmail,
        '{vcode}' =&gt; $sCode
    );
    echo strtr(file_get_contents('templates/step2.html'), $aParams);
    exit;
}

// unset validation code if exists
unset($_SESSION['valdiation_code']);

// draw registration page
echo strtr(file_get_contents('templates/main_page.html'), array());

// extra useful function to make POST variables more safe
function escape($s) {
    //return mysql_real_escape_string(strip_tags($s)); // uncomment in when you will use connection with database
    return strip_tags($s);
}
</pre><p>Now, lets try to understand this. This script generally does EXACTLY the same what previous JS scripts did but it is launched on the server side to check everything once more. Continue reading to check how does it work.</p><p>So, please pay attention to all our checks, and &#8211; to added validation functional. When our form submitted, the next step will contain single field to accept some validation code. Of course, for our demo page you always can see that checking code. But, as some suggestion &#8211; I can offer you to enable email confirmation (as example). So, you have to add email sending to this code also. And, only after accepting that extra validation code (if this code was right) &#8211; only then allow member registration. Please read my comments carefully.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Form Validation with Javascript and PHP - demo 228" href="http://www.script-tutorials.com/demos/228/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Form Validation with Javascript and PHP - package" href="http://www.script-tutorials.com/demos/228/source.zip" target="_blank" rel="nofollow">download in archive</a></strong></h5><hr
/><h3>Conclusion</h3><p>So that is all for now. In the final version I also added some classes which make table better positioned (stable) so make sure you&#8217;ve checked it out. While creating your own form you can expand it anyhow relying on what I wrote or try to use your imagination to create something better. Hope you enjoyed it. Good luck and welcome back!</p><div
class="shr-publisher-1403"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/data-validation-html5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/49.png" alt="Data Validation &#8211; How to Validate Forms using HTML5" /> <br
/> Data Validation &#8211; How to Validate Forms using HTML5</a></li><li> <a
href="http://www.script-tutorials.com/animated-photo-gallery-grid-with-javascript/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/54/thumb.png" alt="Animated Photo Gallery (grid) with javascript" /> <br
/> Animated Photo Gallery (grid) with javascript</a></li><li> <a
href="http://www.script-tutorials.com/cross-browser-effect-of-waves-using-javascript/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/81/thumb.png" alt="Creating Cross-browser Compatible Wave Effects Using Javascript" /> <br
/> Creating Cross-browser Compatible Wave Effects Using Javascript</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/form-validation-with-javascript-and-php/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Powerful Chat System &#8211; Lesson 3</title><link>http://www.script-tutorials.com/powerful-chat-system-lesson-3/</link> <comments>http://www.script-tutorials.com/powerful-chat-system-lesson-3/#comments</comments> <pubDate>Mon, 30 Jan 2012 17:01:39 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[AJAX]]></category> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[ajax chat]]></category> <category><![CDATA[chat]]></category> <category><![CDATA[chat system]]></category> <category><![CDATA[registration]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1396</guid> <description><![CDATA[Powerful Chat System &#8211; Lesson 3 Today we continue a series of articles on the creation of powerful chat system. Our third lesson will contain next elements: join form (with html5 validation). A long ago, I have already made similar validation. So you can refresh your memories if you like. Today I will publish updated [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/221/thumb.png" alt="Powerful Chat System &#8211; Lesson 2" /> Powerful Chat System &#8211; Lesson 2</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/218/thumb.png" alt="Powerful Chat System" /> Powerful Chat System</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-ajax-style-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make AJAX Style PHP Chat Application" /> How to Easily Make AJAX Style PHP Chat Application</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Powerful Chat System" alt="Powerful Chat System" src="http://www.script-tutorials.com/demos/226/thumb.png"></div><p><strong>Powerful Chat System &#8211; Lesson 3</strong><br
/> <br
/>Today we continue a series of articles on the creation of powerful chat system. Our third lesson will contain next elements: join form (with html5 validation). A long ago, I have already made similar <a
target="_blank" href="http://www.script-tutorials.com/data-validation-html5/">validation</a>. So you can refresh your memories if you like.<br
/> <span
id="more-1396"></span></p><p>Today I will publish updated sources of our growing project (several files was modified, plus I expanded structure of database slightly). All project is well structured: system classes is in &#8216;classes&#8217; folder, stylesheets in &#8216;css&#8217; folder, template files in &#8216;templates&#8217; folder, and &#8211; new folder &#8216;js&#8217; for javascript files.</p><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 226" href="http://www.script-tutorials.com/demos/226/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/226/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Now &#8211; download the source files and lets start coding !</p><hr
/><h3>Step 1. SQL</h3><p>I have added new field into table of profiles where we will store its first names. So, please execute next SQL:</p><pre class="brush:sql">
ALTER TABLE `cs_profiles` ADD `first_name` varchar(255) NOT NULL default '' AFTER `name`;
</pre><h3>Step 2. HTML</h3><p>I have updated template with login form. As you can see &#8211; I have expanded this markup and added join form here:</p><h4>templates/logout_form.html</h4><pre class="brush:html">
&lt;div class=&quot;column&quot;&gt;
    &lt;h3&gt;Powerful Chat System Demonstration&lt;/h3&gt;
    &lt;p&gt;Our chat will contain next features: registration, main chat, profiles with avatars, ranking system, private messaging, custom rooms, moderation / administration and possible something else (in future).&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;

    &lt;div class=&quot;tabs_container&quot;&gt;
        &lt;ul class=&quot;tabs&quot;&gt;
            &lt;li class=&quot;active&quot;&gt;&lt;h3&gt;Log In&lt;/h3&gt;&lt;/li&gt;
            &lt;li&gt;&lt;h3&gt;Join&lt;/h3&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;

    &lt;div class=&quot;nav_container&quot;&gt;
        &lt;form class=&quot;login_form&quot; action=&quot;index.php&quot; method=&quot;post&quot; id=&quot;1&quot;&gt;
            &lt;label&gt;Username:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;
            &lt;label&gt;Password:&lt;/label&gt;&lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;
            &lt;input type=&quot;submit&quot; name=&quot;Login&quot; value=&quot;Login&quot;&gt;
        &lt;/form&gt;
        &lt;form class=&quot;join_form&quot; action=&quot;index.php&quot; method=&quot;post&quot; id=&quot;2&quot; style=&quot;display: none;&quot;&gt;

            &lt;label&gt;Full name:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;username&quot; name=&quot;username&quot; placeholder=&quot;Your name&quot; maxlength=&quot;128&quot; title=&quot;Your name&quot; required&gt;

            &lt;label&gt;First name:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;firstname&quot; name=&quot;firstname&quot; placeholder=&quot;Your first name&quot; maxlength=&quot;128&quot; title=&quot;Your first name&quot;&gt;

            &lt;label&gt;Last name:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;lastname&quot; name=&quot;lastname&quot; placeholder=&quot;Your last name&quot; maxlength=&quot;128&quot; title=&quot;Your last name&quot;&gt;

            &lt;label&gt;Email:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Your email&quot; maxlength=&quot;128&quot; title=&quot;Format: *@gmail.com&quot; pattern=&quot;.*@gmail\.com&quot; required&gt;

            &lt;label&gt;Password:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;password&quot; name=&quot;password&quot; maxlength=&quot;128&quot; title=&quot;Password&quot; required&gt;

            &lt;label&gt;Repeat Password:&lt;/label&gt;
            &lt;input type=&quot;text&quot; id=&quot;password&quot; name=&quot;password&quot; maxlength=&quot;128&quot; title=&quot;Repeat password&quot; required oninput=&quot;checkpass(this)&quot;&gt;

            &lt;input type=&quot;submit&quot; name=&quot;Join&quot; value=&quot;Join&quot;&gt;
        &lt;/form&gt;
    &lt;/div&gt;

&lt;/div&gt;

&lt;script&gt;
$(document).ready(function(){
    $('.tabs li h3').click(function () {
      $('.tabs li').removeClass('active');
      $(this).parent().addClass('active');

      $('.nav_container form').hide();
      var index = $('.tabs li h3').index(this);
      $('.nav_container form').eq(index).show();
      return false;
    });
});

function checkpass(input) {
    if (input.value != document.getElementById('password').value) {
        input.setCustomValidity('Password must match.');
    } else {
        input.setCustomValidity('');
    }
}
&lt;/script&gt;
</pre><p>Please pay attention to HTML structure of join form, it contain several new attributes for html5 validation: placeholder, required and pattern. This is pretty interesting.</p><h3>Step 3. CSS</h3><p>This file has updated too</p><h4>css/main.css</h4><pre class="brush:html">
/* page layout */
*{
    margin:0;
    padding:0;
}
body {
    background-color:#eee;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
header {
    background-color:#212121;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    position:relative;
    width:100%;
    z-index:100;
}
header h2{
    font-size:22px;
    font-weight:normal;
    left:50%;
    margin-left:-400px;
    padding:22px 0;
    position:absolute;
    width:540px;
}
header a.stuts,a.stuts:visited{
    border:none;
    text-decoration:none;
    color:#fcfcfc;
    font-size:14px;
    left:50%;
    line-height:31px;
    margin:23px 0 0 110px;
    position:absolute;
    top:0;
}
header .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}

/* main styles */
.container {
    background-color: #222;
    color: #bbb;
    margin: 20px auto;
    overflow: hidden;
    padding: 20px;
    position: relative;
    width: 800px;
}
.container h2 {
    color: #fff;
    margin-bottom: 10px;
}
.column {
    float: left;
    width: 48%;
}
.column:first-child {
    margin-right: 4%;
}
.column &gt; * {
    color: #ddd;
    margin-bottom: 10px;
}

/* tabs section */
.tabs_container {
    margin: 0;
}
.tabs {
    overflow: hidden;
}
.tabs li {
    float: left;
    list-style: none;
}
.tabs li h3:first-child {
    margin-left: 10px
}
.tabs li h3 {
    border: 1px solid #ddd;
    border-bottom-width: 0;
    display: block;
    margin: 0 2px 0 0;
    padding: 6px 10px 4px
}
.tabs li.active h3 {
    background-color: #555;
    border: 1px solid #ddd;
    border-bottom-width: 0;

    -moz-border-radius: 4px 4px 0 0;
    -ms-border-radius: 4px 4px 0 0;
    -o-border-radius: 4px 4px 0 0;
    -webkit-border-radius: 4px 4px 0 0;
    border-radius: 4px 4px 0 0;
}
.tabs li h3:hover {
    background-color: #666;
    cursor: pointer;
}
.tabs li.active h3:hover {
    background-color: #555;
    cursor: normal;
}
.nav_container form {
    background-color: #555;
    display: block;
    padding: 15px;
}
.column h3 {
    color: #fff;
}
.login_form input,.login_form label,
.join_form input,.join_form label {
    display: block;
    margin-bottom: 10px;
}
input[type=text], input[type=password], input[type=submit] {
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
input[type=text], input[type=password] {
    font-size: 16px;
    height: 25px;
    margin-right: 10px;
    width: 200px;
}
input[type=submit]{
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    height: 35px;
    padding: 5px;
}

/* chat block */
.chat_messages {
    border: 1px solid #888;
    box-shadow: 0 0 5px #AAA;
    color: #000;
    padding: 10px;
}
.chat_messages h2 {
    color: #fff;
}
.chat_messages .message {
    background-color: #fff;
    margin: 5px;
    padding: 5px;

    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
.chat_messages .message span {
    color: #444;
    font-size: 10px;
    margin-left: 10px;
}
.chat_submit_form {
    margin: 10px 0px;
}
.chat_submit_form div {
    float: left;
    width: 49%;
}
.chat_submit_form .error, .chat_submit_form .success, .chat_submit_form .protect {
    display: none;
}
.chat_submit_form .error {
    color: #f55;
}
.chat_submit_form .success {
    color: #5f5;
}
.chat_submit_form .protect {
    color: #55f;
}
</pre><h3>Step 4. PHP</h3><p>Now, lets review php sources. Our index.php file has updated. I have added here join processing functional. Before actual joining, we have to check if someone else was joined with same email (this field should be unique of course)</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

// set error reporting level
if (version_compare(phpversion(), '5.3.0', '&gt;=') == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
else
  error_reporting(E_ALL &amp; ~E_NOTICE);

require_once('classes/Services_JSON.php');
require_once('classes/CMySQL.php'); // including service class to work with database
require_once('classes/CLogin.php'); // including service class to work with login processing

$sErrors = '';
// join processing
if (! isset($_SESSION['member_id']) &amp;&amp; $_POST['Join'] == 'Join') {
    $sUsername = $GLOBALS['MySQL']-&gt;escape($_POST['username']);
    $sFirstname = $GLOBALS['MySQL']-&gt;escape($_POST['firstname']);
    $sLastname = $GLOBALS['MySQL']-&gt;escape($_POST['lastname']);
    $sEmail = $GLOBALS['MySQL']-&gt;escape($_POST['email']);
    $sPassword = $GLOBALS['MySQL']-&gt;escape($_POST['password']);

    if ($sUsername &amp;&amp; $sEmail &amp;&amp; $sPassword) {
        // check if already exist
        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `email`='{$sEmail}'&quot;);
        if ($aProfile['id'] &gt; 0) {
            $sErrors = '&lt;h2&gt;Another profile with same email already exist&lt;/h2&gt;';
        } else {
            // generate Salt and Cached password
            $sSalt = 'testing'; // TODO - we will add generation of salt in future
            $sPass = sha1(md5($sPassword) . $sSalt);

            // add new member into database
            $sSQL = &quot;
                INSERT INTO `cs_profiles` SET
                `name` = '{$sUsername}',
                `first_name` = '{$sFirstname}',
                `last_name` = '{$sLastname}',
                `email` = '{$sEmail}',
                `password` = '{$sPass}',
                `salt` = '{$sSalt}',
                `status` = 'active',
                `role` = '1',
                `date_reg` = NOW();
            &quot;;
            $GLOBALS['MySQL']-&gt;res($sSQL);

            // autologin
            $GLOBALS['CLogin']-&gt;performLogin($sUsername, $sPassword);
        }
    }
}

// login system init and generation code
$sLoginForm = $GLOBALS['CLogin']-&gt;getLoginBox();

$sChat = '&lt;h2&gt;You do not have rights to use chat&lt;/h2&gt;';
$sInput = '';
if ($_SESSION['member_id'] &amp;&amp; $_SESSION['member_status'] == 'active' &amp;&amp; $_SESSION['member_role']) {
    require_once('classes/CChat.php'); // including service class to work with chat

    // get last messages
    $sChat = $GLOBALS['MainChat']-&gt;getMessages();
    if ($_GET['action'] == 'get_last_messages') { // regular updating of messages in chat
        $oJson = new Services_JSON();
        header('Content-type: application/json');
        echo $oJson-&gt;encode(array('messages' =&gt; $sChat));
        exit;
    }

    // get input form
    $sInput = $GLOBALS['MainChat']-&gt;getInputForm();

    if ($_POST['message']) { // POST-ing of message
        $iRes = $GLOBALS['MainChat']-&gt;acceptMessage();

        $oJson = new Services_JSON();
        header('Content-type: application/json');
        echo $oJson-&gt;encode(array('result' =&gt; $iRes));
        exit;
    }
}

// draw common page
echo strtr(file_get_contents('templates/main_page.html'), array('{form}' =&gt; $sLoginForm . $sErrors, '{chat}' =&gt; $sChat, '{input}' =&gt; $sInput));
</pre><p>As you can see &#8211; I have added chat functionality today.</p><h4>classes/CLogin.php</h4><pre class="brush:php">
&lt;?php

class CLogin {

    // constructor
    function CLogin() {
        session_start();
    }

    // get login box function
    function getLoginBox() {
        if (isset($_GET['logout'])) { // logout processing
            if (isset($_SESSION['member_name']) &amp;&amp; isset($_SESSION['member_pass']))
                $this-&gt;performLogout();
        }

        if ($_POST &amp;&amp; $_POST['Login'] == 'Login' &amp;&amp; $_POST['username'] &amp;&amp; $_POST['password']) { // login processing
            if ($this-&gt;checkLogin($_POST['username'], $_POST['password'], false)) { // successful login
                $this-&gt;performLogin($_POST['username'], $_POST['password']);
                header( &quot;Location:{$_SERVER['REQUEST_URI']}&quot; );
                exit;
            } else { // wrong login
                return file_get_contents('templates/login_form.html') . '&lt;h2&gt;Username or Password is incorrect&lt;/h2&gt;';
            }
        } else { // in case if we already logged (on refresh page):
            if (isset($_SESSION['member_name']) &amp;&amp; $_SESSION['member_name'] &amp;&amp; $_SESSION['member_pass']) {
                $aReplaces = array(
                    '{name}' =&gt; $_SESSION['member_name'],
                    '{status}' =&gt; $_SESSION['member_status'],
                    '{role}' =&gt; $_SESSION['member_role'],
                );
                return strtr(file_get_contents('templates/logout_form.html'), $aReplaces);
            }

            // otherwise - draw login form
            return file_get_contents('templates/login_form.html');
        }
    }

    // perform login
    function performLogin($sName, $sPass) {
        $this-&gt;performLogout();

        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        // $sPassEn = $aProfile['password'];
        $iPid = $aProfile['id'];
        $sSalt = $aProfile['salt'];
        $sStatus = $aProfile['status'];
        $sRole = $aProfile['role'];

        $sPass = sha1(md5($sPass) . $sSalt);

        $_SESSION['member_id'] = $iPid;
        $_SESSION['member_name'] = $sName;
        $_SESSION['member_pass'] = $sPass;
        $_SESSION['member_status'] = $sStatus;
        $_SESSION['member_role'] = $sRole;
    }

    // perform logout
    function performLogout() {
        unset($_SESSION['member_id']);
        unset($_SESSION['member_name']);
        unset($_SESSION['member_pass']);
        unset($_SESSION['member_status']);
        unset($_SESSION['member_role']);
    }

    // check login
    function checkLogin($sName, $sPass, $isHash = true) {
        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);
        $sPass = $GLOBALS['MySQL']-&gt;escape($sPass);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        $sPassEn = $aProfile['password'];

        if ($sName &amp;&amp; $sPass &amp;&amp; $sPassEn) {
            if (! $isHash) {
                $sSalt = $aProfile['salt'];
                $sPass = sha1(md5($sPass) . $sSalt);
            }
            return ($sPass == $sPassEn);
        }
        return false;
    }
}

$GLOBALS['CLogin'] = new CLogin();
</pre><p>Minor changes were made in this file too. The rest of the functional was not changed. We will continue enhance our chat soon.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 226" href="http://www.script-tutorials.com/demos/226/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/226/source.zip" target="_blank" rel="nofollow">download in archive</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that our new series of articles of chat system creation is useful and interesting for you. If you want to share your ideas, or you noticed any weakness &#8211; don&#8217;t hesitate to contact us. Good luck and welcome back!</p><div
class="shr-publisher-1396"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/221/thumb.png" alt="Powerful Chat System &#8211; Lesson 2" /> <br
/> Powerful Chat System &#8211; Lesson 2</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/218/thumb.png" alt="Powerful Chat System" /> <br
/> Powerful Chat System</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-ajax-style-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make AJAX Style PHP Chat Application" /> <br
/> How to Easily Make AJAX Style PHP Chat Application</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/powerful-chat-system-lesson-3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>CSS3 Image Hover Effects</title><link>http://www.script-tutorials.com/css3-image-hover-effects/</link> <comments>http://www.script-tutorials.com/css3-image-hover-effects/#comments</comments> <pubDate>Wed, 25 Jan 2012 16:59:22 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[effects]]></category> <category><![CDATA[image hover]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1386</guid> <description><![CDATA[CSS3 Image Hover Effects Today I will tell you how to create different CSS3 image hover effects. I hope that you still remember our one old tutorial. We used javascript there. Today I will try to make something similar with using CSS3. In the result gallery page we will have 9 images, each of them [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-slideshow/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/204/thumb.png" alt="How to Create a Pure CSS3 Slideshow" /> How to Create a Pure CSS3 Slideshow</a></li><li> <a
href="http://www.script-tutorials.com/how-to-do-pure-css3-photo-gallery/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/171/thumb.png" alt="How to Create a Pure CSS3 Animated Photo Gallery" /> How to Create a Pure CSS3 Animated Photo Gallery</a></li><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/184/thumb.png" alt="Creating Fantastic Animated Buttons using CSS3" /> Creating Fantastic Animated Buttons using CSS3</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="CSS3 Image Hover Effects" alt="CSS3 Image Hover Effects" src="http://www.script-tutorials.com/demos/225/thumb.png"></div><p><strong>CSS3 Image Hover Effects</strong><br
/> <br
/>Today I will tell you how to create different CSS3 image hover effects. I hope that you still remember our <a
target="_blank" href="http://www.script-tutorials.com/animated-photo-gallery-grid-with-javascript/">one old tutorial</a>. We used javascript there. Today I will try to make something similar with using CSS3. In the result gallery page we will have 9 images, each of them have own hover effect.<br
/> <span
id="more-1386"></span></p><h5 style="text-align: center;"><strong><a
title="CSS3 Image Hover Effects - online demo" href="http://www.script-tutorials.com/demos/225/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="CSS3 Image Hover Effects - package" href="http://www.script-tutorials.com/demos/225/source.zip" target="_blank">download result</a></strong></h5><hr
/><p>Ok, download the example files and lets start !</p><hr
/><h3>Step 1. HTML</h3><p>First, lets prepare the main HTML markup for our demo gallery. As you can see &#8211; result structure is quite easy. Here are set of DIV objects. Each of them contain one image and some virtual mask (DIV). Last one element will contain two masks.</p><h4>index.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;CSS3 Image Hover Effects | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/layout.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
        &lt;link href=&quot;css/gall.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            &lt;h2&gt;CSS3 Image Hover Effects&lt;/h2&gt;
            &lt;a href=&quot;http://www.script-tutorials.com/css3-image-hover-effects/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
        &lt;/header&gt;

        &lt;!-- panel with buttons --&gt;
        &lt;div class=&quot;photos&quot;&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic1.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic2.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic3.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic4.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic5.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic6.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic7.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;img src=&quot;images/pic8.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;pair&quot;&gt;
                &lt;img src=&quot;images/pic9.jpg&quot; /&gt;
                &lt;div&gt;&lt;/div&gt;
                &lt;div&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Step 2. CSS</h3><p>I omit styles of layout.css. Here are nothing interesting. The most interesting &#8211; next one file (where I have prepared all necessary styles of our gallery):</p><h4>css/gall.css</h4><pre class="brush:css">
.photos {
    width: 945px;
    height: 400px;
    margin: 100px auto;
    position:relative;
}
.photos &gt; div {
    background-color: rgba(128, 128, 128, 0.5);
    border: 2px solid #444;
    float: left;
    height: 100px;
    margin: 5px;
    overflow: hidden;
    position: relative;
    width: 300px;
    z-index: 1;

    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    -ms-border-radius: 10px;
    -o-border-radius: 10px;
    border-radius: 10px;

    -webkit-transform:scale(1.0);
    -moz-transform:scale(1.0);
    -ms-transform:scale(1.0);
    -o-transform:scale(1.0);
    transform:scale(1.0);

    -webkit-transition-duration: 0.5s;
    -moz-transition-duration: 0.5s;
    -ms-transition-duration: 0.5s;
    -o-transition-duration: 0.5s;
    transition-duration: 0.5s;
}
.photos &gt; div img{
    width: 100%;
}
.photos &gt; div:hover{
    z-index: 10;

    -webkit-transform:scale(2.0);
    -moz-transform:scale(2.0);
    -ms-transform:scale(2.0);
    -o-transform:scale(2.0);
    transform:scale(2.0);
}
.photos &gt; div div {
    background: url(../images/hover.gif) repeat scroll 0 0 transparent;
    cursor: pointer;
    height: 100%;
    left: 0;
    opacity: 0.5;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 15;

    -webkit-transition-duration: 0.5s;
    -moz-transition-duration: 0.5s;
    -ms-transition-duration: 0.5s;
    -o-transition-duration: 0.5s;
    transition-duration: 0.5s;
}
.photos &gt; div:nth-child(1):hover div {
    height: 0%;
}

.photos &gt; div:nth-child(2):hover div {
    height: 0%;
    margin-top: 100px;
}
.photos &gt; div:nth-child(3):hover div {
    width: 0%;
}
.photos &gt; div:nth-child(4):hover div {
    margin-left: 300px;
    width: 0%;
}
.photos &gt; div:nth-child(5):hover div {
    height: 0%;
    margin-left: 150px;
    margin-top: 50px;
    width: 0%;
}
.photos &gt; div:nth-child(6):hover div {
    margin-left: 150px;
    width: 0%;
}
.photos &gt; div:nth-child(7):hover div {
    height: 0%;
    margin-left: 150px;
    margin-top: 50px;
    width: 0%;

    -webkit-transform: rotateX(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(-360deg);
    transform: rotate(-360deg);
}
.photos &gt; div:nth-child(8):hover div {
    height: 0%;
    margin-left: 150px;
    margin-top: 50px;
    width: 0%;

    -webkit-transform: rotateZ(600deg);
    -moz-transform: rotateZ(600deg);
    -ms-transform: rotateZ(600deg);
    -o-transform: rotateZ(600deg);
    transform: rotateZ(600deg);
}
.photos &gt; div.pair div {
    width: 50%;
}
.photos &gt; div.pair div:nth-child(odd) {
    margin-left: 150px;
}
.photos &gt; div.pair:hover div {
    width: 0%;
}
.photos &gt; div.pair:hover div:nth-child(odd) {
    margin-left: 300px;
}
</pre><hr
/><h5 style="text-align: center;"><strong><a
title="CSS3 Image Hover Effects - demo 225" href="http://www.script-tutorials.com/demos/225/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="CSS3 Image Hover Effects - package" href="http://www.script-tutorials.com/demos/225/source.zip" target="_blank" rel="nofollow">download result</a></strong></h5><hr
/><h3>Conclusion</h3><p>Today we have nine great onhover image effects. Welcome back to read our new tutorials!</p><div
class="shr-publisher-1386"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-slideshow/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/204/thumb.png" alt="How to Create a Pure CSS3 Slideshow" /> <br
/> How to Create a Pure CSS3 Slideshow</a></li><li> <a
href="http://www.script-tutorials.com/how-to-do-pure-css3-photo-gallery/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/171/thumb.png" alt="How to Create a Pure CSS3 Animated Photo Gallery" /> <br
/> How to Create a Pure CSS3 Animated Photo Gallery</a></li><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/184/thumb.png" alt="Creating Fantastic Animated Buttons using CSS3" /> <br
/> Creating Fantastic Animated Buttons using CSS3</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/css3-image-hover-effects/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>HTML5 Game Development &#8211; Lesson 7</title><link>http://www.script-tutorials.com/html5-game-development-lesson-7/</link> <comments>http://www.script-tutorials.com/html5-game-development-lesson-7/#comments</comments> <pubDate>Mon, 23 Jan 2012 18:24:06 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[collisions]]></category> <category><![CDATA[game development]]></category> <category><![CDATA[html5 games]]></category> <category><![CDATA[HTML5 local storage]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1380</guid> <description><![CDATA[HTML5 Game Development &#8211; Lesson 7 Today we will create our first complete game &#8211; Arkanoid. In this lesson I will show you how to detect basic collisions and work with HTML5 local storage. You can operate with pad using mouse and keyboard (left/right buttons). We will store in local storage elapsed time of previous [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-6/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/214/thumb.png" alt="HTML5 Game Development &#8211; Lesson 6" /> HTML5 Game Development &#8211; Lesson 6</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/205/thumb.png" alt="HTML5 Game Development &#8211; Lesson 5" /> HTML5 Game Development &#8211; Lesson 5</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-navigating-your-spaceship-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/166/thumb.png" alt="HTML5 Game Development &#8211; Navigating Your Spaceship- Lesson 3" /> HTML5 Game Development &#8211; Navigating Your Spaceship- Lesson 3</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="HTML5 Game Development - Lesson 7" alt="HTML5 Game Development - Lesson 7" src="http://www.script-tutorials.com/demos/223/thumb.png"></div><p><strong>HTML5 Game Development &#8211; Lesson 7</strong><br
/> <br
/>Today we will create our first complete game &#8211; Arkanoid. In this lesson I will show you how to detect basic collisions and work with HTML5 local storage. You can operate with pad using mouse and keyboard (left/right buttons). We will store in local storage elapsed time of previous game and amount of broken bricks (points).<br
/> <br
/>Here you can read our previous lesson: <a
href="http://www.script-tutorials.com/html5-game-development-lesson-6/">Developing Your First HTML5 Game – Lesson 6</a>.<br
/> <span
id="more-1380"></span><br
/></p><p>Here are our demo and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="HTML5 Game Development - Lesson 7 - live demo" href="http://www.script-tutorials.com/demos/223/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="HTML5 Game Development - Lesson 7 - package" href="http://www.script-tutorials.com/demos/223/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the example files and lets start coding !</p><hr
/><h3>Step 1. HTML</h3><p>Here is source code of our seventh lesson</p><h4>index.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;HTML5 Game Development - Lesson 7 | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
        &lt;script src=&quot;js/jquery-1.5.2.min.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;js/script.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            &lt;h2&gt;HTML5 Game Development - Lesson 7&lt;/h2&gt;
            &lt;a href=&quot;http://www.script-tutorials.com/html5-game-development-lesson-7/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
        &lt;/header&gt;

        &lt;div class=&quot;container&quot;&gt;
            &lt;canvas id=&quot;scene&quot; width=&quot;800&quot; height=&quot;600&quot;&gt;&lt;/canvas&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Step 2. CSS</h3><p>Here are used CSS styles.</p><h4>css/main.css</h4><pre class="brush:css">
/* page layout styles */
*{
    margin:0;
    padding:0;
}
body {
    background-color:#eee;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
header {
    background-color:#212121;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    position:relative;
    width:100%;
    z-index:100;
}
header h2{
    font-size:22px;
    font-weight:normal;
    left:50%;
    margin-left:-400px;
    padding:22px 0;
    position:absolute;
    width:540px;
}
header a.stuts,a.stuts:visited{
    border:none;
    text-decoration:none;
    color:#fcfcfc;
    font-size:14px;
    left:50%;
    line-height:31px;
    margin:23px 0 0 110px;
    position:absolute;
    top:0;
}
header .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}
.container {
    margin: 20px auto;
    overflow: hidden;
    position: relative;
    width: 800px;
}
</pre><h3>Step 3. JS</h3><h4>js/jquery-1.5.2.min.js</h4><p>We use jQuery for our lesson. Available in package. Next file most important (here are all our html5 functional):</p><h4>js/script.js</h4><pre class="brush:js">
// inner variables
var canvas, ctx;

var iStart = 0;
var bRightBut = false;
var bLeftBut = false;
var oBall, oPadd, oBricks;
var aSounds = [];
var iPoints = 0;
var iGameTimer;
var iElapsed = iMin = iSec = 0;
var sLastTime, sLastPoints;

// objects :
function Ball(x, y, dx, dy, r) {
    this.x = x;
    this.y = y;
    this.dx = dx;
    this.dy = dy;
    this.r = r;
}
function Padd(x, w, h, img) {
    this.x = x;
    this.w = w;
    this.h = h;
    this.img = img;
}
function Bricks(w, h, r, c, p) {
    this.w = w;
    this.h = h;
    this.r = r; // rows
    this.c = c; // cols
    this.p = p; // padd
    this.objs;
    this.colors = ['#9d9d9d', '#f80207', '#feff01', '#0072ff', '#fc01fc', '#03fe03']; // colors for rows
}

// -------------------------------------------------------------
// draw functions :

function clear() { // clear canvas function
    ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);

    // fill background
    ctx.fillStyle = '#111';
    ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}

function drawScene() { // main drawScene function
    clear(); // clear canvas

    // draw Ball (circle)
    ctx.fillStyle = '#f66';
    ctx.beginPath();
    ctx.arc(oBall.x, oBall.y, oBall.r, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.fill();

    if (bRightBut)
        oPadd.x += 5;
    else if (bLeftBut)
        oPadd.x -= 5;

    // draw Padd (rectangle)
    ctx.drawImage(oPadd.img, oPadd.x, ctx.canvas.height - oPadd.h);

    // draw bricks (from array of its objects)
    for (i=0; i &lt; oBricks.r; i++) {
        ctx.fillStyle = oBricks.colors[i];
        for (j=0; j &lt; oBricks.c; j++) {
            if (oBricks.objs[i][j] == 1) {
                ctx.beginPath();
                ctx.rect((j * (oBricks.w + oBricks.p)) + oBricks.p, (i * (oBricks.h + oBricks.p)) + oBricks.p, oBricks.w, oBricks.h);
                ctx.closePath();
                ctx.fill();
            }
        }
    }

    // collision detection
    iRowH = oBricks.h + oBricks.p;
    iRow = Math.floor(oBall.y / iRowH);
    iCol = Math.floor(oBall.x / (oBricks.w + oBricks.p));

    // mark brick as broken (empty) and reverse brick
    if (oBall.y &lt; oBricks.r * iRowH &amp;&amp; iRow &gt;= 0 &amp;&amp; iCol &gt;= 0 &amp;&amp; oBricks.objs[iRow][iCol] == 1) {
        oBricks.objs[iRow][iCol] = 0;
        oBall.dy = -oBall.dy;
        iPoints++;

        aSounds[0].play(); // play sound
    }

    // reverse X position of ball
    if (oBall.x + oBall.dx + oBall.r &gt; ctx.canvas.width || oBall.x + oBall.dx - oBall.r &lt; 0) {
        oBall.dx = -oBall.dx;
    }

    if (oBall.y + oBall.dy - oBall.r &lt; 0) {
        oBall.dy = -oBall.dy;
    } else if (oBall.y + oBall.dy + oBall.r &gt; ctx.canvas.height - oPadd.h) {
        if (oBall.x &gt; oPadd.x &amp;&amp; oBall.x &lt; oPadd.x + oPadd.w) {
            oBall.dx = 10 * ((oBall.x-(oPadd.x+oPadd.w/2))/oPadd.w);
            oBall.dy = -oBall.dy;

            aSounds[2].play(); // play sound
        }
        else if (oBall.y + oBall.dy + oBall.r &gt; ctx.canvas.height) {
            clearInterval(iStart);
            clearInterval(iGameTimer);

            // HTML5 Local storage - save values
            localStorage.setItem('last-time', iMin + ':' + iSec);
            localStorage.setItem('last-points', iPoints);

            aSounds[1].play(); // play sound
        }
    }

    oBall.x += oBall.dx;
    oBall.y += oBall.dy;

    ctx.font = '16px Verdana';
    ctx.fillStyle = '#fff';
    iMin = Math.floor(iElapsed / 60);
    iSec = iElapsed % 60;
    if (iMin &lt; 10) iMin = &quot;0&quot; + iMin;
    if (iSec &lt; 10) iSec = &quot;0&quot; + iSec;
    ctx.fillText('Time: ' + iMin + ':' + iSec, 600, 520);
    ctx.fillText('Points: ' + iPoints, 600, 550);

    if (sLastTime != null &amp;&amp; sLastPoints != null) {
        ctx.fillText('Last Time: ' + sLastTime, 600, 460);
        ctx.fillText('Last Points: ' + sLastPoints, 600, 490);
    }
}

// initialization
$(function(){
    canvas = document.getElementById('scene');
    ctx = canvas.getContext('2d');

    var width = canvas.width;
    var height = canvas.height;

    var padImg = new Image();
    padImg.src = 'images/padd.png';
    padImg.onload = function() {};

    oBall = new Ball(width / 2, 550, 0.5, -5, 10); // new ball object
    oPadd = new Padd(width / 2, 120, 20, padImg); // new padd object
    oBricks = new Bricks((width / <img src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> - 1, 20, 6, 8, 2); // new bricks object

    oBricks.objs = new Array(oBricks.r); // fill-in bricks
    for (i=0; i &lt; oBricks.r; i++) {
        oBricks.objs[i] = new Array(oBricks.c);
        for (j=0; j &lt; oBricks.c; j++) {
            oBricks.objs[i][j] = 1;
        }
    }

    aSounds[0] = new Audio('media/snd1.wav');
    aSounds[0].volume = 0.9;
    aSounds[1] = new Audio('media/snd2.wav');
    aSounds[1].volume = 0.9;
    aSounds[2] = new Audio('media/snd3.wav');
    aSounds[2].volume = 0.9;

    iStart = setInterval(drawScene, 10); // loop drawScene
    iGameTimer = setInterval(countTimer, 1000); // inner game timer

    // HTML5 Local storage - get values
    sLastTime = localStorage.getItem('last-time');
    sLastPoints = localStorage.getItem('last-points');

    $(window).keydown(function(event){ // keyboard-down alerts
        switch (event.keyCode) {
            case 37: // 'Left' key
                bLeftBut = true;
                break;
            case 39: // 'Right' key
                bRightBut = true;
                break;
        }
    });
    $(window).keyup(function(event){ // keyboard-up alerts
        switch (event.keyCode) {
            case 37: // 'Left' key
                bLeftBut = false;
                break;
            case 39: // 'Right' key
                bRightBut = false;
                break;
        }
    });

    var iCanvX1 = $(canvas).offset().left;
    var iCanvX2 = iCanvX1 + width;
    $('#scene').mousemove(function(e) { // binding mousemove event
        if (e.pageX &gt; iCanvX1 &amp;&amp; e.pageX &lt; iCanvX2) {
            oPadd.x = Math.max(e.pageX - iCanvX1 - (oPadd.w/2), 0);
            oPadd.x = Math.min(ctx.canvas.width - oPadd.w, oPadd.x);
        }
    });
});

function countTimer() {
    iElapsed++;
}
</pre><p>I added my comments anywhere, hope that all code is pretty understandable. Please pay attention to &#8216;localStorage&#8217; object to understand how to work with HTML5 Local storage (I use &#8216;setItem&#8217; method to store something and &#8216;getItem&#8217; to read this from local storage). Also, it can be also interesting to understand how to calculate collisions between the ball and bricks.</p><hr
/><h5 style="text-align: center;"><strong><a
title="HTML5 Game Development - Lesson 7 - live demo" href="http://www.script-tutorials.com/demos/223/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="HTML5 Game Development - Lesson 7 - package" href="http://www.script-tutorials.com/demos/223/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>Today, we made our first arkanoid game. Most functionality are already here. We have implemented our first knowledge about collisions and HTML5 local storage too. I will be glad to see your thanks and comments. Good luck!</p><div
class="shr-publisher-1380"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-6/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/214/thumb.png" alt="HTML5 Game Development &#8211; Lesson 6" /> <br
/> HTML5 Game Development &#8211; Lesson 6</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/205/thumb.png" alt="HTML5 Game Development &#8211; Lesson 5" /> <br
/> HTML5 Game Development &#8211; Lesson 5</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-navigating-your-spaceship-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/166/thumb.png" alt="HTML5 Game Development &#8211; Navigating Your Spaceship- Lesson 3" /> <br
/> HTML5 Game Development &#8211; Navigating Your Spaceship- Lesson 3</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/html5-game-development-lesson-7/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>CSS3 Modal Popups</title><link>http://www.script-tutorials.com/css3-modal-popups/</link> <comments>http://www.script-tutorials.com/css3-modal-popups/#comments</comments> <pubDate>Fri, 20 Jan 2012 18:24:04 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[css3 popup]]></category> <category><![CDATA[modal window]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1377</guid> <description><![CDATA[CSS3 Modal Popups Today I will tell you how to create cool CSS3 modal popup windows (or boxes). Literally, not so long ago, in order to achieve such effects, we used jQuery. But, as it turned out, CSS3 has all the necessary tools for making modal windows too. In our demonstration I have prepared single [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/184/thumb.png" alt="Creating Fantastic Animated Buttons using CSS3" /> Creating Fantastic Animated Buttons using CSS3</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/87/thumb.png" alt="Creating a cool CSS3 Dropdown Menu" /> Creating a cool CSS3 Dropdown Menu</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu-4/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/102/thumb.png" alt="Creating A CSS3 Dropdown Menu #4" /> Creating A CSS3 Dropdown Menu #4</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="CSS3 Modal Popups" alt="CSS3 Modal Popups" src="http://www.script-tutorials.com/demos/222/thumb.png"></div><p><strong>CSS3 Modal Popups</strong><br
/> <br
/>Today I will tell you how to create cool CSS3 modal popup windows (or boxes). Literally, not so long ago, in order to achieve such effects, we used jQuery. But, as it turned out, CSS3 has all the necessary tools for making modal windows too. In our demonstration I have prepared single page with two popup elements: join form and login form. Welcome to test results and understand how it was made.<br
/> <span
id="more-1377"></span></p><h5 style="text-align: center;"><strong><a
title="CSS3 Modal Popups - online demo" href="http://www.script-tutorials.com/demos/222/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="CSS3 Modal Popups - package" href="http://www.script-tutorials.com/demos/222/source.zip" target="_blank">download result</a></strong></h5><hr
/><p>Ok, download the example files and lets start !</p><hr
/><h3>Step 1. HTML</h3><p>First, lets create the main HTML markup. As you can see &#8211; the structure is quite easy. Here are one panel with buttons and two popups. Each of them contains own overlay DIV element and popup DIV element with some content inside and &#8216;close&#8217; button.</p><h4>index.html</h4><pre class="brush:html">
<!DOCTYPE html>
&lt;html lang=&quot;en&quot; &gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;CSS3 Modal Popups | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/layout.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
        &lt;link href=&quot;css/modal.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            &lt;h2&gt;CSS3 Modal Popups&lt;/h2&gt;
            &lt;a href=&quot;http://www.script-tutorials.com/css3-modal-popups/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
        &lt;/header&gt;

        &lt;!-- panel with buttons --&gt;
        &lt;div class=&quot;main&quot;&gt;
            &lt;div class=&quot;panel&quot;&gt;
                &lt;a href=&quot;#login_form&quot; id=&quot;login_pop&quot;&gt;Log In&lt;/a&gt;
                &lt;a href=&quot;#join_form&quot; id=&quot;join_pop&quot;&gt;Sign Up&lt;/a&gt;
            &lt;/div&gt;

        &lt;/div&gt;

        &lt;!-- popup form #1 --&gt;
        &lt;a href=&quot;#x&quot; class=&quot;overlay&quot; id=&quot;login_form&quot;&gt;&lt;/a&gt;
        &lt;div class=&quot;popup&quot;&gt;
            &lt;h2&gt;Welcome Guest!&lt;/h2&gt;
            &lt;p&gt;Please enter your login and password here&lt;/p&gt;
            &lt;div&gt;
                &lt;label for=&quot;login&quot;&gt;Login&lt;/label&gt;
                &lt;input type=&quot;text&quot; id=&quot;login&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                &lt;input type=&quot;password&quot; id=&quot;password&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;input type=&quot;button&quot; value=&quot;Log In&quot; /&gt;

            &lt;a class=&quot;close&quot; href=&quot;#close&quot;&gt;&lt;/a&gt;
        &lt;/div&gt;

        &lt;!-- popup form #2 --&gt;
        &lt;a href=&quot;#x&quot; class=&quot;overlay&quot; id=&quot;join_form&quot;&gt;&lt;/a&gt;
        &lt;div class=&quot;popup&quot;&gt;
            &lt;h2&gt;Sign Up&lt;/h2&gt;
            &lt;p&gt;Please enter your details here&lt;/p&gt;
            &lt;div&gt;
                &lt;label for=&quot;email&quot;&gt;Login (Email)&lt;/label&gt;
                &lt;input type=&quot;text&quot; id=&quot;email&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;pass&quot;&gt;Password&lt;/label&gt;
                &lt;input type=&quot;password&quot; id=&quot;pass&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;firstname&quot;&gt;First name&lt;/label&gt;
                &lt;input type=&quot;text&quot; id=&quot;firstname&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;div&gt;
                &lt;label for=&quot;lastname&quot;&gt;Last name&lt;/label&gt;
                &lt;input type=&quot;text&quot; id=&quot;lastname&quot; value=&quot;&quot; /&gt;
            &lt;/div&gt;
            &lt;input type=&quot;button&quot; value=&quot;Sign Up&quot; /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;or&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;#login_form&quot; id=&quot;login_pop&quot;&gt;Log In&lt;/a&gt;

            &lt;a class=&quot;close&quot; href=&quot;#close&quot;&gt;&lt;/a&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Step 2. CSS</h3><p>I omit styles of layout.css. Here are nothing interesting. The most interesting &#8211; next one file (where I have prepared all necessary styles for our modal popups):</p><h4>css/modal.css</h4><pre class="brush:css">
.main {
    background: #aaa url(../images/bg.jpg) no-repeat;
    width: 800px;
    height: 600px;
    margin: 50px auto;
}
.panel {
    background-color: #444;
    height: 34px;
    padding: 10px;
}
.panel a#login_pop, .panel a#join_pop {
    border: 2px solid #aaa;
    color: #fff;
    display: block;
    float: right;
    margin-right: 10px;
    padding: 5px 10px;
    text-decoration: none;
    text-shadow: 1px 1px #000;

    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    -ms-border-radius: 10px;
    -o-border-radius: 10px;
    border-radius: 10px;
}
a#login_pop:hover, a#join_pop:hover {
    border-color: #eee;
}
.overlay {
    background-color: rgba(0, 0, 0, 0.6);
    bottom: 0;
    cursor: default;
    left: 0;
    opacity: 0;
    position: fixed;
    right: 0;
    top: 0;
    visibility: hidden;
    z-index: 1;

    -webkit-transition: opacity .5s;
    -moz-transition: opacity .5s;
    -ms-transition: opacity .5s;
    -o-transition: opacity .5s;
    transition: opacity .5s;
}
.overlay:target {
    visibility: visible;
    opacity: 1;
}
.popup {
    background-color: #fff;
    border: 3px solid #fff;
    display: inline-block;
    left: 50%;
    opacity: 0;
    padding: 15px;
    position: fixed;
    text-align: justify;
    top: 40%;
    visibility: hidden;
    z-index: 10;

    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);

    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    -ms-border-radius: 10px;
    -o-border-radius: 10px;
    border-radius: 10px;

    -webkit-box-shadow: 0 1px 1px 2px rgba(0, 0, 0, 0.4) inset;
    -moz-box-shadow: 0 1px 1px 2px rgba(0, 0, 0, 0.4) inset;
    -ms-box-shadow: 0 1px 1px 2px rgba(0, 0, 0, 0.4) inset;
    -o-box-shadow: 0 1px 1px 2px rgba(0, 0, 0, 0.4) inset;
    box-shadow: 0 1px 1px 2px rgba(0, 0, 0, 0.4) inset;

    -webkit-transition: opacity .5s, top .5s;
    -moz-transition: opacity .5s, top .5s;
    -ms-transition: opacity .5s, top .5s;
    -o-transition: opacity .5s, top .5s;
    transition: opacity .5s, top .5s;
}
.overlay:target+.popup {
    top: 50%;
    opacity: 1;
    visibility: visible;
}
.close {
    background-color: rgba(0, 0, 0, 0.8);
    height: 30px;
    line-height: 30px;
    position: absolute;
    right: 0;
    text-align: center;
    text-decoration: none;
    top: -15px;
    width: 30px;

    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    -ms-border-radius: 15px;
    -o-border-radius: 15px;
    border-radius: 15px;
}
.close:before {
    color: rgba(255, 255, 255, 0.9);
    content: &quot;X&quot;;
    font-size: 24px;
    text-shadow: 0 -1px rgba(0, 0, 0, 0.9);
}
.close:hover {
    background-color: rgba(64, 128, 128, 0.8);
}
.popup p, .popup div {
    margin-bottom: 10px;
}
.popup label {
    display: inline-block;
    text-align: left;
    width: 120px;
}
.popup input[type=&quot;text&quot;], .popup input[type=&quot;password&quot;] {
    border: 1px solid;
    border-color: #999 #ccc #ccc;
    margin: 0;
    padding: 2px;

    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    -ms-border-radius: 2px;
    -o-border-radius: 2px;
    border-radius: 2px;
}
.popup input[type=&quot;text&quot;]:hover, .popup input[type=&quot;password&quot;]:hover {
    border-color: #555 #888 #888;
}
</pre><hr
/><h5 style="text-align: center;"><strong><a
title="CSS3 Modal Popups - demo 222" href="http://www.script-tutorials.com/demos/222/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="CSS3 Modal Popups - package" href="http://www.script-tutorials.com/demos/222/source.zip" target="_blank" rel="nofollow">download result</a></strong></h5><hr
/><h3>Conclusion</h3><p>Today we have made another great CSS3 demonstration &#8211; popup modal windows. Welcome back to read our new tutorials!</p><div
class="shr-publisher-1377"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-a-pure-css3-animated-buttons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/184/thumb.png" alt="Creating Fantastic Animated Buttons using CSS3" /> <br
/> Creating Fantastic Animated Buttons using CSS3</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/87/thumb.png" alt="Creating a cool CSS3 Dropdown Menu" /> <br
/> Creating a cool CSS3 Dropdown Menu</a></li><li> <a
href="http://www.script-tutorials.com/creating-css3-dropdown-menu-4/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/102/thumb.png" alt="Creating A CSS3 Dropdown Menu #4" /> <br
/> Creating A CSS3 Dropdown Menu #4</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/css3-modal-popups/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Powerful Chat System &#8211; Lesson 2</title><link>http://www.script-tutorials.com/powerful-chat-system-lesson-2/</link> <comments>http://www.script-tutorials.com/powerful-chat-system-lesson-2/#comments</comments> <pubDate>Wed, 18 Jan 2012 17:17:45 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[AJAX]]></category> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[ajax chat]]></category> <category><![CDATA[chat]]></category> <category><![CDATA[chat system]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1373</guid> <description><![CDATA[Powerful Chat System &#8211; Lesson 2 Today we continue a series of articles on the creation of powerful chat system. Our second lesson will contain next elements: smart chat (ajax, with spam filtering &#8211; protection from the frequent messages). I have decided to make registration for next lesson. Hope that it is ok for you. [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/226/thumb.png" alt="Powerful Chat System &#8211; Lesson 3" /> Powerful Chat System &#8211; Lesson 3</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/218/thumb.png" alt="Powerful Chat System" /> Powerful Chat System</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-ajax-style-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make AJAX Style PHP Chat Application" /> How to Easily Make AJAX Style PHP Chat Application</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Powerful Chat System" alt="Powerful Chat System" src="http://www.script-tutorials.com/demos/221/thumb.png"></div><p><strong>Powerful Chat System &#8211; Lesson 2</strong><br
/> <br
/>Today we continue a series of articles on the creation of powerful chat system. Our second lesson will contain next elements: smart chat (ajax, with spam filtering &#8211; protection from the frequent messages). I have decided to make registration for next lesson. Hope that it is ok for you.<br
/> <span
id="more-1373"></span></p><p>Today I have included next elements: chat processor, plus &#8211; slight corrections in our previous sources. All project is well structured: system classes is in &#8216;classes&#8217; folder, stylesheets in &#8216;css&#8217; folder, template files in &#8216;templates&#8217; folder, and &#8211; new folder &#8216;js&#8217; for javascript files.</p><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 221" href="http://www.script-tutorials.com/demos/221/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/221/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Now &#8211; download the source files and lets start coding !</p><hr
/><h3>Step 1. SQL</h3><p>This table has got minor changes. I have changed type of field &#8216;when&#8217;.</p><pre class="brush:sql">
CREATE TABLE `cs_messages` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sender` int(11) unsigned NOT NULL,
  `recipient` int(11) unsigned NOT NULL default '0',
  `message` VARCHAR(255) NOT NULL,
  `when` int(11) NOT NULL default '0',
  `room` int(5) unsigned NOT NULL default '0',
  `type` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
</pre><h3>Step 2. HTML</h3><p>This is main (index) page html markup:</p><h4>templates/main_page.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
&lt;head&gt;
    &lt;title&gt;Powerful Chat System - Lesson 2&lt;/title&gt;
    &lt;link href=&quot;css/main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
    &lt;script src=&quot;http://code.jquery.com/jquery-latest.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;header&gt;
        &lt;h2&gt;Powerful Chat System - Lesson 2&lt;/h2&gt;
        &lt;a href=&quot;http://www.script-tutorials.com/powerful-chat-system-lesson-2/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
    &lt;/header&gt;
    &lt;div class=&quot;container&quot;&gt;
        {form}
    &lt;/div&gt;
    &lt;div class=&quot;container&quot;&gt;
        &lt;h2&gt;Main Chat Block&lt;/h2&gt;
        &lt;div class=&quot;chat_messages&quot;&gt;
            {chat}
        &lt;/div&gt;
        {input}
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre><p>As you can see &#8211; I have changed our second container (which contains our ajax chat).</p><h4>templates/login_form.html and templates/logout_form.html</h4><p>These files haven&#8217;t changed since last time. Next one new template &#8211; chat form:</p><h4>templates/chat.html</h4><pre class="brush:html">
&lt;form class=&quot;chat_submit_form&quot;&gt;
    &lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;message&quot; /&gt;&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;Submit&quot; /&gt;&lt;/div&gt;
    &lt;div&gt;
        &lt;h3 class=&quot;error&quot;&gt;Some error occurs during sending message&lt;/h3&gt;
        &lt;h3 class=&quot;success&quot;&gt;Message successfully sent&lt;/h3&gt;
        &lt;h3 class=&quot;protect&quot;&gt;Please wait 5 secs before adding next message&lt;/h3&gt;
    &lt;/div&gt;
&lt;/form&gt;
&lt;script src=&quot;js/chat.js&quot;&gt;&lt;/script&gt;
</pre><h3>Step 3. CSS</h3><p>This file contains updated styles of our chat</p><h4>css/main.css</h4><pre class="brush:html">
/* page layout */
*{
    margin:0;
    padding:0;
}
body {
    background-color:#eee;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
header {
    background-color:#212121;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    position:relative;
    width:100%;
    z-index:100;
}
header h2{
    font-size:22px;
    font-weight:normal;
    left:50%;
    margin-left:-400px;
    padding:22px 0;
    position:absolute;
    width:540px;
}
header a.stuts,a.stuts:visited{
    border:none;
    text-decoration:none;
    color:#fcfcfc;
    font-size:14px;
    left:50%;
    line-height:31px;
    margin:23px 0 0 110px;
    position:absolute;
    top:0;
}
header .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}

/* main styles */
.container {
    background-color: #222;
    color: #bbb;
    margin: 20px auto;
    overflow: hidden;
    padding: 20px;
    position: relative;
    width: 800px;
}
.container h2 {
    color: #fff;
    margin-bottom: 10px;
}
.column {
    float: left;
    width: 48%;
}
.column:first-child {
    margin-right: 4%;
}
.column &gt; * {
    color: #ddd;
    margin-bottom: 10px;
}
.column h3 {
    color: #fff;
}
.login_form input,.login_form label {
    display: block;
    margin-bottom: 10px;
}
input[type=text], input[type=password], input[type=submit] {
    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
input[type=text], input[type=password] {
    font-size: 16px;
    height: 30px;
    margin-right: 10px;
    width: 200px;
}
input[type=submit]{
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    height: 35px;
    padding: 5px;
}

/* chat block */
.chat_messages {
    border: 1px solid #888;
    box-shadow: 0 0 5px #AAA;
    color: #000;
    padding: 10px;
}
.chat_messages h2 {
    color: #fff;
}
.chat_messages .message {
    background-color: #fff;
    margin: 5px;
    padding: 5px;

    -moz-border-radius: 5px;
    -ms-border-radius: 5px;
    -o-border-radius: 5px;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
.chat_messages .message span {
    color: #444;
    font-size: 10px;
    margin-left: 10px;
}
.chat_submit_form {
    margin: 10px 0px;
}
.chat_submit_form div {
    float: left;
    width: 49%;
}
.chat_submit_form .error, .chat_submit_form .success, .chat_submit_form .protect {
    display: none;
}
.chat_submit_form .error {
    color: #f55;
}
.chat_submit_form .success {
    color: #5f5;
}
.chat_submit_form .protect {
    color: #55f;
}
</pre><h3>Step 4. JS</h3><p>I have created first JS for our chat. At beginning &#8211; it contain one function for regular obtaining messages, and handler of form submitting.</p><h4>js/chat.js</h4><pre class="brush:js">
$(function() {
    getMessages = function() {
        $.getJSON('index.php?action=get_last_messages', function(data){
            if (data.messages) {
                $('.chat_messages').html(data.messages);
            }

            // get recent chat messages in loop
            setTimeout(function(){
               getMessages();
            }, 5000);
        });
    }
    getMessages();

    $('.chat_submit_form').submit(function() {
        $.post('index.php', { message: $('.chat_submit_form input[name=message]').val() },
            function(data){
                if (data.result == 1) {
                    $('.chat_submit_form .success').fadeIn('slow', function () {
                        $(this).delay(1000).fadeOut('slow');
                    });
                } else if (data.result == 2) {
                    $('.chat_submit_form .protect').fadeIn('slow', function () {
                        $(this).delay(1000).fadeOut('slow');
                    });
                } else {
                    $('.chat_submit_form .error').fadeIn('slow', function () {
                        $(this).delay(1000).fadeOut('slow');
                    });
                }
            }
        );
        return false;
    });
});
</pre><h3>Step 5. PHP</h3><p>Now, lets review php sources:</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

// set error reporting level
if (version_compare(phpversion(), '5.3.0', '&gt;=') == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
else
  error_reporting(E_ALL &amp; ~E_NOTICE);

require_once('classes/Services_JSON.php');
require_once('classes/CMySQL.php'); // including service class to work with database
require_once('classes/CLogin.php'); // including service class to work with login processing

// login system init and generation code
$sLoginForm = $GLOBALS['CLogin']-&gt;getLoginBox();

$sChat = '&lt;h2&gt;You do not have rights to use chat&lt;/h2&gt;';
$sInput = '';
if ($_SESSION['member_id'] &amp;&amp; $_SESSION['member_status'] == 'active' &amp;&amp; $_SESSION['member_role']) {
    require_once('classes/CChat.php'); // including service class to work with chat

    // get last messages
    $sChat = $GLOBALS['MainChat']-&gt;getMessages();
    if ($_GET['action'] == 'get_last_messages') { // regular updating of messages in chat
        $oJson = new Services_JSON();
        header('Content-type: application/json');
        echo $oJson-&gt;encode(array('messages' =&gt; $sChat));
        exit;
    }

    // get input form
    $sInput = $GLOBALS['MainChat']-&gt;getInputForm();

    if ($_POST['message']) { // POST-ing of message
        $iRes = $GLOBALS['MainChat']-&gt;acceptMessage();

        $oJson = new Services_JSON();
        header('Content-type: application/json');
        echo $oJson-&gt;encode(array('result' =&gt; $iRes));
        exit;
    }
}

// draw common page
echo strtr(file_get_contents('templates/main_page.html'), array('{form}' =&gt; $sLoginForm, '{chat}' =&gt; $sChat, '{input}' =&gt; $sInput));
</pre><p>As you can see &#8211; I have added chat functionality today.</p><h4>classes/CLogin.php</h4><pre class="brush:php">
&lt;?php

class CLogin {

    // constructor
    function CLogin() {
        session_start();
    }

    // get login box function
    function getLoginBox() {
        if (isset($_GET['logout'])) { // logout processing
            if (isset($_SESSION['member_name']) &amp;&amp; isset($_SESSION['member_pass']))
                $this-&gt;performLogout();
        }

        if ($_POST &amp;&amp; $_POST['username'] &amp;&amp; $_POST['password']) { // login processing
            if ($this-&gt;checkLogin($_POST['username'], $_POST['password'], false)) { // successful login
                $this-&gt;performLogin($_POST['username'], $_POST['password']);
                header( &quot;Location:{$_SERVER['REQUEST_URI']}&quot; );
                exit;
            } else { // wrong login
                return file_get_contents('templates/login_form.html') . '&lt;h2&gt;Username or Password is incorrect&lt;/h2&gt;';
            }
        } else { // in case if we already logged (on refresh page):
            if (isset($_SESSION['member_name']) &amp;&amp; $_SESSION['member_name'] &amp;&amp; $_SESSION['member_pass']) {
                $aReplaces = array(
                    '{name}' =&gt; $_SESSION['member_name'],
                    '{status}' =&gt; $_SESSION['member_status'],
                    '{role}' =&gt; $_SESSION['member_role'],
                );
                return strtr(file_get_contents('templates/logout_form.html'), $aReplaces);
            }

            // otherwise - draw login form
            return file_get_contents('templates/login_form.html');
        }
    }

    // perform login
    function performLogin($sName, $sPass) {
        $this-&gt;performLogout();

        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        // $sPassEn = $aProfile['password'];
        $iPid = $aProfile['id'];
        $sSalt = $aProfile['salt'];
        $sStatus = $aProfile['status'];
        $sRole = $aProfile['role'];

        $sPass = sha1(md5($sPass) . $sSalt);

        $_SESSION['member_id'] = $iPid;
        $_SESSION['member_name'] = $sName;
        $_SESSION['member_pass'] = $sPass;
        $_SESSION['member_status'] = $sStatus;
        $_SESSION['member_role'] = $sRole;
    }

    // perform logout
    function performLogout() {
        unset($_SESSION['member_id']);
        unset($_SESSION['member_name']);
        unset($_SESSION['member_pass']);
        unset($_SESSION['member_status']);
        unset($_SESSION['member_role']);
    }

    // check login
    function checkLogin($sName, $sPass, $isHash = true) {
        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);
        $sPass = $GLOBALS['MySQL']-&gt;escape($sPass);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        $sPassEn = $aProfile['password'];

        if ($sName &amp;&amp; $sPass &amp;&amp; $sPassEn) {
            if (! $isHash) {
                $sSalt = $aProfile['salt'];
                $sPass = sha1(md5($sPass) . $sSalt);
            }
            return ($sPass == $sPassEn);
        }
        return false;
    }
}

$GLOBALS['CLogin'] = new CLogin();
</pre><p>This class is updated too. I have decided to add &#8216;member_id&#8217; in sessions too. It will useful afterward.</p><h4>classes/CMySQL.php</h4><p>This is database service class. Available in package. Pay attention &#8211; database settings of our project is in this file.</p><h4>classes/Services_JSON.php</h4><p>This is JSON service class. Available in package.</p><h4>classes/CChat.php</h4><pre class="brush:php">
&lt;?php

class CChat {

    // constructor
    function CChat() {}

    // add to DB message
    function acceptMessage() {
        $sName = $GLOBALS['MySQL']-&gt;escape($_SESSION['member_name']);
        $iPid = (int)$_SESSION['member_id'];
        $sMessage = $GLOBALS['MySQL']-&gt;escape($_POST['message']);

        if ($iPid &amp;&amp; $sName != '' &amp;&amp; $sMessage != '') {
            $sSQL = &quot;
                SELECT `id`
                FROM `cs_messages`
                WHERE `sender` = '{$iPid}' AND UNIX_TIMESTAMP( ) - `when` &lt; 5
                LIMIT 1
            &quot;;
            $iLastId = $GLOBALS['MySQL']-&gt;getOne($sSQL);
            if ($iLastId) return 2; // as protection from very often messages

            $bRes = $GLOBALS['MySQL']-&gt;res(&quot;INSERT INTO `cs_messages` SET `sender` = '{$iPid}', `message` = '{$sMessage}', `when` = UNIX_TIMESTAMP()&quot;);
            return ($bRes) ? 1 : 3;
        }
    }

    // return input text form
    function getInputForm() {
        return file_get_contents('templates/chat.html');
    }

    // get last 10 messages
    function getMessages() {
        $sSQL = &quot;
            SELECT `a` . * , `cs_profiles`.`name` , UNIX_TIMESTAMP( ) - `a`.`when` AS 'diff'
            FROM `cs_messages` AS `a`
            INNER JOIN `cs_profiles` ON `cs_profiles`.`id` = `a`.`sender`
            ORDER BY `a`.`id` DESC
            LIMIT 10
        &quot;;
        $aMessages = $GLOBALS['MySQL']-&gt;getAll($sSQL);
        asort($aMessages);

        // create list of messages
        $sMessages = '';
        foreach ($aMessages as $i =&gt; $aMessage) {
            $sExStyles = $sExJS = '';
            $iDiff = (int)$aMessage['diff'];
            if ($iDiff &lt; 7) { // less than 7 seconds
                $sExStyles = 'style=&quot;display:none;&quot;';
                $sExJS = &quot;&lt;script&gt; $('#message_{$aMessage['id']}').fadeIn('slow'); &lt;/script&gt;&quot;;
            }

            $sWhen = date(&quot;H:i:s&quot;, $aMessage['when']);
            $sMessages .= '&lt;div class=&quot;message&quot; id=&quot;message_'.$aMessage['id'].'&quot; '.$sExStyles.'&gt;&lt;b&gt;' . $aMessage['name'] . ':&lt;/b&gt; ' . $aMessage['message'] . '&lt;span&gt;(' . $sWhen . ')&lt;/span&gt;&lt;/div&gt;' . $sExJS;
        }
        return $sMessages;
    }
}

$GLOBALS['MainChat'] = new CChat();
</pre><p>This is our new class for chat processor. For now &#8211; it contain only 3 functions: acceptMessage, getInputForm and getMessages.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 221" href="http://www.script-tutorials.com/demos/221/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/221/source.zip" target="_blank" rel="nofollow">download in archive</a></strong></h5><hr
/><h3>Conclusion</h3><p>I will hope that our new series of articles of chat system creation will be useful and interesting for you. If you want to share your ideas, or you noticed any weakness &#8211; don&#8217;t hesitate to contact us. Good luck and welcome back!</p><div
class="shr-publisher-1373"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/226/thumb.png" alt="Powerful Chat System &#8211; Lesson 3" /> <br
/> Powerful Chat System &#8211; Lesson 3</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/218/thumb.png" alt="Powerful Chat System" /> <br
/> Powerful Chat System</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-ajax-style-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make AJAX Style PHP Chat Application" /> <br
/> How to Easily Make AJAX Style PHP Chat Application</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/powerful-chat-system-lesson-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Isometric interactive interior guide</title><link>http://www.script-tutorials.com/isometric-interactive-interior-guide/</link> <comments>http://www.script-tutorials.com/isometric-interactive-interior-guide/#comments</comments> <pubDate>Tue, 17 Jan 2012 17:37:15 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[inspiration]]></category> <category><![CDATA[interactive guide]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1369</guid> <description><![CDATA[Isometric interactive interior guide During browsing internet, I have noticed new interesting thing &#8211; it looked like isometric guide. Today I will show you how you can create something similar. We will create isometric interactive interior guide with CSS3 and jQuery. Here are samples and downloadable package: Live Demo download in package Ok, download the [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-dialogs-using-ui-dialog/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/40.png" alt="How to create Animated Dialogs using UI Dialog (jQuery)" /> How to create Animated Dialogs using UI Dialog (jQuery)</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/205/thumb.png" alt="HTML5 Game Development &#8211; Lesson 5" /> HTML5 Game Development &#8211; Lesson 5</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Isometric interactive interior guide" alt="Isometric interactive interior guide" src="http://www.script-tutorials.com/demos/220/thumb.png" /></div><p><strong>Isometric interactive interior guide</strong></p><p>During browsing internet, I have noticed new interesting thing &#8211; it looked like isometric guide. Today I will show you how you can create something similar. We will create isometric interactive interior guide with CSS3 and jQuery.</p><p><span
id="more-1369"></span></p><hr
/><p>Here are samples and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="Isometric interactive interior guide - demo 220" href="http://www.script-tutorials.com/demos/220/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Isometric interactive interior guide - package" href="http://www.script-tutorials.com/demos/220/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the example files and lets start coding !</p><hr
/><h3>Step 1. HTML</h3><p>As usual, we start with the HTML. Here is full html code of our guide page. You can see here main scene (container object), six labels on this scene (with some description), and empty dialog element.</p><h4>index.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;Isometric interactive interior guide with CSS3 and jQuery | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/layout.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;js/main.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            &lt;h2&gt;Isometric interactive interior guide&lt;/h2&gt;
            &lt;a href=&quot;http://www.script-tutorials.com/isometric-interactive-interior-guide/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
        &lt;/header&gt;

        &lt;div class=&quot;container&quot;&gt;
            &lt;div class=&quot;labels&quot;&gt;
                &lt;a id=&quot;label1&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;sofa
                    &lt;p&gt;A sofa, is an item of furniture designed to seat more than one person, and providing support for the back and arms.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
                &lt;a id=&quot;label2&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;television
                    &lt;p&gt;Television (TV) is a telecommunication medium for transmitting and receiving moving images that can be monochrome (black-and-white) or colored, with or without accompanying sound.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
                &lt;a id=&quot;label3&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;chest
                    &lt;p&gt;In many video games, especially role-playing video games, treasure chests contain various items, currency, and sometimes monsters.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
                &lt;a id=&quot;label4&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;workplace
                    &lt;p&gt;A virtual workplace is a workplace that is not located in any one physical space.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
                &lt;a id=&quot;label5&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;entrance
                    &lt;p&gt;A door is a movable structure used to open and close off an entrance, typically consisting of a panel that swings on hinges or that slides or rotates inside of a space.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
                &lt;a id=&quot;label6&quot; class=&quot;label&quot; href=&quot;#&quot;&gt;safe room
                    &lt;p&gt;A safe room or panic room is a fortified room which is installed in a private residence or business to provide a safe shelter, or hiding place, for the inhabitants in the event of a break-in, home invasion, tornado, or other threat.&lt;/p&gt;
                    &lt;span /&gt;
                &lt;/a&gt;
            &lt;/div&gt;
            &lt;div class=&quot;dialog&quot;&gt;
                &lt;p&gt;&lt;/p&gt;
                &lt;a class=&quot;close&quot;&gt;X&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Step 2. CSS</h3><p>Now &#8211; CSS styles. Which I have separated into two parts: common page styles and styles of our main scene.</p><h4>css/layout.css</h4><pre class="brush:css">
/* page layout styles */
*{
    margin:0;
    padding:0;
}
body {
    background-color:#fefffa;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
header {
    background-color:#212121;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    position:relative;
    width:100%;
    z-index:100;
}
header h2{
    font-size: 22px;
    font-weight: normal;
    left: 40%;
    margin-left: -300px;
    padding: 22px 0;
    position: absolute;
    width: 1000px;
}
header a.stuts,a.stuts:visited{
    border: none;
    color: #FCFCFC;
    font-size: 14px;
    left: 50%;
    line-height: 31px;
    margin: 23px 0 0 110px;
    position: absolute;
    text-decoration: none;
    top: 0;
}
header .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}

/* demo */
.container {
    background: url(&quot;../images/scene.jpg&quot;) no-repeat scroll center top transparent;
    color: #000000;
    height: 535px;
    margin: 20px auto;
    overflow: hidden;
    position: relative;
    width: 1030px;
}
.dialog {
    background-color: rgba(163, 154, 77, 0.9);
    color: #FFFFFF;
    display: none;
    height: 140px;
    left: 343px;
    line-height: 24px;
    padding: 100px 30px;
    position: absolute;
    text-align: center;
    top: 97px;
    width: 280px;
    z-index: 10;

    -moz-border-radius: 170px;
    -ms-border-radius: 170px;
    -o-border-radius: 170px;
    -webkit-border-radius: 170px;
    border-radius: 170px;
}
.dialog .close {
    background-color: #65683b;
    cursor: pointer;
    font-size: 22px;
    font-weight: bold;
    height: 36px;
    line-height: 36px;
    position: absolute;
    right: 10px;
    top: 60px;
    width: 36px;

    -moz-border-radius: 18px;
    -ms-border-radius: 18px;
    -o-border-radius: 18px;
    -webkit-border-radius: 18px;
    border-radius: 18px;
}
.labels p {
    display: none;
}
.labels a {
    background-color: rgba(203, 189, 58, 0.8);
    color: #FFFFFF;
    display: none;
    height: 50px;
    padding: 30px 0 0;
    position: absolute !important;
    text-align: center;
    text-decoration: none;
    width: 80px;

    -moz-border-radius: 40px;
    -ms-border-radius: 40px;
    -o-border-radius: 40px;
    -webkit-border-radius: 40px;
    border-radius: 40px;
}
.labels &gt; a {
    background-color: rgba(203, 189, 58, 0.8);

    -moz-transition: .3s;
    -ms-transition: .3s;
    -o-transition: .3s;
    -webkit-transition: .3s;
    transition: .3s;
}
.labels a:hover {
    background-color: rgba(128, 128, 128, 0.8);
}
.labels a span {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 15px solid rgba(203, 189, 58, 0.8);
    bottom: -14px;
    height: 0;
    left: 30px;
    position: absolute;
    width: 0;

    -moz-transition: .3s;
    -ms-transition: .3s;
    -o-transition: .3s;
    -webkit-transition: .3s;
    transition: .3s;
}
.labels a:hover span {
    border-top: 15px solid rgba(128, 128, 128, 0.8);
}
#label1 {
    left: 720px;
    top: 215px;
}
#label2 {
    left: 495px;
    top: 290px;
}
#label3 {
    left: 450px;
    top: 115px;
}
#label4 {
    left: 270px;
    top: 170px;
}
#label5 {
    left: 570px;
    top: 65px;
}
#label6 {
    left: 275px;
    top: 30px;
}
</pre><h3>Step 3. JS</h3><p>And now &#8211; our jQuery code:</p><h4>js/main.js</h4><pre class="brush:js">
jQuery(function(){
    // initialize of labels
    $('.labels a#label1').fadeIn(100).effect('bounce', { times:3 }, 300, function() {
        $('.labels a#label2').fadeIn(100).effect('bounce', { times:3 }, 300, function() {
            $('.labels a#label3').fadeIn(100).effect('bounce', { times:3 }, 300, function() {
                $('.labels a#label4').fadeIn(100).effect('bounce', { times:3 }, 300, function() {
                    $('.labels a#label5').fadeIn(100).effect('bounce', { times:3 }, 300, function() {
                        $('.labels a#label6').fadeIn(100).effect('bounce', { times:3 }, 300);
                    });
                });
            });
        });
    });

    // dialog close
    $('.dialog .close').click(function() {
        $(this).parent().fadeOut(500);
        return false;
    });

    // display dialog on click by labels
    $('.labels a').click(function() {
        $('.dialog p').html( $(this).find('p').html() ).parent().fadeIn(500);
        return false;
    });

    // close dialog on click outside
    $('.container').click(function() {
        $('.dialog').fadeOut(500);
    });
});
</pre><p>Here are just a few event handlers of our scene objects.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Isometric interactive interior guide - demo 220" href="http://www.script-tutorials.com/demos/220/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Isometric interactive interior guide - package" href="http://www.script-tutorials.com/demos/220/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I will happy if our material will useful for you, and can bring you some inspiration. Don&#8217;t forget telling thanks and leaving a comment. <img
src='http://www.script-tutorials.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> Good luck!</p><div
class="shr-publisher-1369"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/how-to-create-dialogs-using-ui-dialog/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/40.png" alt="How to create Animated Dialogs using UI Dialog (jQuery)" /> <br
/> How to create Animated Dialogs using UI Dialog (jQuery)</a></li><li> <a
href="http://www.script-tutorials.com/html5-game-development-lesson-5/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/205/thumb.png" alt="HTML5 Game Development &#8211; Lesson 5" /> <br
/> HTML5 Game Development &#8211; Lesson 5</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/isometric-interactive-interior-guide/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Powerful Chat System</title><link>http://www.script-tutorials.com/powerful-chat-system/</link> <comments>http://www.script-tutorials.com/powerful-chat-system/#comments</comments> <pubDate>Fri, 13 Jan 2012 14:14:57 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[AJAX]]></category> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[ajax chat]]></category> <category><![CDATA[chat]]></category> <category><![CDATA[chat system]]></category> <category><![CDATA[profiles]]></category> <category><![CDATA[registration]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1360</guid> <description><![CDATA[Powerful Chat System Today we begin a series of articles on the creation of powerful chat system. The system will contain next elements: registration, login processing, main chat, profiles with avatars, ranking system (of profiles), private messaging, custom rooms, moderation / administration and possible something else (in future). This will be ajax chat PHP) with [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/226/thumb.png" alt="Powerful Chat System &#8211; Lesson 3" /> Powerful Chat System &#8211; Lesson 3</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/221/thumb.png" alt="Powerful Chat System &#8211; Lesson 2" /> Powerful Chat System &#8211; Lesson 2</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-a-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make a PHP Chat Application" /> How to Easily Make a PHP Chat Application</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Powerful Chat System" alt="Powerful Chat System" src="http://www.script-tutorials.com/demos/218/thumb.png"></div><p><strong>Powerful Chat System</strong><br
/> <br
/>Today we begin a series of articles on the creation of powerful chat system. The system will contain next elements: registration, login processing, main chat, profiles with avatars, ranking system (of profiles), private messaging, custom rooms, moderation / administration and possible something else (in future). This will be ajax chat PHP) with storing messages in database (MySQL). Plus we will implement CSS3/HTML5 features in our development process.<br
/> <span
id="more-1360"></span></p><p>Today I have included next elements: initial code (PHP + SQL) with login processor. All project will be well structured: system classes is in &#8216;classes&#8217; folder, stylesheets in &#8216;css&#8217; folder, template files in &#8216;templates&#8217; folder.</p><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 218" href="http://www.script-tutorials.com/demos/218/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/218/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Now &#8211; download the source files and lets start coding !</p><hr
/><h3>Step 1. SQL</h3><p>Here is SQL structure of tables for profiles and messages</p><pre class="brush:sql">
CREATE TABLE `cs_profiles` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `last_name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `password` varchar(40) NOT NULL default '',
  `salt` varchar(10) NOT NULL default '',
  `status` enum('active','passive') NOT NULL default 'active',
  `role` tinyint(4) unsigned NOT NULL default '1',
  `about` varchar(255) NOT NULL,
  `date_reg` datetime NOT NULL default '0000-00-00 00:00:00',
  `rate` float NOT NULL,
  `rate_count` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

INSERT INTO `cs_profiles` (`name`, `last_name`, `email`, `password`, `salt`, `status`, `role`, `about`, `date_reg`, `rate`, `rate_count`) VALUES
('test user', 'test user last name', 'user@user.com', 'b88c654d6c68fc37f4dda1d29935235eea9a845b', 'testing', 'active', 1, 'Few words about test user', '2012-01-14 00:00:00', 0, 0),
('moderator', 'moderator last name', 'moderator@moderator.com', 'b88c654d6c68fc37f4dda1d29935235eea9a845b', 'testing', 'active', 4, 'Few words about moderator', '2012-01-14 00:00:00', 0, 0),
('admin', 'admin last name', 'admin@admin.com', 'b88c654d6c68fc37f4dda1d29935235eea9a845b', 'testing', 'active', 5, 'Few words about admin', '2012-01-14 00:00:00', 0, 0);

CREATE TABLE `cs_messages` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `sender` int(11) unsigned NOT NULL,
  `recipient` int(11) unsigned NOT NULL default '0',
  `message` VARCHAR(255) NOT NULL,
  `when` TIMESTAMP NOT NULL default CURRENT_TIMESTAMP,
  `room` int(5) unsigned NOT NULL default '0',
  `type` tinyint(1) unsigned NOT NULL default '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
</pre><p>I have added 3 profiles in the system. Each of them have different role. I plan to make ordinary members (1), moderators (4), administrators (5). You can use another roles (as example 2 and 3) for any other purposes (paid members?). And, quite forgot &#8211; password for all of them is <b>&#8216;password&#8217;</b>. So you can login as &#8216;test user&#8217; -> &#8216;password&#8217;, &#8216;moderator&#8217; -> &#8216;password&#8217; and &#8216;admin&#8217; -> &#8216;password&#8217;. Registration process will in next article.</p><h3>Step 2. HTML</h3><p>This is main (index) page html markup:</p><h4>templates/main_page.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
&lt;head&gt;
    &lt;title&gt;Powerful Chat System&lt;/title&gt;
    &lt;link href=&quot;css/main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;header&gt;
        &lt;h2&gt;Powerful Chat System&lt;/h2&gt;
        &lt;a href=&quot;http://www.script-tutorials.com/powerful-chat-system/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
    &lt;/header&gt;
    &lt;div class=&quot;container&quot;&gt;
        {form}
    &lt;/div&gt;
    &lt;div class=&quot;container&quot;&gt;
        {chat}
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre><p>It is easy layout, isn&#8217;t it?. Now, next template file for login form:</p><h4>templates/login_form.html</h4><pre class="brush:html">
&lt;div class=&quot;column&quot;&gt;
    &lt;h3&gt;Powerful Chat System Demonstration&lt;/h3&gt;
    &lt;p&gt;Our chat will contain next features: registration, main chat, profiles with avatars, ranking system, private messaging, custom rooms, moderation / administration and possible something else (in future).&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
    &lt;form class=&quot;login_form&quot; action=&quot;index.php&quot; method=&quot;post&quot;&gt;
        &lt;h3&gt;Log In&lt;/h3&gt;
        &lt;label&gt;Username:&lt;/label&gt;&lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;
        &lt;label&gt;Password:&lt;/label&gt;&lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;
        &lt;input type=&quot;submit&quot; name=&quot;LogIn&quot; value=&quot;Login&quot;&gt;
    &lt;/form&gt;
&lt;/div&gt;
</pre><p>Next one template &#8211; logout form:</p><h4>logout_form.html</h4><pre class="brush:html">
&lt;div class=&quot;column&quot;&gt;
    &lt;h3&gt;Hello {name}&lt;/h3&gt;
    &lt;h3&gt;Your status:&lt;/h3&gt;
    &lt;div&gt;{status}&lt;/div&gt;
    &lt;h3&gt;Your role:&lt;/h3&gt;
    &lt;div&gt;{role}&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;column&quot;&gt;
    &lt;a href=&quot;index.php?logout&quot;&gt;Log Out&lt;/a&gt;
&lt;/div&gt;
</pre><h3>Step 3. CSS</h3><p>This file contains styles of our page layout</p><h4>css/main.css</h4><pre class="brush:html">
/* page layout */
*{
    margin:0;
    padding:0;
}
body {
    background-color:#eee;
    color:#fff;
    font:14px/1.3 Arial,sans-serif;
}
header {
    background-color:#212121;
    box-shadow: 0 -1px 2px #111111;
    display:block;
    height:70px;
    position:relative;
    width:100%;
    z-index:100;
}
header h2{
    font-size:22px;
    font-weight:normal;
    left:50%;
    margin-left:-400px;
    padding:22px 0;
    position:absolute;
    width:540px;
}
header a.stuts,a.stuts:visited{
    border:none;
    text-decoration:none;
    color:#fcfcfc;
    font-size:14px;
    left:50%;
    line-height:31px;
    margin:23px 0 0 110px;
    position:absolute;
    top:0;
}
header .stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}

/* main styles */
.container {
    background-color:#222;
    color: #bbb;
    margin: 20px auto;
    overflow: hidden;
    padding:20px;
    position: relative;
    width: 800px;
}
.column {
    float:left;
    width:48%;
}
.column:first-child {
    margin-right:4%;
}
.column &gt; * {
    color:#ddd;
    margin-bottom:10px;
}
.column h3 {
    color:#fff;
}
.login_form input,.login_form label {
    display:block;
    margin-bottom:5px;
}
input[type=text],
input[type=password] {
    width:200px;
}
input[type=submit]{
    height:30px;
    margin-top:10px;
    width:72px;
}
</pre><h3>Step 4. PHP</h3><p>Now, lets review php sources:</p><h4>index.php</h4><pre class="brush:php">
&lt;?php

// set error reporting level
if (version_compare(phpversion(), &quot;5.3.0&quot;, &quot;&gt;=&quot;) == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
else
  error_reporting(E_ALL &amp; ~E_NOTICE);

require_once('classes/CMySQL.php'); // including service class to work with database
require_once('classes/CLogin.php'); // including service class to work with login processing

// login system init and generation code
$sLoginForm = $GLOBALS['CLogin']-&gt;getLoginBox();

$sChat = ($_SESSION['member_name'] &amp;&amp; $_SESSION['member_status'] == 'active') ? '&lt;h2&gt;TODO chat&lt;/h2&gt;' : '&lt;h2&gt;You have to login before use chat&lt;/h2&gt;';

echo strtr(file_get_contents('templates/main_page.html'), array('{form}' =&gt; $sLoginForm, '{chat}' =&gt; $sChat));
</pre><p>As we need only login processing for today &#8211; our index file is pretty small. New functional will appear in further articles. Here is sources of our login processor:</p><h4>classes/CLogin.php</h4><pre class="brush:php">
&lt;?php

class CLogin {

    // constructor
    function CLogin() {
        session_start();
    }

    // get login box function
    function getLoginBox() {
        if (isset($_GET['logout'])) { // logout processing
            if (isset($_SESSION['member_name']) &amp;&amp; isset($_SESSION['member_pass']))
                $this-&gt;performLogout();
        }

        if ($_POST &amp;&amp; $_POST['username'] &amp;&amp; $_POST['password']) { // login processing
            if ($this-&gt;checkLogin($_POST['username'], $_POST['password'], false)) { // successful login
                $this-&gt;performLogin($_POST['username'], $_POST['password']);
                header( &quot;Location:{$_SERVER['REQUEST_URI']}&quot; );
                exit;
            } else { // wrong login
                return file_get_contents('templates/login_form.html') . '&lt;h2&gt;Username or Password is incorrect&lt;/h2&gt;';
            }
        } else { // in case if we already logged (on refresh page):
            if (isset($_SESSION['member_name']) &amp;&amp; $_SESSION['member_name'] &amp;&amp; $_SESSION['member_pass']) {
                $aReplaces = array(
                    '{name}' =&gt; $_SESSION['member_name'],
                    '{status}' =&gt; $_SESSION['member_status'],
                    '{role}' =&gt; $_SESSION['member_role'],
                );
                return strtr(file_get_contents('templates/logout_form.html'), $aReplaces);
            }

            // otherwise - draw login form
            return file_get_contents('templates/login_form.html');
        }
    }

    // perform login
    function performLogin($sName, $sPass) {
        $this-&gt;performLogout();

        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        // $sPassEn = $aProfile['password'];
        $sSalt = $aProfile['salt'];
        $sStatus = $aProfile['status'];
        $sRole = $aProfile['role'];

        $sPass = sha1(md5($sPass) . $sSalt);

        $_SESSION['member_name'] = $sName;
        $_SESSION['member_pass'] = $sPass;
        $_SESSION['member_status'] = $sStatus;
        $_SESSION['member_role'] = $sRole;
    }

    // perform logout
    function performLogout() {
        unset($_SESSION['member_name']);
        unset($_SESSION['member_pass']);
        unset($_SESSION['member_status']);
        unset($_SESSION['member_role']);
    }

    // check login
    function checkLogin($sName, $sPass, $isHash = true) {
        // make variables safe
        $sName = $GLOBALS['MySQL']-&gt;escape($sName);
        $sPass = $GLOBALS['MySQL']-&gt;escape($sPass);

        $aProfile = $GLOBALS['MySQL']-&gt;getRow(&quot;SELECT * FROM `cs_profiles` WHERE `name`='{$sName}'&quot;);
        $sPassEn = $aProfile['password'];

        if ($sName &amp;&amp; $sPass &amp;&amp; $sPassEn) {
            if (! $isHash) {
                $sSalt = $aProfile['salt'];
                $sPass = sha1(md5($sPass) . $sSalt);
            }
            return ($sPass == $sPassEn);
        }
        return false;
    }
}

$GLOBALS['CLogin'] = new CLogin();
</pre><p>I hope you still remember our <a
href="http://www.script-tutorials.com/creating-advance-level-login-system-with-logic-captcha/" target="_blank">previous article of advanced login system</a>. We will have similar system with using sha1 + md5 encryption. All profiles will kept in database.</p><h4>classes/CMySQL.php</h4><p>This is database service class. Available in package. Pay attention &#8211; database settings of our project is in this file.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - demo 218" href="http://www.script-tutorials.com/demos/218/index.php" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Powerful Chat System - package" href="http://www.script-tutorials.com/demos/218/source.zip" target="_blank" rel="nofollow">download in archive</a></strong></h5><hr
/><h3>Conclusion</h3><p>I will hope that our new series of articles of chat system creation will be useful and interesting for you. If you want to share your ideas, or you noticed any weakness &#8211; don&#8217;t hesitate to contact us. Good luck and welcome back!</p><div
class="shr-publisher-1360"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/226/thumb.png" alt="Powerful Chat System &#8211; Lesson 3" /> <br
/> Powerful Chat System &#8211; Lesson 3</a></li><li> <a
href="http://www.script-tutorials.com/powerful-chat-system-lesson-2/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/221/thumb.png" alt="Powerful Chat System &#8211; Lesson 2" /> <br
/> Powerful Chat System &#8211; Lesson 2</a></li><li> <a
href="http://www.script-tutorials.com/how-to-easily-make-a-php-chat-application/" rel="bookmark"> <img
src="/ssimages/no_image.gif" alt="How to Easily Make a PHP Chat Application" /> <br
/> How to Easily Make a PHP Chat Application</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/powerful-chat-system/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Creating photo album with jQuery Fotorama</title><link>http://www.script-tutorials.com/photo-album-with-jquery-fotorama/</link> <comments>http://www.script-tutorials.com/photo-album-with-jquery-fotorama/#comments</comments> <pubDate>Wed, 11 Jan 2012 12:44:06 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Fotorama]]></category> <category><![CDATA[iphone]]></category> <category><![CDATA[photo album]]></category> <category><![CDATA[touch]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1353</guid> <description><![CDATA[Creating photo album with jQuery Fotorama Today I have prepared tutorial about using new impressive jQuery gallery &#8211; Fotorama. This is a nice looking javascript gallery with intuitive controls, and great browser compatibility. You can use this plugin at iPhones and any other mobile devices (you can slide photos with touch). Here are links to [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/creating-photo-album-with-galleriffic-jquery-plugin/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/156/thumb.png" alt="Creating a Photo Album with Galleriffic jQuery plugin" /> Creating a Photo Album with Galleriffic jQuery plugin</a></li><li> <a
href="http://www.script-tutorials.com/creating-photo-album-with-jquery-chop-slider/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/196/thumb.png" alt="Creating photo album with jQuery Chop Slider" /> Creating photo album with jQuery Chop Slider</a></li><li> <a
href="http://www.script-tutorials.com/how-to-create-photo-album-with-tn3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/146/thumb.png" alt="How to Create a Fantastic Photo Album with TN3" /> How to Create a Fantastic Photo Album with TN3</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Creating photo album with jQuery Fotorama" alt="Creating photo album with jQuery Fotorama" src="http://www.script-tutorials.com/demos/216/thumb.png"></div><p><strong>Creating photo album with jQuery Fotorama</strong><br
/> <br
/>Today I have prepared tutorial about using new impressive jQuery gallery &#8211; Fotorama. This is a nice looking javascript gallery with intuitive controls, and great browser compatibility. You can use this plugin at iPhones and any other mobile devices (you can slide photos with touch).<br
/> <span
id="more-1353"></span></p><p>Here are links to demo and downloadable package:</p><h5 style="text-align: center;"><strong><a
title="Creating photo album with jQuery Fotorama - demo 216" href="http://www.script-tutorials.com/demos/216/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating photo album with jQuery Fotorama - package" href="http://www.script-tutorials.com/demos/216/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, lets download the example files and goto coding !</p><hr
/><h3>Step 1. HTML</h3><h4>index.html</h4><p>This is markup of our result page with Fotorama gallery. Here it is.</p><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; &gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;Creating photo album with jQuery Fotorama | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/layout.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
        &lt;link href=&quot;css/fotorama.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
        &lt;script src=&quot;http://code.jquery.com/jquery-latest.min.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;js/fotorama.js&quot;&gt;&lt;/script&gt;
        &lt;script src=&quot;js/main.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;header&gt;
            &lt;h2&gt;Creating photo album with jQuery Fotorama&lt;/h2&gt;
            &lt;a href=&quot;http://www.script-tutorials.com/photo-album-with-jquery-fotorama/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;
        &lt;/header&gt;
        &lt;div class=&quot;container&quot;&gt;

            &lt;div id=&quot;fotorama&quot;&gt;
                &lt;img src=&quot;images/pic1.jpg&quot; alt=&quot;photo #1&quot; /&gt;
                &lt;img src=&quot;images/pic2.jpg&quot; alt=&quot;photo #2&quot; /&gt;
                &lt;img src=&quot;images/pic3.jpg&quot; alt=&quot;photo #3&quot; /&gt;
                &lt;img src=&quot;images/pic4.jpg&quot; alt=&quot;photo #4&quot; /&gt;
                &lt;img src=&quot;images/pic5.jpg&quot; alt=&quot;photo #5&quot; /&gt;
                &lt;img src=&quot;images/pic6.jpg&quot; alt=&quot;photo #6&quot; /&gt;
                &lt;img src=&quot;images/pic7.jpg&quot; alt=&quot;photo #7&quot; /&gt;
                &lt;img src=&quot;images/pic8.jpg&quot; alt=&quot;photo #8&quot; /&gt;
                &lt;img src=&quot;images/pic9.jpg&quot; alt=&quot;photo #9&quot; /&gt;
                &lt;img src=&quot;images/pic10.jpg&quot; alt=&quot;photo #10&quot; /&gt;
                &lt;img src=&quot;images/pic11.jpg&quot; alt=&quot;photo #11&quot; /&gt;
                &lt;img src=&quot;images/pic12.jpg&quot; alt=&quot;photo #12&quot; /&gt;
            &lt;/div&gt;

        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><p>Very easy &#8211; right?</p><h3>Step 2. CSS</h3><h4>css/layout.css and css/fotorama.css</h4><p>First stylesheet is page layout of our page. Second one is default stylesheet file of fotorama gallery. You can customize it (if need). Both files available in our package.</p><h3>Step 3. JS</h3><h4>js/fotorama.js</h4><p>This is main gallery javascript file. It uses jQuery, so we have to include both (fotorama.js and jquery) files. This file available in package.</p><h4>js/main.js</h4><pre class="brush:js">
jQuery(function(){
    $('#fotorama').fotorama({
        // width: 1000, // Width of container
        // height: 600, // Height of container
        startImg: 10, // Initial image
        transitionDuration: 400, // Duration of transition
        touchStyle: true, // Enable dragging
        // pseudoClick: true, // Slide between images by click (if touchStyle = true)
        // loop: false, // Loop for images (if touchStyle = false)
        // backgroundColor: null, // Custom background color
        margin: 10, // Margin between images
        // minPadding: 10, // Min padding
        // alwaysPadding: false, // Apply padding for images
        // preload: 3, // Amount of pre-loaded images from each end of the active image
        // resize: false, // Resize images
        // zoomToFit: true, // Zoom to fit
        // cropToFit: false, // Crop to fit
        // vertical: false, // Vertical thumbs
        // verticalThumbsRight: false, // Vertical thumbs at right
        // arrows: true, // Draw arrows
        arrowsColor: '#3399cc', // Arrows color
        // thumbs: true, // Draw thumbs
        // thumbsBackgroundColor: null, // Thumbs Background Color
        // thumbColor: null, // Thumb Color
        // thumbsPreview: true, // Thumb Preview
        thumbSize: 50, // Thumb size (height)
        // thumbMargin: 5, // Thumb margins
        thumbBorderWidth: 1, // Thumb border width
        // thumbBorderColor: null, // Thumb Border Color
        caption: true, // Display captions
        // html: null, // You can full html code of gallery here
        // onShowImg: null, // Custom function when we select image
        // shadows: true // Display shadows
    });
});
</pre><p>This is main initialization of fotorama gallery. Several styles was customized, another &#8211; no. I have added descriptions of all possible parameters of this gallery.</p><p><a
rel="nofollow" href="http://fotoramajs.com/">Here</a> you can find official documentation of this gallery.</p><h3>Step 4. Images</h3><p>All gallery images is in &#8216;images&#8217; folder.</p><hr
/><h5 style="text-align: center;"><strong><a
title="Creating photo album with jQuery Fotorama - demo 216" href="http://www.script-tutorials.com/demos/216/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Creating photo album with jQuery Fotorama - package" href="http://www.script-tutorials.com/demos/216/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>I hope that today we made new nice photo gallery. Good luck in your projects!</p><div
class="shr-publisher-1353"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/creating-photo-album-with-galleriffic-jquery-plugin/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/156/thumb.png" alt="Creating a Photo Album with Galleriffic jQuery plugin" /> <br
/> Creating a Photo Album with Galleriffic jQuery plugin</a></li><li> <a
href="http://www.script-tutorials.com/creating-photo-album-with-jquery-chop-slider/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/196/thumb.png" alt="Creating photo album with jQuery Chop Slider" /> <br
/> Creating photo album with jQuery Chop Slider</a></li><li> <a
href="http://www.script-tutorials.com/how-to-create-photo-album-with-tn3/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/146/thumb.png" alt="How to Create a Fantastic Photo Album with TN3" /> <br
/> How to Create a Fantastic Photo Album with TN3</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/photo-album-with-jquery-fotorama/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Fullscreen Javascript Slide navigation</title><link>http://www.script-tutorials.com/fullscreen-javascript-slide-navigation/</link> <comments>http://www.script-tutorials.com/fullscreen-javascript-slide-navigation/#comments</comments> <pubDate>Tue, 10 Jan 2012 14:43:02 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[HTML/CSS]]></category> <category><![CDATA[JavaScript]]></category><guid
isPermaLink="false">http://www.script-tutorials.com/?p=1350</guid> <description><![CDATA[Fullscreen Javascript Slide navigation Today &#8211; new pure javascript tutorial-demonstration. Result page will contain 16 slides (pages). Four in each row, four columns, plus we will add animated navigation to them through css3 arrows (at sides of screen). Plus, we will have mini-navigation bar for better navigation. Live Demo download in package Ok, download the [...]<div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/css3-bottom-navigation-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/170/thumb.png" alt="Creating a Toggle CSS3 Bottom Navigation Bar" /> Creating a Toggle CSS3 Bottom Navigation Bar</a></li><li> <a
href="http://www.script-tutorials.com/css3-onclick-vertical-metal-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/162/thumb.png" alt="Creating an Accordian like CSS3 Onclick Vertical Navigation" /> Creating an Accordian like CSS3 Onclick Vertical Navigation</a></li><li> <a
href="http://www.script-tutorials.com/css3-metal-menu-with-icons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/152/thumb.png" alt="Creating a Multilevel CSS3 Metal Navigation with icons" /> Creating a Multilevel CSS3 Metal Navigation with icons</a></li></ol></div>]]></description> <content:encoded><![CDATA[<div
class="thumb"><img
width="128" height="128" class="aligncenter" title="Fullscreen Javascript Slide navigation" alt="Fullscreen Javascript Slide navigation" src="http://www.script-tutorials.com/demos/215/thumb.png" /></div><p><strong>Fullscreen Javascript Slide navigation</strong></p><p>Today &#8211; new pure javascript tutorial-demonstration. Result page will contain 16 slides (pages). Four in each row, four columns, plus we will add animated navigation to them through css3 arrows (at sides of screen). Plus, we will have mini-navigation bar for better navigation.</p><p><span
id="more-1350"></span></p><hr
/><h5 style="text-align: center;"><strong><a
title="Fullscreen Javascript Slide navigation - demo 215" href="http://www.script-tutorials.com/demos/215/index.html" target="_blank">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Fullscreen Javascript Slide navigation - package" href="http://www.script-tutorials.com/demos/215/source.zip" target="_blank">download in package</a></strong></h5><hr
/><p>Ok, download the example files and lets start coding !</p><hr
/><h3>Step 1. HTML markup</h3><p>In our markup you can see 16 &#8216;pages&#8217; and mini-navigation for our slides. Here it is.</p><h4>index.html</h4><pre class="brush:html">
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
    &lt;head&gt;
        &lt;meta charset=&quot;utf-8&quot; /&gt;
        &lt;title&gt;Fullscreen Javascript Slide navigation | Script Tutorials&lt;/title&gt;
        &lt;link href=&quot;css/layout.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;&gt;
        &lt;script src=&quot;js/main.js&quot;&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class=&quot;container&quot; id=&quot;container&quot;&gt;
            &lt;div id=&quot;pages&quot;&gt;
                &lt;div id=&quot;page1&quot;&gt;
                    &lt;a href=&quot;#page2&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page5&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page2&quot;&gt;
                    &lt;a href=&quot;#page1&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page3&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page6&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page3&quot;&gt;
                    &lt;a href=&quot;#page2&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page4&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page7&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page4&quot;&gt;
                    &lt;a href=&quot;#page3&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page8&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page5&quot;&gt;
                    &lt;a href=&quot;#page1&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page6&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page9&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page6&quot;&gt;
                    &lt;a href=&quot;#page5&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page2&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page7&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page10&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page7&quot;&gt;
                    &lt;a href=&quot;#page6&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page3&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page8&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page11&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page8&quot;&gt;
                    &lt;a href=&quot;#page7&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page4&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page12&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page9&quot;&gt;
                    &lt;a href=&quot;#page5&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page10&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page13&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page10&quot;&gt;
                    &lt;a href=&quot;#page9&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page6&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page11&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page14&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page11&quot;&gt;
                    &lt;a href=&quot;#page10&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page7&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page12&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page15&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page12&quot;&gt;
                    &lt;a href=&quot;#page11&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page8&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page16&quot; class=&quot;go bottom&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page13&quot;&gt;
                    &lt;a href=&quot;#page9&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page14&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page14&quot;&gt;
                    &lt;a href=&quot;#page13&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page10&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page15&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page15&quot;&gt;
                    &lt;a href=&quot;#page14&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page11&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page16&quot; class=&quot;go right&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div id=&quot;page16&quot;&gt;
                    &lt;a href=&quot;#page15&quot; class=&quot;go left&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page12&quot; class=&quot;go top&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div id=&quot;nav&quot;&gt;
                &lt;div&gt;Fullscreen Javascript Slide navigation&lt;/div&gt;
                &lt;div style=&quot;width:130px&quot;&gt;
                    &lt;a href=&quot;#page1&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page2&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page3&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page4&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page5&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page6&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page7&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page8&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page9&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page10&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page11&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page12&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page13&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page14&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page15&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                    &lt;a href=&quot;#page16&quot; class=&quot;go&quot;&gt;&lt;/a&gt;
                &lt;/div&gt;
                &lt;div&gt;&lt;a href=&quot;http://www.script-tutorials.com/fullscreen-javascript-slide-navigation/&quot; class=&quot;stuts&quot;&gt;Back to original tutorial on &lt;span&gt;Script Tutorials&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre><h3>Step 2. CSS</h3><p>Now &#8211; stylesheets for our slides:</p><h4>css/layout.css</h4><pre class="brush:css">
*{
    margin:0;
    padding:0;
}
body {
    background-color:#aaa;
    color:#fff;
    font:16px Arial,sans-serif;
    font-weight:700;
    margin:0px;
    padding:0px;
    background:#111;
    width:100%;
    height:100%;
}
a.stuts,a.stuts:visited{
    color: #FCFCFC;
    font-size: 14px;
    text-decoration: none;
}
.stuts span {
    font-size:22px;
    font-weight:bold;
    margin-left:5px;
}
.container {
    position: absolute;
    left: 0;
    top: 0;
    background: #000;
    overflow: hidden;
    width: 100%;
    height: 100%;
}
#pages {
    left:0;
    position:absolute;
    top:0;
}
#nav {
    background-color:rgba(0, 0, 0, 0.8);
    margin:0;
    outline:#333 solid 1px;
    padding:10px;
    position:fixed;
    right:200px;
    top:50px;
    width:200px;
}
#nav div a.go {
    background:#333;
    float:left;
    height:25px;
    margin:3px;
    overflow:hidden;
    text-decoration:none;
    width:25px;
}
#nav div a.go:visited,#nav div a.visited {
    background-color:#666;
}
#nav div a.go:active,#nav div a.active {
    background-color:#fff !important;
}
#nav div a.go:hover,#nav div a.go:focus {
    background-color:#00f;
}
#pages &gt; div {
    height:1100px;
    position:absolute;
    width:1700px;
}
#page1 {
    background:url(../images/1.jpg) no-repeat center center;
    left:0;
    top:0;
}
#page2 {
    background:url(../images/2.jpg) no-repeat center center;
    left:1800px;
    top:0;
}
#page3 {
    background:url(../images/3.jpg) no-repeat center center;
    left:3600px;
    top:0;
}
#page4 {
    background:url(../images/4.jpg) no-repeat center center;
    left:5400px;
    top:0;
}
#page5 {
    background:url(../images/5.jpg) no-repeat center center;
    left:0;
    top:1300px;
}
#page6 {
    background:url(../images/6.jpg) no-repeat center center;
    left:1800px;
    top:1300px;
}
#page7 {
    background:url(../images/7.jpg) no-repeat left center;
    left:3600px;
    top:1300px;
}
#page8 {
    background:url(../images/8.jpg) no-repeat center center;
    left:5400px;
    top:1300px;
}
#page9 {
    background:url(../images/9.jpg) no-repeat center center;
    left:0;
    top:2600px;
}
#page10 {
    background:url(../images/10.jpg) no-repeat center center;
    left:1800px;
    top:2600px;
}
#page11 {
    background:url(../images/11.jpg) no-repeat center center;
    left:3600px;
    top:2600px;
}
#page12 {
    background:url(../images/12.jpg) no-repeat center center;
    left:5400px;
    top:2600px;
}
#page13 {
    background:url(../images/13.jpg) no-repeat center center;
    left:0;
    top:3900px;
}
#page14 {
    background:url(../images/14.jpg) no-repeat center center;
    left:1800px;
    top:3900px;
}
#page15 {
    background:url(../images/15.jpg) no-repeat center center;
    left:3600px;
    top:3900px;
}
#page16 {
    background:url(../images/16.jpg) no-repeat center center;
    left:5400px;
    top:3900px;
}
#pages .left {
    border-bottom:transparent solid 50px;
    border-right:#FFF solid 80px;
    border-top:transparent solid 50px;
    height:0;
    left:20px;
    position:absolute;
    top:50%;
    width:0;
}
#pages .right {
    border-bottom:transparent solid 50px;
    border-left:#FFF solid 80px;
    border-top:transparent solid 50px;
    height:0;
    position:absolute;
    right:20px;
    top:50%;
    width:0;
}
#pages .top {
    border-bottom:#FFF solid 80px;
    border-left:transparent solid 50px;
    border-right:transparent solid 50px;
    height:0;
    left:50%;
    position:absolute;
    top:20px;
    width:0;
}
#pages .bottom {
    border-left:transparent solid 50px;
    border-right:transparent solid 50px;
    border-top:#FFF solid 80px;
    bottom:20px;
    height:0;
    left:50%;
    position:absolute;
    width:0;
}
#pages .left:hover {
    border-right:red solid 80px;
}
#pages .right:hover {
    border-left:red solid 80px;
}
#pages .top:hover {
    border-bottom:red solid 80px;
}
#pages .bottom:hover {
    border-top:red solid 80px;
}
#nav &gt; div {
    margin:10px auto;
    overflow:hidden;
    text-align:center;
}
</pre><h3>Step 3. JS</h3><p>ANd now &#8211; our javascript code:</p><h4>js/main.js</h4><pre class="brush:js">
var navi = {
    // variables
    aPages : [],
    aLinks : [],
    tween : {},
    oParent : null,
    oPages : null,
    bRunning : null,
    sTargPage : null,
    sCurPage : null,
    bHash : null,
    sOldH : null,
    bUpdateH : true,

    // initialization
    init : function (aParams) {
        this.oPages = document.getElementById(aParams.pages_id);
        this.oParent  = document.getElementById(aParams.parent_id);

        var aAEls = this.oParent.getElementsByTagName('a');
        var i = 0; var p = null;
        while (p = aAEls[i++]) {
            if (p.className &amp;&amp; p.className.indexOf('go') &gt;= 0) {
                var sHref = p.href.split('#')[1];
                var oDst = document.getElementById(sHref);
                if (oDst) {
                    // fill-in pages array
                    this.aPages[sHref] = {
                        oObj:  oDst,
                        iXPos: -oDst.offsetLeft,
                        iYPos: -oDst.offsetTop
                    };

                    // fill-in links array
                    this.aLinks.push({a: p, oObj: oDst});

                    p.onclick = function () {
                        navi.goto(this.href.split('#')[1], aParams.duration);
                        return false;
                    }
                }
            }
        }

        this.resize();

        if ('onhashchange' in window) {
            if (location.hash !== '' &amp;&amp; location.hash !== '#') {
                this.sOldH = location.hash.substring(1);
                this.goto(this.sOldH, -1);
            } else
                this.goto('page1', -1);
            this.bHash = true;

            window.onhashchange = function() {
                if (location.hash.substring(1) !== navi.sOldH) {
                    navi.sOldH = location.hash.substring(1);
                    if (navi.sOldH == '') {
                        navi.bUpdateH = false;
                    }
                    navi.goto(navi.sOldH, aParams.duration);
                }
                return false;
            }
        }
    },

    // on resize
    resize : function () {
        var iCurW = this.oParent.offsetWidth; // current sizes
        var iCurH = this.oParent.offsetHeight;
        for (var i in this.aPages) { // for each page
            var oPage = this.aPages[i];
            var iNewX = Math.round(oPage.oObj.offsetLeft * iCurW / oPage.oObj.offsetWidth); // new sizes
            var iNewY = Math.round(oPage.oObj.offsetTop  * iCurH / oPage.oObj.offsetHeight);
            oPage.oObj.style.left   = iNewX + 'px';
            oPage.oObj.style.top    = iNewY + 'px';
            oPage.oObj.style.width  = iCurW + 'px';
            oPage.oObj.style.height = iCurH + 'px';
            oPage.iXPos = -iNewX;
            oPage.iYPos = -iNewY;

            if (this.sCurPage)
                this.goto(this.sCurPage, -1);
        }
    },

    goto : function (sHref, iDur) {
        this.tween.iStart = new Date() * 1;
        this.tween.iDur = iDur;
        this.tween.fromX = this.oPages.offsetLeft;
        this.tween.fromY = this.oPages.offsetTop;
        this.tween.iXPos   = this.aPages[sHref].iXPos - this.tween.fromX;
        this.tween.iYPos   = this.aPages[sHref].iYPos - this.tween.fromY;
        this.sTargPage = sHref;

        if (! this.bRunning)
            this.bRunning = window.setInterval(this.animate, 24);
    },

    animate : function () {
        var iCurTime = (new Date() * 1) - navi.tween.iStart;
        if (iCurTime &lt; navi.tween.iDur) {
            var iCur = Math.cos(Math.PI * (iCurTime / navi.tween.iDur)) - 1;
            navi.oPages.style.left = Math.round(-navi.tween.iXPos * .5 * iCur + navi.tween.fromX) + 'px';
            navi.oPages.style.top  = Math.round(-navi.tween.iYPos * .5 * iCur + navi.tween.fromY) + 'px';
        } else {
            navi.oPages.style.left = Math.round(navi.tween.fromX + navi.tween.iXPos) + 'px';
            navi.oPages.style.top  = Math.round(navi.tween.fromY + navi.tween.iYPos) + 'px';

            window.clearInterval(navi.bRunning);
            navi.bRunning = false;
            navi.sCurPage = navi.sTargPage;

            var i = 0; var p = null;
            while (p = navi.aLinks[i++]) {
                if (p.oObj.id == navi.sCurPage) {
                    if (p.a.className.indexOf('visited') &gt;= 0 ) {
                        p.a.className = p.a.className.replace('visited', 'active');
                    } else p.a.className += ' active';
                    p.visited = true;
                } else if (p.visited) {
                    p.a.className = p.a.className.replace('active', 'visited');
                }
            }

            if (navi.bHash) {
                if (navi.bUpdateH) {
                    navi.sOldH = navi.sCurPage;
                    window.location.hash = navi.sCurPage;
                }
                navi.bUpdateH = true;
            }
        }
    }
}

window.onload = function() { // page onload
    navi.init({parent_id: 'container', pages_id: 'pages', duration: 1000});
}
window.onkeydown = function(event){ // keyboard alerts
    switch (event.keyCode) {
        case 37: // Left key
            var iPage = navi.sCurPage.substring(4) * 1;
            iPage--;
            if (iPage &lt; 1) {
                iPage = 1;
            }
            navi.goto('page' + iPage, 1000);
            break;
        case 39: // Right key
            var iPage = navi.sCurPage.substring(4) * 1;
            iPage++;
            if (iPage &gt; 16) {
                iPage = 16;
            }
            navi.goto('page' + iPage, 1000);
            break;
    }
};
</pre><hr
/><h5 style="text-align: center;"><strong><a
title="Fullscreen Javascript Slide navigation - demo 215" href="http://www.script-tutorials.com/demos/215/index.html" target="_blank" rel="nofollow">Live Demo</a></strong></h5><h5 style="text-align: center;"><strong><a
title="Fullscreen Javascript Slide navigation - package" href="http://www.script-tutorials.com/demos/215/source.zip" target="_blank" rel="nofollow">download in package</a></strong></h5><hr
/><h3>Conclusion</h3><p>Finally we have prepared interested result! I hope that this will interesting addition to your website. Don&#8217;t forget to tell thanks and leave a comment. Good luck!</p><div
class="shr-publisher-1350"></div><div
id="main-related"><h4>Related Stuff You Will Love!</h4><ol
class="related-posts"><li> <a
href="http://www.script-tutorials.com/css3-bottom-navigation-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/170/thumb.png" alt="Creating a Toggle CSS3 Bottom Navigation Bar" /> <br
/> Creating a Toggle CSS3 Bottom Navigation Bar</a></li><li> <a
href="http://www.script-tutorials.com/css3-onclick-vertical-metal-menu/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/162/thumb.png" alt="Creating an Accordian like CSS3 Onclick Vertical Navigation" /> <br
/> Creating an Accordian like CSS3 Onclick Vertical Navigation</a></li><li> <a
href="http://www.script-tutorials.com/css3-metal-menu-with-icons/" rel="bookmark"> <img
src="http://www.script-tutorials.com/demos/152/thumb.png" alt="Creating a Multilevel CSS3 Metal Navigation with icons" /> <br
/> Creating a Multilevel CSS3 Metal Navigation with icons</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://www.script-tutorials.com/fullscreen-javascript-slide-navigation/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching using disk: basic

Served from: www.script-tutorials.com @ 2012-02-04 21:55:30 -->
