<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2" -->
<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/"
	>

<channel>
	<title>DHTML Central Blog</title>
	<link>http://www.dhtmlcentral.com/dhtmlog</link>
	<description>Official DHTML-Central Blog: DHTML, Ajax, Web 2.0</description>
	<pubDate>Sun, 27 Jan 2008 11:36:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<item>
		<title>Rambo 4 Trailer</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/rambo-4-trailer.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/rambo-4-trailer.php#comments</comments>
		<pubDate>Mon, 28 May 2007 18:16:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Just4Fun]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/rambo-4-trailer.php</guid>
		<description><![CDATA[Now on youtube, the brand new rambo 4 trailer:
First official John Rambo (Rambo 4) teaser!



]]></description>
			<content:encoded><![CDATA[<p>Now on youtube, the brand new rambo 4 trailer:</p>
<p>First official John Rambo (Rambo 4) teaser!<br />
<object width="425" height="350">
<param name="movie" value="http://www.youtube.com/v/Rx6i090FGzQ"></param>
<param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Rx6i090FGzQ" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/rambo-4-trailer.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Tutorials back online!</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/tutorials-back-online.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/tutorials-back-online.php#comments</comments>
		<pubDate>Sun, 27 May 2007 22:06:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/tutorials-back-online.php</guid>
		<description><![CDATA[I´ve added the old DHTML Tutorials on the dhtml central blog.
Have Fun!
PS - This is not the final layout!
111111
]]></description>
			<content:encoded><![CDATA[<p>I´ve added the old <a href="http://www.dhtmlcentral.com/dhtmlog/dhtml-tutorials">DHTML Tutorials</a> on the dhtml central blog.</p>
<p>Have Fun!</p>
<p>PS - This is not the final layout!</p>
<p><code>111111</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/tutorials-back-online.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Making a standards supporting page and menu script</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/making-a-standards-supporting-page-and-menu-script.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/making-a-standards-supporting-page-and-menu-script.php#comments</comments>
		<pubDate>Sun, 27 May 2007 22:00:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/making-a-standards-supporting-page-and-menu-script.php</guid>
		<description><![CDATA[Intro
In this tutorial I would like to take up some issues about making a site and a menu script that actually follows the standards.
Ok, let&#8217;s get an overview over the situation: I want to make a simple site in XHTML , I want it to work in ALL browsers and internet devices. But for the [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Intro</h3>
<p>In this tutorial I would like to take up some issues about making a site and a menu script that actually follows the standards.</p>
<p>Ok, let&#8217;s get an overview over the situation: I want to make a simple site in XHTML , I want it to work in ALL browsers and internet devices. But for the browsers that  supports it I want to make a neat menu system.</p>
<p>Because we want to (and can) make the content of the site view able no matter what we  have to take into consideration a lot of different things; browsers that doesn&#8217;t support stylesheets and/or scripting, browsers that have stylesheets and/or scripting disabled or even PDA&#8217;s with small screens et cetera. This means that as a opposite to most of  the scripts found on this site the menu have to initially work, then we add scripting and styling.</p>
<pre>
<h3 class="clWinHeading">Making the initial page</h3>
</pre>
<p>.<br />
We start by making the actual page, I will keep it very simple.  First I&#8217;ll make a logo div:</p>
<pre>
<h2 id="logo">My Personal Site</h2>
</pre>
<p>Then the menu, I&#8217;ll make it as an unordered list. That way it will look ok in non-style browsers:</p>
<pre>&lt;ul&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;About me&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href="#"&gt;Pictures&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="#"&gt;CV&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;

	&lt;li&gt;
		&lt;a href="#"&gt;Portfolio&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href="#"&gt;Sites&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="#"&gt;Design&lt;/a&gt;&lt;/li&gt;
			&lt;li&gt;&lt;a href="#"&gt;Other projects&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;a href="#"&gt;Weblog&lt;/a&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;a href="#"&gt;Archive&lt;/a&gt;&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ul&gt;</pre>
<p>Then some content:</p>
<pre>&lt;div id="content"&gt;
	&lt;h3&gt;Welcome to my homepage&lt;/h3&gt;
	&lt;p&gt;
	Here you can
	learn everything about me.
	&lt;/p&gt;

	[dummy text]

&lt;/div&gt;</pre>
<p>And last but not least the very important and always needed copyright notice:</p>
<pre>&lt;div id="content"&gt;
	© Copyright 2002 Thomas Brattli</pre>
<h3 class="clWinHeading">Styling up the page</h3>
<p>Again for simplicity of this article I will keep the layout simple. We&#8217;ll place the logo on the top, the menu on the right side (just to be different from all the left side menus :} ), the content on the left and the copyright at the bottom.<br />
<a href="http://www.dhtmlcentral.com/tutorials/page2.html" target="__blank">View the page</a>.</p>
<p>The stylesheet added looks like this:</p>
<pre>&lt;style type="text/css"&gt;
body{
	font-family: sans-serif;
	padding-left:5%;
	padding-right:5%;
}
#logo{
	font-size:2em;
	border-bottom:1px dotted silver;
	color:silver;
}
#myMenu{
	float:right;
	width:25%;
}
#content{
	float:left;
	width:70%;
	font-size:0.8em
}
#copyright{
	clear:both;
	border-top:1px solid silver;
	margin-top:20px;
	text-align:right;
	padding-right:5px;
	font-size:0.5em;
}
&lt;/style&gt;</pre>
<p>It&#8217;s pretty straigh-forward stuff so I will not go more into that. By now you are probably very impressed with my stylistic powers, but there&#8217;s still a lot to do. Next we want to style up the menu.</p>
<h3 class="clWinHeading">Styling up the menu and adding script</h3>
<p class="clContent"> Because this could be used on large menus I don&#8217;t want to set any classnames or anything on the individual menu items so instead I make a function that will loop the entire three and set the classnames for me (note that I added an ID &#8220;myMenu&#8221; to the top UL  surrounding the menu so I can reach it):</p>
<pre>function loopElements(el,level){
 for(var i=0;i&lt;el.childNodes.length;i++){
  //We only want LI nodes:
  if(el.childNodes[i] &amp;&amp; el.childNodes[i]["tagName"]
   &amp;&amp; el.childNodes[i].tagName.toLowerCase() == "li"){
   //Ok we have the LI node - let's give it a className
   el.childNodes[i].className = "myMenu"+level
   //Let's look for the A and if it has child elements
   childs = el.childNodes[i].childNodes
   for(var j=0;j&lt;childs.length;j++){
     temp = childs[j]
     if(temp &amp;&amp; temp["tagName"]){
       if(temp.tagName.toLowerCase() == "a"){
       //We found the A tag - set class
       temp.className = "myMenu"+level
      }else if(temp.tagName.toLowerCase() == "ul"){
       //Set class
       temp.className= "myMenu"+level
       //Recursive - calling itself with new element
       //to go all the way through the three.
       loopElements(temp,level +1)
     }
    }
   }
  }
 }
}</pre>
<p>This cute little function will loop any UL three you give it, and set classNames to all the LI, UL and A tags. It&#8217;s recursive so it can be used on as many levels at you want. After running this function, called like this:</p>
<pre>var menu = document.getElementById("myMenu") //Get menu div
menu.className="myMenu"+0 //Set class to the top level
loopElements(menu,0) //Call the function</pre>
<p>it will set the className <code>"myMenu"+level</code> to all elements. Which means that to style up all the top level <code>li</code> tags I go like this:</p>
<pre>li.myMenu0{
	margin:0;
	padding:0;
	list-style : none;
}</pre>
<p>And to style up the actual text I go like this:</p>
<pre>a.myMenu0{
	display:block;
	position:relative;
	background-color:silver;
	padding:3px;
	text-decoration:none;
	color:Navy;
	border:1px solid red;
	margin-top:10px;
}</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/page3.html" target="_blank">View the page</a> (I really need to start making better looking examples)</p>
<p>But it still doesn&#8217;t *do* anything. I&#8217;ll add one line to the script which makes all level 1+ <code>ul</code> tags hidden:</p>
<pre>}else if(temp.tagName.toLowerCase() == "ul"){
	//ADDED LINE:
	temp.style.display = "none"
	//Set class
	temp.className= "myMenu"+level
	//Recursive - calling it self with the new found element
	//to go all the way through the three.
	loopElements(temp,level +1)
}</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/page4.html" target="_blank">View the page</a><br />
Now we&#8217;re getting somewhere, only the main items are open by default, now we just have to add some code that will enable us to open them again onclick:</p>
<pre>function showHide(){
	//We have a A tag - need to go to the LI tag to check for UL tags:
	el = this.parentNode
	//Loop for UL tags:
	for(var i=0;i&lt;el.childNodes.length;i++){
		temp = el.childNodes[i]
		if(temp &amp;&amp; temp["tagName"]
      &amp;&amp; temp.tagName.toLowerCase() == "ul"){
			//Check status:
			if(temp.style.display=="none"){
				temp.style.display = ""
			}else{
				temp.style.display = "none"
			}
		}
	}
	return false
}</pre>
<p>We add a onclick event to the <code>a</code> tags:</p>
<pre>if(temp.tagName.toLowerCase() == "a"){
	//We found the A tag - let's style it
	temp.className = "myMenu"+level
	//ADDED LINE
	temp.onclick = showHide;
} et cetera...</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/page5.html" target="_blank">View the page</a></p>
<p>Wow, it&#8217;s working :) We add some styles, and some small script parts and we end up with this:</p>
<p><a href="http://www.dhtmlcentral.com/tutorials/page6.html" target="_blank">View the page</a></p>
<h3 class="clWinHeading">More examples</h3>
<p>Just for fun I&#8217;ll show you how easy it is to change the entire layout of this page with some simple adjustments to the stylesheet. Remember, still same XHTML  markup and same menuscript.</p>
<p><a href="http://www.dhtmlcentral.com/tutorials/page7.html" target="_blank">View the page</a></p>
<p><a href="http://www.dhtmlcentral.com/tutorials/page8.html" target="_blank">View the page</a></p>
<h3 class="clWinHeading">Summary</h3>
<h3>Summary</h3>
<p>All examples can be validated at w3c:<br />
<a href="http://validator.w3.org/check?uri=http%3A//www.dhtmlcentral.com/tutorials/page6.html" target="_blank">Validate xhtml1.1</a><br />
<a href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.dhtmlcentral.com/tutorials/page6.html" target="_blank">Validate css</a><br />
Or  <a href="http://www.delorie.com/web/lynxview.cgi?url=http%3A%2F%2Fwww.dhtmlcentral.com%2Ftutorials%2Fpage6.html" target="_blank">viewed with Lynx</a></p>
<p>All the examples in this article can be viewed on any browser, any screen-size and with or without style/script support. The content will be accessible  even though the style and scripting might not be (I know it&#8217;s not *perfect*, but it works as an example).</p>
<p><strong>NOTE:</strong> In this article I have surfaced a lot of different standards and accessibility concerns. Hopefully this site will soon give you more detailed information about some of the subjects.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/making-a-standards-supporting-page-and-menu-script.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic data using the DOM and Remote Scripting</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/dynamic-data-using-the-dom-and-remote-scripting.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/dynamic-data-using-the-dom-and-remote-scripting.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:58:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DOM Scripting]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/dynamic-data-using-the-dom-and-remote-scripting.php</guid>
		<description><![CDATA[How it works
As most of you probably know the DOM allows us to dynamically create almost any element that can be on a page, so  we use it to create a SCRIPT tag that we set a src to. When setting the src of a script tag then adding it to the page the [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">How it works</h3>
<p class="clContent">As most of you probably know the DOM allows us to dynamically create almost any element that can be on a page, so  we use it to create a SCRIPT tag that we set a src to. When setting the src of a script tag then adding it to the page the DOM browsers will try to load the script file that we specify.</p>
<p>First I&#8217;ll make a reusable function that we can use to load the new content into the page with:</p>
<pre>function loadContent(file){
  var head = document.getElementsByTagName('head').item(0)
  var scriptTag = document.getElementById('loadScript');
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
}</pre>
<p>Let&#8217;s go line by line;</p>
<pre>var head = document.getElementsByTagName('head').item(0)</pre>
<p>This just makes a short reference to the head element. Used later in the function.</p>
<pre>var scriptTag = document.getElementById('loadScript');</pre>
<p>This line tries to get the script tag called loadScript. The first time this function is called this will return null because the tag does not exists.</p>
<pre>if(scriptTag) head.removeChild(scriptTag);</pre>
<p>If the tag exists we remove it because we don&#8217;t want all the old tags to stay in the page. In explorer you don&#8217;t really have to do this, you  can just set a src to the existing script element but that doesn&#8217;t seem to work in Mozilla.</p>
<pre>script = document.createElement('script');</pre>
<p>This creates a script tag.</p>
<pre>script.src = file;</pre>
<p>This line sets the src of the script tag to the  file that you specify when you call the function.</p>
<pre>script.type = 'text/javascript';</pre>
<p>We set the type of the script tag to text/javascript</p>
<pre>script.id = 'loadScript';</pre>
<p>Here we set the ID to loadScript so we can reach it with the second line in the code the next time this function is called.</p>
<pre>head.appendChild(script)</pre>
<p>Then we add the script tag to the page with the appendChild function. It&#8217;s added to the head of the page.</p>
<p>So if you call the function like this:</p>
<pre>loadContent('myfile.js')</pre>
<p>it&#8217;s more or less the same as adding a script tag with regular code like this:</p>
<pre>&lt;script type="text/javascript" id="loadScript" src="myfile.js"&gt;&lt;/script&gt;</pre>
<p>Note that the file you load in a script tag like this HAVE to be a JS file. You cannot load another HTML file or whatever like this. It has to valid script inside the file.</p>
<p>Ok, now we know how it works, but what can we do with it?</p>
<p>There are tons of things we can do with this technique, let&#8217;s start of with a simple example</p>
<h3 class="clWinHeading">Simple example</h3>
<p class="clContent">I had a hard time finding a very simple example for this one so I&#8217;ll make a totally useless one just so you can see that it works.</p>
<p><a href="http://www.dhtmlcentral.com/tutorials/examples/load_script_tutorial_example1.html" target="_blank">Example 1</a></p>
<p>This doesn&#8217;t really start to get really powerfull before you start using it together with  some server-side stuff though. Let&#8217;s say you had a page with stock quotes, you could set the script to reload and get the latest stock quotes every 2 minutes and the user would never have to reload the actual page, the only thing updated is the quotes.</p>
<p>Anyway, let&#8217;s move on to the menu script</p>
<h3 class="clWinHeading">Menu script</h3>
<p class="clContent">Let&#8217;s say you have a menu similar to the foldoutMenu from this site with 200 menu items. This is a modified and a little simplified version where the script only loads the  top items as HTML (making the older browsers use the main items only), and loads the other elements with the loadContent function only if and when they are needed.</p>
<p>I&#8217;ll start by showing you the menu (the first menu and the second sub and subsub menu opens new items)</p>
<p><a href="http://www.dhtmlcentral.com/tutorials/examples/load_script_tutorial_example2.html" target="_blank">Example2</a></p>
<p>This is a simple version of the menu basically to give you the idea (i know, i know, the code is a mess), note that I don&#8217;t mean that you should use this script, it&#8217;s only intended to help you understand the basics of this technique. Though by all means feel free to reuse the code if you like.</p>
<p>We make the top items manually. That way they will be shown and works in all browsers. The submenus only works in dom browsers. Right now I will not write more about how this works, you&#8217;re on your own. The source-code has a lot of comments that should help you understand it (it can be downloaded at the end of the tutorial).</p>
<p>I&#8217;ll give you one more example to give you the idea of how I use this script.</p>
<h3 class="clWinHeading">ASP Menu script</h3>
<p class="clContent">This part of this tutorial shows an ASP example and you should know some ASP to understand this.</p>
<p>As mentioned before this doesn&#8217;t really become useful until you start doing some backend stuff. Let&#8217;s say I have a database with 500 products divided in 10 categories and stored in a database (again simplified example).</p>
<p>Database tblCategories:<br />
<code>dbID</code> - autonumber<br />
<code>Catname</code> - Txt<br />
Database tblProducts:<br />
<code>dbID</code> - autonumber<br />
<code>Productname</code> - Txt<br />
<code>Productinfo</code> - Txt<br />
<code>category</code> - Number - related to DBID in table1</p>
<p>You would probably want to add some more info in there, like price and whatever, but you get the idea.</p>
<p>Then we have some data like this in tblCategories:</p>
<table border="1">
<tr>
<td><strong>dbID</strong></td>
<td><strong>Catname</strong></td>
</tr>
<tr>
<td>1</td>
<td>Software</td>
</tr>
<tr>
<td>2</td>
<td>Hardware</td>
</tr>
</table>
<p>And in tblProducts:</p>
<table border="1">
<tr>
<td><strong>dbID</strong></td>
<td><strong>Productname</strong></td>
<td><strong>Productinfo</strong></td>
<td><strong>category</strong></td>
</tr>
<tr>
<td>1</td>
<td>Homesite 5</td>
<td>The best code editor around</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>44 inch flat screen</td>
<td>Use the computer as your home-cinema screen</td>
<td>1</td>
</tr>
</table>
<p>Now we are ready to start displaying the data. The first page displays the categories as topMenus: (note that I code ASP in JScript - so should you!)</p>
<pre>//Pointer to the database
database="Provider=Microsoft.Jet.OLEDB.4.0;"
  +"Data Source="+Server.MapPath("example.mdb")+";"

//opening db
q="Select * from tblCategories"
rs=Server.CreateObject("ADODB.Recordset")
rs.open(q,database)

//looping records
while(!rs.EOF){
  name=rs("catname").value
  id=rs("dbid").value
  Response.write('&lt;div level="0" id="m'+id+'" '
  +'scriptFile="products.asp?id='+id+'" class="cl0"&gt;'
  +'&lt;a href="old_browsers_link.html" '
onclick="return openMenu(this)"&gt;&lt;/a&gt;'+name+'&lt;/a&gt;'
  +'&lt;/div&gt;nn')
  rs.moveNext()
}
rs.close()
rs=null</pre>
<p>The second page &#8220;products.asp&#8221; is that page that will be loaded with the js loading. If you&#8217;re thinking &#8220;Hey, I thought you said that it had to be js file!!&#8221; your right, so we have to get the server to return the content as a javascript file. We do that with this little line:</p>
<pre>Response.ContentType="text/js"</pre>
<p>So the entire products.asp looks like this:</p>
<pre>@LANGUAGE=JAVASCRIPT

//Getting the ASP page to return a js file
Response.ContentType="text/js"

//Getting the id
catid = Request.queryString("id")

//Pointer to the database
database="Provider=Microsoft.Jet.OLEDB.4.0;"
+"Data Source=" + Server.MapPath("example.mdb") + ";"

//opening db
q="Select * from tblProducts where category = "+catid
rs=Server.CreateObject("ADODB.Recordset")

rs.open(q,database)

//looping database records
while(!rs.EOF){
  txt=rs("ProductName").value + " " + rs("ProductInfo").value
  id=rs("dbid").value
  Response.write('addElements("'+txt+'","","show_product_details.asp?id='+id+'")n')
  rs.moveNext()
}
rs.close()
rs=null

Response.write("loaded()")</pre>
<p>Again, this was a simple example, and the only thing it does is get the info from the db and display in the menu from the last example. I have not included any product display page or any error checking. But I am sure that if you get the point of this example you&#8217;ll see that a similar approuch could be used to load entire tables of data in all kind of cool ways.</p>
<p class="clContent">&nbsp;</p>
<h3 class="clWinHeading">Download</h3>
<p class="clContent">You can download all the examples from this tutorial <a href="http://www.dhtmlcentral.com/tutorials/examples/load_tutorial.zip">here</a> (with the database and ASP files).</p>
<p>More examples on gow to use this technique will come!</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/dynamic-data-using-the-dom-and-remote-scripting.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Upgrading to CoolMenus 4</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/upgrading-to-coolmenus-4.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/upgrading-to-coolmenus-4.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:56:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/upgrading-to-coolmenus-4.php</guid>
		<description><![CDATA[Intro
I am really sorry to say that I had to change most property/variable names when making the new script. I needed a more stable naming convention for the properties so they are a little different. Shouldn&#8217;t really be to hard to update it though, but you DO have to go step by step through the [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Intro</h3>
<p class="clContent">I am really sorry to say that I had to change most property/variable names when making the new script. I needed a more stable naming convention for the properties so they are a little different. Shouldn&#8217;t really be to hard to update it though, but you DO have to go step by step through the script and change some stuff.</p>
<p>I this tutorial I will actually update the old example 1 from the coolMenus 3 examples step by step while writing.</p>
<p>Remember that this version does not yet support frames so if you&#8217;re using coolMenus3 with frames you CAN NOT update yet! The first thing you have to do is update your browsercheck. Remove the entire thing from your page and just use the one in the new JS file (If you site is in a frame and you get problems with NS4 saying &#8220;bw is not defined&#8221; then move it from the JS file and into your HTML file again.</p>
<h3 class="clWinHeading">Menu properties</h3>
<p class="clContent">We&#8217;ll start with the menu properties.   The first line of the menu creation script looked like this before:</p>
<pre>var mDebugging=2</pre>
<p>Just delete that line.  The old menu creation line was like this:</p>
<pre>oCMenu=new makeCoolMenu("oCMenu")</pre>
<p>Change that to:</p>
<pre>oCMenu=new makeCM("oCMenu")</pre>
<p>These:</p>
<pre>oCMenu.useframes=0
oCMenu.frame=""
oCMenu.useclick=0</pre>
<p>can be deleted since this version does not yet support frames or click activation.  You can also delete these lines (if you have them):</p>
<pre>oCMenu.useNS4links=1
oCMenu.NS4padding=2</pre>
<p>Netscape 4 will now use the same classes as Explorer.</p>
<p>This one:</p>
<pre>oCMenu.checkselect=0</pre>
<p>Is no longer part of the core script. If you where using this feature you have to get the add-in.js (see the coolMenus documention for more info). So this line can be deleted as well.</p>
<pre>oCMenu.offlineUrl="file:///C|/Inetpub/wwwroot/dhtmlcentral/"
oCMenu.onlineUrl="http://www.dhtmlcentral.com/coolmenus/examples/"</pre>
<p>The onlineUrl and offlineUrl are replaced with <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=33','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">onlineRoot</a>  and <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=34','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">offlineRoot</a>.</p>
<p>This is basically done because of all the problems the offlineUrl and onlineUrl caused ppl in version 3. Please note that this means you might have to change all your urls :(</p>
<p>These:</p>
<pre>oCMenu.pagecheck=1
oCMenu.checkscroll=1</pre>
<p>Can also be deleted as they are also part of the add-in.js now.</p>
<pre>oCMenu.resizecheck=1</pre>
<p>Is the same exept that it&#8217;s now called:</p>
<pre>oCMenu.resizeCheck=1 //Note the UPPER-CASE "C"</pre>
<p>The wait property:</p>
<pre>oCMenu.wait=1000</pre>
<p>Is the same.</p>
<p>The fromleft, fromtop, pxbetween and menuplacement variables are still the same, only they have changed to upper-case on the second part of their names (all properties have changed this way):</p>
<pre>oCMenu.fromLeft=20
oCMenu.fromTop=0
oCMenu.pxBetween=30
oCMenu.menuPlacement="center"</pre>
<p>The <code>oCMenu.rows</code> is still the same.</p>
<p>There are two new main properties,  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=29','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">fillImg</a> and  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=6','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">zIndex</a>. I don&#8217;t care about the zIndex for my examples as it&#8217;s not important. The fillImg have to be set though, you have to get the cm_fill.gif from the zip file and upload it with the script. The value of the property should be the path to the image from the ROOT of your web:</p>
<pre>oM.fillImg="images/cm_fill.gif"
oM.zIndex=0</pre>
<p>More info about the menu properties can be found <a href="http://www.dhtmlcentral.com/projects/coolmenus/properties.asp?m=47" target="_blank">here</a>.</p>
<p class="clContent">&nbsp;</p>
<h3 class="clWinHeading">Background-bar properties</h3>
<p class="clContent">The usebar, barx, bary, barwidth and barheight properties are the same as before except now they are called:</p>
<pre>oCMenu.useBar=1
oCMenu.barWidth="100%"
oCMenu.barHeight
oCMenu.barX=0
oCMenu.barY="menu"</pre>
<p>Be sure to change the &#8220;B&#8221;,&#8221;W&#8221;, &#8220;H&#8221;, &#8220;X&#8221; and &#8220;Y&#8221; to upper-case letters.</p>
<p>The old barcolor variable is replaced with <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=2&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=12','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">barClass</a>:</p>
<pre>oM.barClass="clBar"</pre>
<p>So we have to make a style sheet with a class with settings for the background-bar. See &#8220;CSS help&#8221; in the documentation for more info about how to make the stylesheet. If I had this before:</p>
<pre>oCMenu.barcolor="Navy"</pre>
<p>My class will look like this:</p>
<pre>.clBar{position:absolute; width:10; height:10; background-color:Navy;
 layer-background-color:Navy; visibility:hidden}</pre>
<p>Note that we have to add <code>layer-background-color</code> for NS4 and that the layer needs a width and height for it to be displayed in Opera. Remember to place the class in a stylesheet.</p>
<p><code>.barinheritborder</code> is replaced with 3 new properties called  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=2&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=37','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">barBorderClass</a>,  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=2&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=38','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">barBorderX</a> and  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=2&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=39','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">barBorderY</a>. In my example I am not using border for the background-bar so I&#8217;ll just set them like this:</p>
<pre>oM.barBorderX=0
oM.barBorderY=0
oM.barBorderClass=0</pre>
<p>More info about the background-bar properties can be found <a href="http://www.dhtmlcentral.com/projects/coolmenus/properties.asp?m=49" target="_blank">here</a>.</p>
<h3 class="clWinHeading">Level properties</h3>
<p class="clContent">There are two main changes in the level properties:</p>
<p>1. The levels now inherit from the last level no matter what.</p>
<p>2. The levels creation code is different:<br />
Before:</p>
<pre>oCMenu.level[0]=new Array()</pre>
<p>Now:</p>
<pre>oCMenu.level[0]=new cm_makeLevel()</pre>
<p>I also added another way to create levels for advanced users, See <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=47','foo','width=600, height=400, toolbars=1'); return false">here</a> for more info.</p>
<p>width and height are still the same.</p>
<p>The old .bgcoloroff, .bgcoloron, .textcolor, .hovercolor and .style are replaced by  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=15','foo','width=600, height=400, toolbars=1'); return false">regClass</a> and  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=16','foo','width=600, height=400, toolbars=1'); return false">overClass</a> which now points to CSS classes that holds the styles for the items in the current level.</p>
<p>In my example it looked like this:</p>
<pre>oCMenu.level[0].bgcoloroff="Navy"
oCMenu.level[0].bgcoloron="#336699"
oCMenu.level[0].textcolor="White"
oCMenu.level[0].hovercolor="Yellow"
oCMenu.level[0].style=""</pre>
<p>So I make two styles in my stylesheet (see CSS help for more info on making the stylesheet):</p>
<pre>.clLevel0{
  position:absolute;
  background-color:Navy;
  layer-background-color:Navy;
  color:white;
  padding:2px;
  font-family:tahoma,arial,helvetica;
  font-size:12px;
  font-weight:bold
}
.clLevel0over{
  position:absolute;
  background-color:#336699;
  layer-background-color:#336699;
  color:Yellow;
  padding:2px;
  font-family:tahoma,arial,helvetica;
  font-size:12px;
  font-weight:bold
  cursor:pointer; /* Note the cursor for NS6 */
  cursor:hand /* Cursor for IE */
}</pre>
<p>And set the variables to:</p>
<pre>oCMenu.level[0].regClass="clLevel0"
oCMenu.level[0].overClass="clLevel0over"</pre>
<p>Actually, I would make the CSS classes like this to save space:</p>
<pre>.clLevel0,.clLevel0over{position:absolute; padding:2px;
font-family:tahoma,arial,helvetica; font-size:12px; font-weight:bold}
.clLevel0{background-color:Navy; layer-background-color:Navy;color:white;}
.clLevel0over{background-color:#336699; color:Yellow;
layer-background-color:#336699; cursor:pointer; cursor:hand; }</pre>
<p>Anyway, moving on the border and bordercolor are replaced by  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=34','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">borderX</a> <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=34','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">borderY</a> and <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=34','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">borderClass</a> . You can now control the vertical and horizontal borders of the items separately. And you control the look of the border with a CSS class. So before I had:</p>
<pre>oCMenu.level[0].border=1
oCMenu.level[0].bordercolor=":#006699"</pre>
<p>I have to make another CSS class:</p>
<pre>.clLevel1border{position:absolute; visibility:hidden;
background-color:#006699; layer-background-color:#006699}</pre>
<p>and set the variables to:</p>
<pre>oCMenu.level[0].borderX=1
oCMenu.level[0].borderY=1
oCMenu.level[0].borderClass="clLevel0border"</pre>
<p>The old .offsetX and .offsetY are the same.</p>
<p>These:</p>
<pre>oCMenu.level[0].NS4font="tahoma,arial,helvetica"
oCMenu.level[0].NS4fontSize</pre>
<p>Can be removed. NS4 now uses the same classes as the other browsers.</p>
<p>Next is the align variable. It works the same as before only I have added a couple of possible <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=20','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">values</a>.</p>
<p>If you where using filters, clip or slide you have to add the add-in.js file to get those properties on the levels again, if now just remove them.</p>
<p>There are four new variables for the levels. They are <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=19','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">rows</a> <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=23','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">arrow</a> <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=24','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">arrowWidth</a> and  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=25','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">arrowHeight</a>. Click on them for more information. In my example I don&#8217;t need those, and I want all subitems in a column so I&#8217;ll add:</p>
<pre>oCMenu.level[0].rows=0
oCMenu.level[0].arrow=0
oCMenu.level[0].arrowWidth=0
oCMenu.level[0].arrowHeight=0</pre>
<p>in level 0.</p>
<p>Remember to do all these changes for ALL levels that you have any of these values specified.</p>
<p>More info about the level properties can be found <a href="http://www.dhtmlcentral.com/projects/coolmenus/properties.asp?m=48" target="_blank">here</a>.</p>
<h3 class="clWinHeading">Item properties</h3>
<p class="clContent">Most of the item properties are still the same.  My old items that looked like this:</p>
<pre>oCMenu.makeMenu('top0',',' News','/news/','frmMain2')
 oCMenu.makeMenu('sub00','top0','Newest news','/news/index.asp')
  oCMenu.makeMenu('sub001','sub00','- New DHTML API released',',',160,0)
   oCMenu.makeMenu('sub002','sub00','- Explorer 7 is out',',',160,0)
   oCMenu.makeMenu('sub003','sub00','- Opera 6 supports innerHTML',',',160,0)
 oCMenu.makeMenu('sub01','top0','News archive','/news/archive.asp')</pre>
<p>Will still work just fine. The only thing to notice is the  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=43','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">links</a>.</p>
<p>With the new  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=33','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">onlineRoot</a> and  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=34','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">offlineRoot</a>  all links now have to be relative to the root of your web. Which means that if you have a file in <code>mypages/myotherpages/myfile.html</code> you have to place in the ENTIRE path like that. This also goes for the image variables;  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=46','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">regImage</a> and <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=48','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">overImage</a> (before called img1 and img2), if you where using images for the menus.</p>
<p><strong>Other changed variables:</strong><br />
bgcolor, bgcoloron, textcolor and hovercolor are replaces with  <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=49','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">regClass</a> and <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=50','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">overClass</a> (see the level part for more information)</p>
<p><strong>New variables:</strong><br />
<a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=51','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">rows</a> - You can override the level rows here. <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=52','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">align</a> - You can override the level align here. <a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=4&amp;id=9#" onclick="window.open('/projects/coolmenus/pop_prop.asp?id=53','foo','toolbar=1,scrollbars=1,status=1,width=600,height=400'); return false">nolink</a> - Used to make a item that doesn&#8217;t link.</p>
<p>The onclick, onmouseover and onmouseout are the same.</p>
<p>It now looks like this:</p>
<pre>myCoolMenu.makeMenu(name, parent_name, text, link, target, width,
height, regImage, overImage, regClass, overClass , align, rows,
nolink, onclick, onmouseover, onmouseout)</pre>
<p>In my example I also had to edit 2 menus that had a onclick event defined, because the adding of the arguments to the function have made the events become one &#8220;more to the left&#8221;. So I had to add an extra &#8220;empty&#8221; space in there.</p>
<p>More info about the item properties can be found <a href="http://www.dhtmlcentral.com/projects/coolmenus/properties.asp?m=50" target="_blank">here</a>.</p>
<h3 class="clWinHeading">Finishing</h3>
<p class="clContent">Now remove the line:</p>
<pre>oCMenu.makeStyle()</pre>
<p>We no longer need this one because the script doesn&#8217;t make the styles anymore.  Leave the <code>oCMenu.construct()</code> code though.  Then after going through the code I got a file like this: <a href="http://www.dhtmlcentral.com/projects/coolmenus/examples/menu1.html" target="_blank">menu1.html</a>.</p>
<p>UPDATED: Remember to add the NEEDED styles to the stylesheet:</p>
<pre>/* CoolMenus 4 - default styles - do not edit */
.clCMEvent{position:absolute; width:99%; height:99%;
clip:rect(0,100%,100%,0); left:0; top:0;}
.clCMAbs{position:absolute; visibility:hidden; left:0; top:0}
/* CoolMenus 4 - default styles - end */</pre>
<p>That&#8217;s about it. If this didn&#8217;t help let me know in the new <a href="http://www.dhtmlcentral.com/forums/forum.asp?FORUM_ID=10&amp;CAT_ID=3&amp;Forum_Title=CoolMenus+4"> CoolMenus 4 forum</a>. And if this helped or you fixed it yourself please come back to the forums and help others do the same.  Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/upgrading-to-coolmenus-4.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scripting for 5th Generation Browsers - Part 2</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-2.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-2.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:54:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-2.php</guid>
		<description><![CDATA[Creating Elements
Another powerful tool in the web developer&#8217;s arsenal is the  document.createElement() method. This method allows  developers to create tags on the fly. Essentially,  you create a whole document complete with images,  text, and whatever else you can think of . However,  what is essential to understand when using this [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Creating Elements</h3>
<p class="clContent">Another powerful tool in the web developer&#8217;s arsenal is the  <code>document.createElement()</code> method. This method allows  developers to create tags on the fly. Essentially,  you create a whole document complete with images,  text, and whatever else you can think of . However,  what is essential to understand when using this method is  that what occurs is the creation of a tag, but the tag  itself does not have any attributes.  For example.</p>
<pre>ifrm = document.createElement("IFRAME");</pre>
<p>creates an IFrame tag, but it does not define its src  attribute or its width and height, nor does it tell it  where to place the IFrame in the document body. In order  to achieve all the above we can use some of the things  that we have learnt previously and create an IFrame  from thin air complete with its attributes.</p>
<p>In the following script example we use:<br />
·	createElement()<br />
·	setAttribute()<br />
·	style attributes<br />
·	appendChild()</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Creating an IFRAME&lt;/title&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
function makeFrame() {
	ifrm = document.createElement("IFRAME");
	ifrm.setAttribute("src", "http://dhtmlnirvana.com/");
	ifrm.style.width = 640+"px";
	ifrm.style.height = 480+"px";
	document.body.appendChild(ifrm);
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body bgcolor="#000000"&gt;
&lt;p&gt;&lt;a href="#" onMouseDown="makeFrame()"&gt; Lets make an iframe &lt;/a&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/iframecreate.htm','winscript','height=550,width=680,toolbars=0'); return false">View example</a></p>
<p><strong>appendChild()</strong><br />
The DOM node method appendChild() is something we have not covered as yet, so  lets try and understand its purpose. The purpose of this node method is  to give the IFrame a place to reside in the document.</p>
<pre>document.body.appendChild(ifrm);</pre>
<p>If we follow the logic of the above line of script from a layman&#8217;s perspective,  this line translates into find the body of the document and place the IFrame in  the body.  The body is actually a node within the html document so it is important  to retrieve it, because this is where all our elements will be displayed.</p>
<h3 class="clWinHeading">CSS Dynamic Manipulation</h3>
<p class="clContent">One of the more functional abilities of the new generation browsers is  the ability to dynamically manipulate CSS properties by utilizing the DOM.   It is just cause to celebrate, because it eases the burden for  web developers in a number of ways.  Instead of having to use  workarounds like <code>document.write</code> to modify CSS properties,  finally we can use a standard way of coding that works in  5th generation browsers and above.</p>
<p>Lets begin by exploring a few text effects. First cab of the  rank is the ability to dynamically alter letter spacing.</p>
<pre>&lt;script language="JavaScript" type="text/javascript"&gt;
function spaceLetter(id, amount) {
	document.getElementById(id).style.letterSpacing = amount;
}
&lt;/script&gt;</pre>
<p>We begin by creating a function spaceLetter() and use two arguments  id and amount, which we can then use to define attributes later  at the event handler point.  The id argument is used in what  should now be the familiar <code>document.getElementById()</code>.  Then we script the wordSpacing style and give it the same  value as our second argument amount.</p>
<pre>document.getElementById(id).style.letterSpacing = amount;</pre>
<p>This function is then called from an event handler which allows for  the manipulation of any elements letter spacing by identifying what the id is ( in this case contentLayer) and the amount that the  letters should be spaced to (in this instance 8 ).</p>
<pre>&lt;a href="javascript:" onMouseOver="spaceLetter('contentLayer','8')"&gt; Space the Letters &lt;/a&gt;</pre>
<p>Here is a complete working example to work from:</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Letter Spacing Example&lt;/title&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
function spaceLetter(id, amount) {
	document.getElementById(id).style.letterSpacing = amount;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;a href="javascript:" onMouseOver="spaceLetter('contentLayer','8')"
onMouseOut="spaceLetter('contentLayer','1')"&gt; Space the Letters &lt;/a&gt;
&lt;div id="contentLayer" style="position:absolute; width:470px; height:39px; z-index:1;
  left: 33px; top: 57px; visibility: visible"&gt;DHTML
  NIRVANA &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/letterspacing.htm','winscript','height=500,width=600,toolbars=0'); return false">View example</a></p>
<p>The same type of scripting method can be applied to many CSS properties. For example,  let us suppose we want to dynamically alter the font face, we could  use the following script:</p>
<pre>&lt;script language="JavaScript" type="text/javascript"&gt;
function fontName(id,fontName) {
document.getElementById(id).style.fontFamily = fontName;
}
&lt;/script&gt;</pre>
<p>and use the following at the event handler point.</p>
<pre>&lt;a href="javascript:" onMouseOver="fontName('contentLayer','Verdana')"
onMouseOut="fontName('contentLayer','Courier')"&gt; Change The Font &lt;/a&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/fontchange.htm','winscript','height=550,width=680,toolbars=0'); return false">View example</a></p>
<p>or if we wanted to dynamically alter a fonts color we could use</p>
<pre>&lt;script language="JavaScript" type="text/javascript"&gt;
function fontColor(id,color) {
document.getElementById(id).style.color = color;
}
&lt;/script&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/fontcolor.htm','winscript','height=550,width=680,toolbars=0'); return false">View example</a></p>
<p>I think you get the idea. We can of course do a whole lot more than just play  around with fonts and that&#8217;s what makes coding for the newer generation browsers  both intriguing and fun. There are many instances where we do not have to use JavaScript but can just use CSS declarations. Let us imagine we wanted to add  OS scroll bars to a &lt;p&gt; element in Internet Explorer 5+ and Netscape 6.</p>
<p>All we need to do is redefine the tag via a CSS declaration as shown below and the &lt;p&gt; tag takes on scrollbars:</p>
<pre>&lt;style type="text/css"&gt;
p {display: block; overflow: scroll; font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px; position: absolute; height: 100px; width: 200px; left: 400px; top: 10px}
&lt;/style&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=1&amp;id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/pscroll.html','winscript','height=550,width=680,toolbars=0'); return false">View example</a></p>
<h3 class="clWinHeading">Object Constructors</h3>
<p class="clContent">Thus far we have focused upon standalone examples to highlight a few of the things  that can be achieved by using standards based coding.  While useful  to illustrate some of the potential of the new generation browsers,  in practical web page building terms there are even more useful  techniques that can be applied to web page building.</p>
<p>As a way of introduction to more comprehensive articles focused on DOM  based web page building techniques,  let us take a look at a couple  of the primary techniques I often use when building Dynamic HTML web pages.</p>
<p>These techniques include the following:<br />
·	Object Constructors<br />
·	Object Orientated Browser Sniffer<br />
·	Positioning Layers By Browser Dimensions.</p>
<p>Let&#8217;s Get Going: In another article at <a href="http://www.webreference.com/new/010412.html" target="_blank">webreference</a> I  demonstrated how to dynamically resize images. In keeping with the notion of  creating liquid web pages that dynamically accommodate different browser dimensions, let  us utilize this opportunity to build on that previous article and demonstrate how  to position layers by browser dimensions from a DOM based coding perspective.  Specifically, let us learn how to dynamically center a layer across varying browser sizes.</p>
<p>First off our browser sniffer script:</p>
<pre>function Is() {
    agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns    = ((agent.indexOf('mozilla') != -1) &amp;&amp;
      ((agent.indexOf('spoofer')  ==   -1) &amp;&amp; (agent.indexOf('compatible') == -1)));
    this.ns4   = (this.ns &amp;&amp; (this.major == 4));
    this.ns6   = (this.ns &amp;&amp; (this.major &gt;= 5));
    this.ie    = (agent.indexOf("msie") != -1);
    this.ie3   = (this.ie &amp;&amp; (this.major  &lt; 4));
    this.ie4   = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.0") == -1));
    this.ie5   = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.0") != -1));
    this.ie55  = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.5") != -1));
    this.ie6  = (this.ie &amp;&amp; (agent.indexOf("msie 6.0")!=-1) );
}

var is = new Is();</pre>
<p>The purpose of this script is to be able to detect which browser the client is using.  In reality, we could use direct object detection here, instead of browser detection,  but in many instances, object detection is not strict enough, particularly if we want  to build a complex backward compatible web page or at a minimum redirect users to an  alternate page or pass an alert.</p>
<p>The browser sniffer is composed of JavaScript objects that converts the user agent  string into an object to use later in the script as a variable by using the  <code>var is = new Is()</code>; statement . As long as the variable is associated  with the correct user agent string, we should not run into many problems.</p>
<p>From the browser sniffer script we need to use the 6 variables that cover  the major DHTML capable browsers: <code>is.ns4</code>, <code>is.ns6</code>, <code>is.ie4</code>,  <code>is.ie5</code>, <code>is.ie55</code> and <code>is.ie6</code>. The easiest  way to understand these variables is to think of them as taking the form  of a question posed to the browser.</p>
<pre>if (is.ie5|| is.ie55|| is.ie6|| is.ns6){
do the script here</pre>
<p>Asks the question is this either Internet Explorer 5 and above or alternatively Netscape 6.  If the answer to the question is yes, then run this portion of the script. Since this condition forms the basis of coding for the W3C DOM where ever possible it takes  priority in the conditional logic.  If the answer is no, then go to the  next question and see if the answer is yes.</p>
<pre>} else if(is.ie4) {
do the script here</pre>
<p>Asks the question is this Internet Explorer 4. As before, if the answer to the question  is yes then run this portion of the script, if the answer is no then go to the next question.</p>
<pre>} else if(is.ns4) {
do the script here</pre>
<p>We could also build in other variables, which detect for Opera, WebTV and so on and could  either redirect users to an alternate page or pass an alert.</p>
<p>Object Constructors: Having worked our way through the basic premise of detection routines and if/else statements,  lets begin to build our JavaScript object construction routine. The purpose of this section of  the script is to convert CSS layers into JavaScript objects that can be easily dynamically  manipulated later on in the scripting routine.</p>
<pre>function layerObject(id,position,left,top,visibility) {
  if (is.ie5|| is.ie55||is.ie6|| is.ns6){
  this.obj = document.getElementById(id).style;
  this.obj.position = position;
  this.obj.left = left;
  this.obj.top = top;
  this.obj.visibility = visibility;
  return this.obj;
  }
}</pre>
<p>The script is dedicated to creating attributes for JavaScript objects. A good way to think  of this is to conceptualize a CSS layer written in the body section of your document,  note how the initial positioning is set to 0 and visibility to hidden. Later on we will  dynamically position the layer and also toggle its visibility to visible.</p>
<pre>&lt;div id="centerLayer" style="position: absolute; width:200px; height:24px; left:
0px; top: 0px; z-index: 6; visibility: hidden;"&gt;&lt;/div&gt;</pre>
<p>You will notice that in the div tag we have an id attribute. Similarly, in our layer  object we also assign an id attribute. The reasoning behind this is that what we  are attempting to achieve is a JavaScript replication of the CSS layer attributes.  Following this course of logic, we then assign more CSS layer attributes to the  layerObject script. We assign, position, top, left and visibility. More attributes  could be assigned as needed, for instance we could include z-index, height  and width and so on. The object constructor can become very detailed and thus  ideally open itself to a myriad of dynamic manipulations. Indeed in later  articles, we will be utilizing object  constructors a fair bit, so it is  important to understand the basic premise of what these allow us to do.  For the purposes of this article, lets stick with just a couple of basic  attributes to get accustomed to the concepts presented here.</p>
<p>It is important to note, that in reality our object constructor has not  really created anything. All we have done is prepared our documents for the  creation of new layer objects. Therefore, we need to focus our attention  on actually creating new layer objects. This is achieved with the <code>layerSetup()</code> script.</p>
<pre>function layerSetup() {
centerLyr=new layerObject('centerLayer','absolute',page_width/2-100,page_height/2-12,'visible')
}</pre>
<p>The first line defines the functions name. The second line does quite a few things  so lets pull it apart to better understand it.</p>
<p>We create a new variable centerLyr and tell the browser that it equals a <code>new layerObject()</code>.  The sole purpose of this section of the JavaScript statement is to hook back into our  <code>layerObject()</code> script so that we can then assign the specific values  needed for that particular layer. You can identify the attribute value that belongs  to <code>layerObject()</code> properties by looking at the following table.</p>
<table border="1" cellspacing="4" width="100%">
<tr>
<td>Function Name</td>
<td>ID Property</td>
<td>Position Property</td>
<td>Left Property</td>
<td>Top Property</td>
<td>Visibility Property</td>
</tr>
<tr>
<td>LayerObject</td>
<td>id</td>
<td>position</td>
<td>left</td>
<td>top</td>
<td>visibility</td>
</tr>
<tr>
<td>LayerSetup</td>
<td>centerLayer</td>
<td>absolute</td>
<td>page_width/2-100</td>
<td>page_height/2-12</td>
<td>visible</td>
</tr>
</table>
<p>The upshot of this little piece of scripting is that we end up with a new  JavaScript object called centerLayer which has the CSS attributes of  positioning, left, top, and visibility assigned to it. From a scripting perspective  this is enormously useful because if we so wished we can then manipulate  any of the CSS properties as we shall see later on in this article.</p>
<h3 class="clWinHeading">Capturing Browser Dimensions</h3>
<p class="clContent">Let&#8217;s get back to positioning our layers by browser dimensions. You will note that  instead of assigning a numeric value to the left and top attributes of the  new layer object, page_width and page_height are used. These are variables  created and set at the <code>onLoad</code> event handler:</p>
<pre>onLoad="
if(is.ns6) {
page_width=innerWidth;
page_height=innerHeight;
layerSetup();
} else if(is.ie5 || is.ie55||is.ie6) {
page_width=document.body.clientWidth;
page_height=document.body.clientHeight;
layerSetup();
}"</pre>
<p>Once again we need to create a little cross browser and backward  compatible DOM switch. Netscape 4 and Netscape 6 use innerWidth  and InnerHeight to detect a users screen resolution.  Therefore, we create a browser detection condition.</p>
<pre>if(is.ns6) {</pre>
<p>if this condition holds true then the variables page_width and page_height  are assigned the correct DOM method for Netscape 6 and the <code>layerSetup()</code> script is triggered.</p>
<pre>page_width=innerWidth;
page_height=innerHeight;
layerSetup();</pre>
<p>If the condition is not true then attention is focused on the  Internet explorer part of the script and the DOM for  those browsers is utilized.</p>
<pre>} else if(is.ie5 || is.ie55 || is.ie6) {
page_width=document.body.clientWidth;
page_height=document.body.clientHeight;
layerSetup();
}"</pre>
<p><strong>Understanding Positioning</strong><br />
Having captured a users browsers page dimensions we can then use  the newly formed variables to position the layer by those dimensions.  Hence, the values of <code>page_width/2-100</code>, <code>page_height/2</code>, in the  <code>layerSetup()</code> script. To determine the meaning of these values,  lets think about this in a different way. The value  <code>page_width/2-100</code> literally stands for the browser  size divided by 2 and minus 100 pixels from the left edge of the browser.</p>
<p>Dividing the browser size by half, centers the layer. However,  its positioning is determined by the top left corner of  the layer, something that many people often overlook.  Therefore, if the content of the layer is sufficiently wide enough,  then the layer displays as not being centered. To overcome this  we need to take into consideration the layer width. In this instance,  the CSS layer centerLayer width is 200 pixels. We halve that,  and recognize that for it to appear centered, we need to move it  over to the left by 100 pixels. Hence the -100 in the left value.  The same logic is applied to top attribute where the browsers height  is divided into half and then the layers height is taken into account.</p>
<p>Let&#8217;s look at the completed web page:</p>
<pre>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;How to Center A Layer&lt;/title&gt;
&lt;script&gt;
function Is() {
    agent  = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns    = ((agent.indexOf('mozilla') != -1) &amp;&amp;
      ((agent.indexOf('spoofer')  ==   -1) &amp;&amp; (agent.indexOf('compatible') == -1)));
    this.ns4   = (this.ns &amp;&amp; (this.major == 4));
    this.ns6   = (this.ns &amp;&amp; (this.major &gt;= 5));
    this.ie    = (agent.indexOf("msie") != -1);
    this.ie3   = (this.ie &amp;&amp; (this.major  &lt; 4));
    this.ie4   = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.0") == -1));
    this.ie5   = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.0") != -1));
    this.ie55  = (this.ie &amp;&amp; (this.major == 4) &amp;&amp; (agent.indexOf("msie 5.5") != -1));
    this.ie6  = (this.ie &amp;&amp; (agent.indexOf("msie 6.0")!=-1) );
}

var is = new Is();

function layerObject(id,position,left,top,visibility) {
if (is.ie5|| is.ie55||is.ie6|| is.ns6){
this.obj = document.getElementById(id).style;
this.obj.position = position;
this.obj.left = left;
this.obj.top = top;
this.obj.visibility = visibility;
return this.obj;
}
}
function layerSetup() {
centerLyr=new layerObject('centerLayer','absolute',page_width/2-100,page_height/2-12,'visible');
}
&lt;/script&gt;
&lt;style type="text/css"&gt;
&lt;!--
.main {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 16px;
color: #FBEED5;
text-decoration: none
}
--&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body bgcolor="#999999" onLoad="
if(is.ns6) {
page_width=innerWidth;
page_height=innerHeight;
layerSetup();
} else if(is.ie5 || is.ie55 ||is.ie6) {
page_width=document.body.clientWidth;
page_height=document.body.clientHeight;
layerSetup();
}"
onResize=" history.go(0); "&gt;
&lt;div id="centerLayer" style="position: absolute; width:200px;
height:24px; left: 0px; top: 0px; z-index: 6; visibility: hidden;"&gt;
&lt;span class="main"&gt;This is a Layer Centered By Screen Resolution&lt;/span&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><a href="http://www.dhtmlcentral.com/tutorials/tutorials.asp?page=3&amp;id=7#" onclick="window.open('http://www.dhtmlcentral.com/tutorials/examples/centerlayer.htm','winscript','height=500,width=600,toolbars=0'); return false">View example</a></p>
<p>In a sense, a one CSS layer example doesn&#8217;t really do justice to the power of using  object constructors, because one of the real advantages of using them is code  reduction, especially when there are lots of CSS layers used in a web page.    It also does not adequately demonstrate the flexibility of object constructors  as they can be used with a wide range of purposes in mind.  Despite the shortcomings  of the above example, it does introduce the notion of object constructors  with regards to coding by a singular standard.</p>
<p>Armed with the concepts presented in this article and what is yet to come  in future articles, it is my sincere hope that this will prepare web developers  for the next generation of scripting techniques.</p>
<p>For more information about these concepts read the <a href="http://www.dhtmlcentral.com/tutorials/tutorial3.asp">DHTML Library</a> tutorial on this site. It has a different but similar approach.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-2.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Making a DHTML Script</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/making-a-dhtml-script.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/making-a-dhtml-script.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:45:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/making-a-dhtml-script.php</guid>
		<description><![CDATA[Understanding the library
As mentioned before the reason we want to use a library is to take care of the most basic browser differences and  concentrate on making the real code. The library has a lot of methods built in that we can reuse at any time. So when we need to make a script, [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Understanding the library</h3>
<p class="clContent">As mentioned before the reason we want to use a library is to take care of the most basic browser differences and  concentrate on making the real code. The <a href="http://www.dhtmlcentral.com/lib/">library</a> has a lot of methods built in that we can reuse at any time. So when we need to make a script, effect or a menu that&#8217;s special for one site we just include the library (with the functions you need) and start coding.</p>
<p>In this tutorial we&#8217;ll make a simple but cute <a href="http://www.dhtmlcentral.com/tutorials/drag_menu.html" target="_blank">dragable menu script</a> where we can drag the &#8220;head&#8221; of the menu and the rest slides after it.  It&#8217;s important that you understand the basics about how the library works to be able to follow this tutorial, so if you haven&#8217;t please read the <a href="http://www.dhtmlcentral.com/lib/">DHTML Lib</a> tutorial.</p>
<p>Then let&#8217;s start coding!</p>
<h3 class="clWinHeading">Starting with HTML and styles</h3>
<p class="clContent">We&#8217;ll start by thinking a little about how to add our DIV tags. We need two mayor divs, one for the head part and one parent div for all the items. Then we&#8217;ll have one div for each item inside the parent div (in this example we&#8217;ll make 4 items). At this point we should also think a little about how the menu should behave on events that occur on the divs. Here&#8217;s a little overview:<br />
<img src="http://www.dhtmlcentral.com/tutorials/script_fig1.gif" border="0" height="293" width="538" /><br />
So we&#8217;ll start with the HTML code to add inside the  body tag:</p>
<pre>&lt;div id="divHead"&gt; Menu&lt;/div&gt;
&lt;div id="divMenu"&gt;
  &lt;div id="divItem0" class="clItem"&gt;Test item1&lt;/div&gt;
  &lt;div id="divItem1" class="clItem"&gt;Test item2&lt;/div&gt;
  &lt;div id="divItem2" class="clItem"&gt;Test item3&lt;/div&gt;
  &lt;div id="divItem3" class="clItem"&gt;Test item4&lt;/div&gt;
&lt;/div&gt;</pre>
<p>Then we need to give the divs some styles:</p>
<pre>&lt;style&gt;
#divMenu{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  width:150;
  height:200;
  clip:rect(0,150,200,0);
  layer-background-color:silver;
  padding:4px
}
#divHead{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  layer-background-color:#333333;
  background-color:#333333;
  clip:rect(0,150,20,0);
  height:20;
  cursor:move;
  z-index:10;
  width:150;
  padding:2px;
  font-size:13px;
  color:white;
  font-weight:bold
}
DIV.clItem{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  height:30;
  top:0;
  padding:4px;
  width:150;
  clip:rect(0,150,30,0);
  cursor:hand
}&lt;/style&gt;</pre>
<p>We place that style tag in the head of our page. I wont talk much about these styles settings now, if you know a little CSS it should be pretty simple to follow. The height,widths and clipping are taken from FIG 1 that where made before I started making the menu. As you can see I have added cursor definitions (NOTE: Setting the cursor only works in Explorer 4+ and Netscape 6) and set the background colors. I set clip values to the same as height and width and layer-background-color to make NS4 cover the entire div with the background color. Did you know many <a href="http://www.crazylifeblog.de/viagra-bestellen.php">Viagra</a> Potenzmittel Shops using DHTML? They don´t buy Cialis or natürliche <a href="http://www.crazylifeblog.de/potenzmittel-2.php">Potenzmittel</a> on a dnymic shop, but viagra.</p>
<p>Then we are ready to start with the fun part, the scripting.</p>
<h3 class="clWinHeading">Making the script</h3>
<p class="clContent">We start with the easy part, adding a reference to out lib.js file in the head part of our page. (if you haven&#8217;t downloaded it yet, see the <a href="http://www.dhtmlcentral.com/lib/" target="_blank">lib page</a>)  Like this:</p>
<pre>&lt;script language="JavaScript1.2" src="lib.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<p>Now we have the libary ready and can start with the code for the menu. First I want to make some global variables for the script. That can be easily changed:<br />
<code>numItems</code> - The number of menu items we want to have.<br />
<code>itemOnColor</code> - The background color to change the item to onmouseover<br />
<code>itemOffColor</code> - The background color to change the item to onmouseout<br />
So we set them like this:</p>
<pre>numItems=4
itemOnColor="red"
itemOffColor="silver"</pre>
<p>We also need to be able to control where each item goes when clicked so I add an array with links:</p>
<pre>itemLinks=new Array()
itemLinks[0]="" 'Note that arrays always start at 0
itemLinks[1]="http://www.bratta.com"
itemLinks[2]="http://www.yahoo.com"
itemLinks[3]="http://www.altavista.com"</pre>
<p>The next part of the script is be a init function where all the library objects are made, the placement of the layers are fixed and the script will start:</p>
<pre>function init(){
  oHead=new lib_obj('divHead')
  oMenu=new lib_obj('divMenu')
  oMenu.bg(menuBgColor)
  oHead.dragdrop()

  oItems=new Array()
  var h=0
  for(i=0;i&lt;numItems;i++){
    oItems[i]=new lib_obj('divItem'+i,'divMenu')
    oItems[i].moveIt(0,h)
    h+=oItems[i].h
    oItems[i].bg(itemOffColor)
    oItems[i].evnt.onmouseover=new Function("mover("+i+")")
    oItems[i].evnt.onmouseout=new Function("mout("+i+")")
    if(bw.ns4){
      oItems[i].ref.captureEvents(Event.MOUSEDOWN)
      oItems[i].ref.onmousedown = new Function("location.href='+itemLinks[i]+''")
    }else oItems[i].evnt.onclick=new Function("location.href='+itemLinks[i]+''")
  }
  oMenu.clipTo(0,oMenu.w,h,0,1)
  moveM2(10)
}</pre>
<p>This function should be called to &#8220;start&#8221; the menu script, so either onload or just after the HTML divs are loaded. Let&#8217;s go line by line:</p>
<p><code>oHead=new lib_obj('divHead')</code> - Here we make a new lib object called <code>oHead</code> which references the div called divHead.</p>
<p><code>oMenu=new lib_obj('divMenu')</code> - Here we make a new lib object called <code>oMenu</code> which references the div called divHead.</p>
<p><code>oHead.dragdrop()</code> - Set drag and drop support for the <code>oHead</code> object.</p>
<p>Then we make a new array which will contain all the items for the menu <code>oItems=new Array()</code> The we loop the array once for each item. Remember that we set the <code>numItems</code> variable above to 4, so this line <code>for(i=0;i&lt;numItems;i++)</code> means that we want to loop from 0 to 4.  The reason we use a loop here is because it makes smaller code and that it should be easy to add more  elements (just add another HTML div and change numItem to 5). Inside each loop we start of by making each oItem[i] object (i is the counter for the loop):<br />
<code>oItems[i]=new lib_obj('divItem'+i,'divMenu')</code>, then we move the object to left 0 and top <code>h</code>. As you see above <code>h=0</code>, on the line below <code>h+=oItems[i].h</code> we add the height of each element to the <code>h</code> variable so the item will be moved to the height of the previous item. That way the items will be below one another. After that we set the default background color <code>oItems[i].bg(itemOffColor)</code>.</p>
<p>Now comes a little interesting part of the code; each lib object has a property called <code>evnt</code> that we use to set events for the object. We remember from FIG 1 that we wanted a onmouseover and a onmouseout event for the item divs that should change the background colors, we will make those functions in a little bit. An event handler set like this doesn&#8217;t support any arguments to a function, that&#8217;s why we attach the event to a new <code>Function</code>, the argument we want to pass is the number of the current item, so we go like this: <code>oItems[i].evnt.onmouseover=new Function("mover("+i+")")</code>.</p>
<p>After that we set the onclick event which will make the page go to the the link for that item when clicked. Netscape 4 doesn&#8217;t support onclick events on layers, so we have to use onmousedown, but first we have to capture the event for that div (<code>ref</code> points to the document of that div) <code>oItems[i].ref.captureEvents(Event.MOUSEDOWN)</code>, then add the event: <code>oItems[i].ref.onmousedown = new Function("location.href=\'+itemLinks[i]+'\'")</code>. For all other browsers we just set the onclick event like this: <code>oItems[i].evnt.onclick=new Function("location.href=\'+itemLinks[i]+'\'")</code></p>
<p>We then end by clipping the main menu object to the same height and width as all the items: <code>oMenu.clipTo(0,oMenu.w,h,0,1)</code><br />
The last line in this function starts another function that will always check if the menu is moved. I will explain that function in a little bit.</p>
<p>Now we&#8217;ll make the <code>mover</code> and <code>mout</code> functions that will be called onmouseover and onmouseout of each item. They are pretty straight forward and look like this:</p>
<pre>function mover(i){
  oItems[i].bg(itemOnColor)
}
function mout(i){
  oItems[i].bg(itemOffColor)
}</pre>
<p>The argument is the number of the item that calls the functions. Then we just set the background color to the <code>itemOnColor</code> or the <code>itemOffColor</code> variables that we defined earlier.</p>
<p>The last but most important function <code>moveM2</code> (called from last line in <code>init</code> above) looks like this:</p>
<pre>function moveM2(inc){
  endx=oHead.x;
  endy=oHead.y+oHead.h
  x=oMenu.x;
  y=oMenu.y
  distx = endx - x;
  disty = endy - y
  num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
  dx = distx/num;
  dy = disty/num
  if((Math.floor(Math.abs(dx))&lt;Math.floor(Math.abs(endx-x))
  ||Math.floor(Math.abs(dy))&lt;Math.floor(Math.abs(endy-y)))){
    oMenu.moveBy(dx,dy)
  }else oMenu.moveIt(endx,endy)
  setTimeout("moveM2("+inc+")",20)
}</pre>
<p>This function will loop itself and run all all the time while the user is on the page. Is basically just checks if there is a difference between the <code>oHead</code> object position and the <code>oMenu</code> object position,  and if there is it will slide the <code>oMenu</code> object to the correct position.  So when you drag the <code>oHead</code> object this function will notice that there is a difference between the positions and &#8220;fix&#8221; it. It has one argument; <code>inc</code>  which helps us control how fast the <code>oMenu</code> object will slide.</p>
<p>Some of this examples you can see on Wordpress Blogs example <a href="http://www.crazylifeblog.de">Crazylifeblog</a></p>
<p>Again we&#8217;ll go line by line: The first four lines just set some varibles so it will be easier to follow below: <code>endx=oHead.x</code> - The x (left) position that the slide will end at.<br />
<code>endx=oHead.y+oHead.h</code> - The y (top) position that the slide will end at.<br />
<code>x=oMenu.x</code> - The current x (left) position of the <code>oMenu</code> object.<br />
<code>y=oMenu.y</code> - The current y (top) position of the <code>oMenu</code> object.<br />
Then we have two lines that figures out the distance we need to slide for x and y:<br />
<code>distx = endx - x</code>, <code>disty = endy - y</code>.<br />
The next line is pure good old fashion math, to get the slide to move correctly (we want the left and the top &#8220;sliding&#8221; to end at the same time) we find the number that we will divide the distance with to get the x and y to move the correctly number of pixel each time. We take the square root of the the distance powered by 2 and divided by <code>inc</code>: <code>num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc</code></p>
<p>The next step is to get the actual pixels to move for x and y; <code> dx = distx/num; </code>, <code> dy = disty/num; </code> We are now ready to start and check whether we should move the menu, I&#8217;ll take part one of this line first: <code>Math.floor(Math.abs(dx))&lt;Math.floor(Math.abs(endx-x))</code> <code>Math.floor</code> just rounds the numbers and makes them integers (rounds down to nearest hole number). <code>Math.abs</code> makes the number positiv no matter if it&#8217;s a negative number or not, we need this because we want the menu to move both ways, left and right (or up and down). So this line basically says: if the number of pixels to move x position is lower then the  position to end at minus the current position - go on. The second part of that line does the same thing for the y position. If that line evaluates to true we will move the menu  by <code>dx</code> and <code>dy</code> pixels: <code>oMenu.moveBy(dx,dy)</code>. If it doesn&#8217;t evaluate to true we just move the menu straight to the <code>endx</code> and <code>endy</code>.<br />
Ok, one line left, this is an easy one; <code>setTimeout("moveM2("+inc+")",20)</code> - it&#8217;s a timeout that calls this function every 20 milliseconds.<br />
Why do we do that you might ask, well there are lots of different ways  we could have done it for instance called the function only when the <code>oHead</code> is dragged or similar, but believe me; to make it as stable as possible this <strong>is</strong> the best way to go. Netscape 4 doesn&#8217;t support <code>clearTimeout</code> very well and if we did it another way there&#8217;s a pretty big chance we would have gotten some problems with multiple timeouts trying to do the same thing. Though timeouts are pretty heavy on the system it&#8217;s ok as long as you don&#8217;t have a lot of them going at the same time. Anyway, after that little side track I have good news; We are done!</p>
<p>Now we just need to paste it all together into one page and we have ourselves a brand new DHTML script.</p>
<p class="clContent">&nbsp;</p>
<h3 class="clWinHeading">The code</h3>
<pre>&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Drag menu from DHTMLCentral.com&lt;/title&gt;
&lt;style&gt;
#divMenu{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  width:150;
  height:200;
  clip:rect(0,150,200,0);
  layer-background-color:silver;
  padding:4px
}
#divHead{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  layer-background-color:#333333;
  background-color:#333333;
  clip:rect(0,150,20,0);
  height:20;
  cursor:move;
  z-index:10;
  width:150;
  padding:2px;
  font-size:13px;
  color:white;
  font-weight:bold
}
DIV.clItem{
  position:absolute;
  font-family:arial,helvetica;
  font-size:12px;
  height:30;
  top:0;
  padding:4px;
  width:150;
  clip:rect(0,150,30,0);
  cursor:hand
}
&lt;/style&gt;
&lt;script language="JavaScript1.2" src="lib.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;
/****************************************************************************
Drag menu from DHTMLCentral.com
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Tutorial availble at dhtmlcentral.com
*   Made by Thomas Brattli 2001
***************************************************************************/
numItems=4 //How many items?
itemOnColor="red" //Item background color onmouseover
itemOffColor="silver" //Item background color onmouseout

itemLinks=new Array() //Link array - one link for each item
itemLinks[0]=""
itemLinks[1]="http://www.bratta.com"
itemLinks[2]="http://www.yahoo.com"
itemLinks[3]="http://www.altavista.com"

function init(){
  oHead=new lib_obj('divHead')
  oMenu=new lib_obj('divMenu')
  oHead.dragdrop()
  oItems=new Array()
  h=0
  for(i=0;i&lt;numItems;i++){
    oItems[i]=new lib_obj('divItem'+i,'divMenu')
    oItems[i].moveIt(0,h)
    oItems[i].bg(itemOffColor)
    oItems[i].evnt.onmouseover=new Function("mover("+i+")")
    oItems[i].evnt.onmouseout=new Function("mout("+i+")")
    if(bw.ns4){
      oItems[i].ref.captureEvents(Event.MOUSEDOWN)
      oItems[i].ref.onmousedown = new Function("location.href='"+itemLinks[i]+"'")
    }else oItems[i].evnt.onclick=new Function("location.href='"+itemLinks[i]+"'")
    h+=oItems[i].h
  }
  oMenu.clipTo(0,oMenu.w,h,0,1)
  moveM2(10)
}
function mover(i){
  oItems[i].bg(itemOnColor)
}
function mout(i){
  oItems[i].bg(itemOffColor)
}
function moveM2(inc){
  endx=oHead.x; endy=oHead.y+oHead.h
  x=oMenu.x;
  y=oMenu.y
  distx = endx - x;
  disty = endy - y
  num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
  dx = distx/num;
  dy = disty/num
  if((Math.floor(Math.abs(dx))&lt;Math.floor(Math.abs(endx-x))||
  Math.floor(Math.abs(dy))&lt;Math.floor(Math.abs(endy-y)))){
  oMenu.moveBy(dx,dy)
  }else oMenu.moveIt(endx,endy)
  setTimeout("moveM2("+inc+")",20)
}
onload=init;
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="divHead"&gt; Menu&lt;/div&gt;
&lt;div id="divMenu"&gt;
  &lt;div id="divItem0" class="clItem"&gt;Test item1&lt;/div&gt;
  &lt;div id="divItem1" class="clItem"&gt;Test item2&lt;/div&gt;
  &lt;div id="divItem2" class="clItem"&gt;Test item3&lt;/div&gt;
  &lt;div id="divItem3" class="clItem"&gt;Test item4&lt;/div&gt;
&lt;/div&gt;
Regular content goes here
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Note that you need the lib.js file that can be found in the <a href="http://www.dhtmlcentral.com/projects/lib/">DHTML library</a> in the same directory of your file for this to work.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/making-a-dhtml-script.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Filters and Transitions</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/filters-and-transitions.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/filters-and-transitions.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:44:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/filters-and-transitions.php</guid>
		<description><![CDATA[Introduction
When Microsoft released Internet Explorer 4 they included a selection of filters and transitions that allow multimedia-style effects in plain HTML web pages. They can be applied to any HTML control, such as DIV tags, form fields or images. Internet Explorer 5 for Windows built on the existing functionality with more advanced transitions and a [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Introduction</h3>
<p class="clContent">When Microsoft released Internet Explorer 4 they included a selection of filters and transitions that allow multimedia-style effects in plain HTML web pages. They can be applied to any HTML control, such as DIV tags, form fields or images. Internet Explorer 5 for Windows built on the existing functionality with more advanced transitions and a different method of applying filters. To see the examples in this tutorial you have to be using Internet Explorer 4+.</p>
<h3 class="clWinHeading">Static Filters</h3>
<p class="clWinHeading">Internet Explorer 4+</p>
<p>The static filters can be applied to any HTML control through the style tag:</p>
<p><code>&lt;div id="drop" style="filter: DropShadow(Color=red, OffX=2, OffY=2, Positive=1); width: 100; height:20;"&gt;hello&lt;/div&gt;</code></p>
<p>or at runtime through javascript:</p>
<p><code>document.all["drop"].style.filter = "DropShadow(Color=red, OffX=2, OffY=2, Positive=1)";</code></p>
<p>both produce this</p>
<p><span style="width: 200px; height: 20px">red drop shadow</span><small>(note: for some reason you must specify the width and height attributes for the filter to work)</small></p>
<table bgcolor="#c0c0c0" border="0" cellpadding="0" cellspacing="1">
<tr>
<td colspan="2" bgcolor="#ffffff" valign="top">Here is a list of the       filters you can use:</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» alpha</td>
<td bgcolor="#ffffff" valign="top">alpha blending (aka transparency)</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» blur</td>
<td bgcolor="#ffffff" valign="top">motion blur</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» chroma</td>
<td bgcolor="#ffffff" valign="top">makes a specified colour       transparent</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» dropShadow</td>
<td bgcolor="#ffffff" valign="top">creates a silhouette of the object</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» flipH</td>
<td bgcolor="#ffffff" valign="top">flips the contents of the object       horizontally</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» flipV</td>
<td bgcolor="#ffffff" valign="top">flips the contents of the object       vertically</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» glow</td>
<td bgcolor="#ffffff" valign="top">creates a glow effect for the       object</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» gray</td>
<td bgcolor="#ffffff" valign="top">converts contents to grayscale</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» invert</td>
<td bgcolor="#ffffff" valign="top">inverts the colours of the object</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» mask</td>
<td bgcolor="#ffffff" valign="top">produces a mask of a specified       colour</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» shadow</td>
<td bgcolor="#ffffff" valign="top">like drop shadow except edges are       blurred</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» wave</td>
<td bgcolor="#ffffff" valign="top">adds a ripple to the image</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» x-ray</td>
<td bgcolor="#ffffff" valign="top">seems to be like an OR function</td>
</tr>
</table>
<p>The best way to use these filter properties is to use <a href="http://webfx.eae.net/tools/filtertool.html" target="_blank">WebFX&#8217;s Filter Tool</a>, you can also check the <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/reference.asp" target="_blank">Microsoft Documentation</a>, except this has been updated to work with the IE5.5+ method of applying filters.</p>
<p class="clWinHeading">Internet Explorer 5.5+</p>
<p>With IE5 Microsoft have changed the way filters are applied, they still use the filter property of the style tag, but uses different syntax.  In HTML:</p>
<p><code>style="<span class="clsLiteral">filter:progid:DXImageTransform.Microsoft.</span>DropShadow<span class="clsLiteral">(</span>Color=red, OffX=2, OffY=2, Positive=1<span class="clsLiteral">)&#8221;;</span></code></p>
<p>and from code:</p>
<p><code>document.all["drop"].style.filter = "<span class="clsLiteral">progid:DXImageTransform.Microsoft.</span>DropShadow<span class="clsLiteral">(</span>Color=red, OffX=2, OffY=2, Positive=1<span class="clsLiteral">)&#8221;;</span></code></p>
<p>If you look at the <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/reference.asp" target="_blank">Microsoft Documentation</a> you will notice several other filters such as Light, Compositor and Matrix.  These work a little differently than the others and probably best if you look at the specific documentation when you are interested.</p>
<p class="clContent">&nbsp;</p>
<h3 class="clWinHeading">Transitions</h3>
<p class="clContent"><script language="javascript"><!-- 	var state=0; 	var verse2 = "From the ashs a fire shall be woken,
&nbsp;&nbsp;&nbsp; A light from the shadows shall spring;
Renewed shall be blade that was broken:
&nbsp;&nbsp; The crownless again shall be king."; 	var verse1 = "All that is gold does not glitter,
&nbsp;&nbsp;&nbsp; Not all those who wander are lost;
The old that is strong does not wither,
&nbsp;&nbsp;&nbsp; Deep roots are not reached by the frost."; 	 	function doFadeImage() { 	  //create object reference 	  var el = document.all["divFader"]; 	   	  //add the filter to the style tag 	  el.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=1)"; 	   	  //apply the filter 	  el.filters[0].apply(); 	   	  //change the object 	  if(state) { 	    el.style.backgroundColor = "#BDAA91"; 	    el.style.color = "#000000"; 	    el.innerHTML = verse1; 	    state = 0;  	  } else { 	    el.style.backgroundColor = "#000000"; 	    el.style.color = "#BDAA91"; 	    el.innerHTML = verse2; 	    state = 1;     	  } 	   	  //play the filter 	  el.filters[0].play(); 	}   //--></script></p>
<p>These (as far as I am aware) only work in Internet Explorer 5.5+ for Windows.   It is therefore necessary to start off with a browser and OS check.  See the <a href="http://www.dhtmlcentral.com/tutorials/tutorial3.asp">DHTML library</a> tutorial for more info about that.</p>
<table bgcolor="#c0c0c0" border="0" cellpadding="0" cellspacing="1">
<tr>
<td colspan="2" bgcolor="#ffffff" valign="top">First off here is a       list of the transitions that you can use:</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» barn</td>
<td bgcolor="#ffffff" valign="top">resembles a door opening or       closing</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» blinds</td>
<td bgcolor="#ffffff" valign="top">appears to open or close blinds</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» checkerBoard</td>
<td bgcolor="#ffffff" valign="top">squares are uncovered like a       checkerboard over original content</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» fade</td>
<td bgcolor="#ffffff" valign="top">fades new content in</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» gradientWipe</td>
<td bgcolor="#ffffff" valign="top">passes a gradient band over the       old content</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» inset</td>
<td bgcolor="#ffffff" valign="top">reveals new content diagonally</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» iris</td>
<td bgcolor="#ffffff" valign="top">produces an effect like the       opening of a camera</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» radialWipe</td>
<td bgcolor="#ffffff" valign="top">like a windscreen wiper</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» randomBars</td>
<td bgcolor="#ffffff" valign="top">exposes random lines of pixels one       at a time</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">»       randomDissolve</td>
<td bgcolor="#ffffff" valign="top">exposes random pixels one at a       time</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» slide</td>
<td bgcolor="#ffffff" valign="top">new content slides in over old       content</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» spiral</td>
<td bgcolor="#ffffff" valign="top">reveals new content in a spiral       motion</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» stretch</td>
<td bgcolor="#ffffff" valign="top">stretching motion to cover       original content; like a cube rotating</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» strips</td>
<td bgcolor="#ffffff" valign="top">moves successive strips into place</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» wheel</td>
<td bgcolor="#ffffff" valign="top">like spokes of a wheel uncovering       new content</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» zigzag</td>
<td bgcolor="#ffffff" valign="top">reveals new content with a forward       and backwards motion down the object</td>
</tr>
</table>
<p>Now we need to know how to use them.  To find the properties of each transition look at the <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/reference.asp" target="_blank">Microsoft Documentation</a> (if I find the time I may make a utility similar to the WebFX one linked above).</p>
<p>We&#8217;ll start off with the fade transition that takes a single property &#8220;duration&#8221;:</p>
<p><span id="divFader" style="padding: 4px; background-color: #bdaa91; color: #000000; font-family: times new roman; font-style: italic; font-size: 12px; width: 225px">   All that is gold does not glitter,<br />
Not all those who wander are lost;<br />
The old that is strong does not wither,<br />
Deep roots are not reached by the frost. </span><a href="javascript:doFadeImage()">do fade</a></p>
<p>Now here is the function that does the above:</p>
<p><code>function doFadeImage() {<br />
//create object reference<br />
var el = document.all["divFader"];</p>
<p>//add the filter to the style tag<br />
el.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=1)";</p>
<p>//apply the filter<br />
el.filters[0].apply();</p>
<p>//change the object<br />
if(state) {<br />
el.style.backgroundColor = "#BDAA91";<br />
el.style.color = "#000000";<br />
el.innerHTML = verse1;<br />
state = 0;<br />
} else {<br />
el.style.backgroundColor = "#000000";<br />
el.style.color = "#BDAA91";<br />
el.innerHTML = verse2;<br />
state = 1;<br />
}</p>
<p>//play the filter<br />
el.filters[0].play();<br />
}</code></p>
<p>Now this may seem a bit complicated so I&#8217;ll brake it down into 4 important stages:<br />
1.  Add the <strong> filter</strong> to the style attribute, either through code or in the HTML<br />
2.  Use the code <code>el.filters[0].apply();</code> to <strong> initiate</strong> the transition<br />
3.  Make the <strong>change</strong>s to the object through code<br />
4.  <strong>Play</strong> the changes using <code> el.filters[0].play();</code></p>
<p>To see how to use transitions with the CoolMenus script check <a href="http://www.dhtmlcentral.com/coolmenus/examples/withoutframes/menu14.html">example 14</a> where you can try all the different filters.</p>
<p>Good luck!</p>
<h3 class="clWinHeading">Appendix A - The Matrix Transformation</h3>
<p class="clContent">In the field of Computer Graphics matrices are used to speed up and simplify certain calculations. For example, your 3D-graphcs card has special hardware that uses a 4&#215;4 matrix to rotate, translate or stretch points in 3-dimensions, thus speeding up calculations that are normally done by the main processor.</p>
<p>In Internet Explorer 5, Microsoft have included a Matrix Filter. This, obviously, only works in 2-dimensions but it can be used to apply a transformation to all pixels in an object.</p>
<p><strong>Matrix Math</strong><br />
To get you started here is a brief introduction to 2D matrix multiplication:</p>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>x</td>
<td rowspan="2">*</td>
<td>a</td>
<td>b</td>
<td rowspan="2">=</td>
<td>x*a         + y*b</td>
</tr>
<tr>
<td>y</td>
<td>c</td>
<td>d</td>
<td>x*c         + y*d</td>
</tr>
</table>
<p>Now, if this is applied to each pixel in an image, we can get  some very interesting results.</p>
<p><strong>Example: rotation</strong><br />
In order to rotate a point around the origin (0,0) you can find the new values of x and y using the following equations (if you don&#8217;t believe here&#8217;s a proof for one of the equations):</p>
<pre>newX = x*cos(Ø) - y*sin(Ø)
newY = x*sin(Ø) + y*cos(Ø)</pre>
<p>Now it can be seen that we can use the following matrix to rotate a point:</p>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>x</td>
<td rowspan="2">*</td>
<td align="center">cos(Ø)</td>
<td align="center">-sin(Ø)</td>
<td rowspan="2">=</td>
<td>x*cos(Ø)         - y*sin(Ø)</td>
</tr>
<tr>
<td>y</td>
<td align="center">sin(Ø)</td>
<td align="center">cos(Ø)</td>
<td>x*sin(Ø)         + y*cos(Ø)</td>
</tr>
</table>
<p><strong>Using the Matrix Filter</strong></p>
<table bgcolor="#c0c0c0" border="0" cellpadding="0" cellspacing="1">
<tr>
<td colspan="2" bgcolor="#ffffff" valign="top">Here is list of the       matrix filter&#8217;s properties:</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» FilterType</td>
<td bgcolor="#ffffff" valign="top"><strong>bilinear</strong> - uses an average       of the 4 nearest pixels; smoother but slower  <strong>nearest</strong> - nearest neighbour, uses best approximation,       faster but jagged</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» SizingMethod</td>
<td bgcolor="#ffffff" valign="top"><strong>clip to original</strong> - if       transformed image exceeds the initial dimensions it will be clipped to fit<br />
<strong>auto expand</strong> - automatically increases/decreases size of       container</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» M11, M12,       M21, M22</td>
<td bgcolor="#ffffff" valign="top">the values of the 2D-matrix (a,b,c,d       as above)</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" width="200">» Dx, Dy</td>
<td bgcolor="#ffffff" valign="top">used for linear transformations</td>
</tr>
</table>
<p>The matrix filter can be applied through either the style tag or using code. To apply it using the style tag apply the properties use the same method that is described for normal filters. In code it is slightly different:</p>
<pre>var el = document.getElementById(name);
el.style.filter = "progid:DXImageTransform.Microsoft.Matrix()";
el.filters.item("DXImageTransform.Microsoft.Matrix").[property] = [value];</pre>
<p><strong>Example</strong><br />
<script language="javascript"><!-- if(bw.ie &#038;&#038; !bw.mac &#038;&#038; !bw.ie4) {   document.write(\'</p>
<div style="position: relative; top: 0; left: 200; width: 75; height: 75;">&#8216;     +&#8217;</p>
<div id="aDiv" style="position: absolute; width: 50; height: 50; background-color: silver; border: 1 solid gray">&#8216;       +&#8217;</p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td align="center" valign="middle">&#8216;           +&#8217;</p>
<p style="font-face: tahoma, arial, helvetica; font-size: 10px">Spin!!&#8217;         +&#8217;</td>
</tr>
</table>
<p>&#8216;     +&#8217;</p></div>
<p>&#8216;   +&#8217;</p></div>
<p>&#8216;)   } else document.write(&#8217;Example only works on explorer 5+ on windows.&#8217;)  function rotate(name, angle){ 	//convert angle into radians 	var rad = degToRad(angle); 	//calculate cos and sin of the angle 	costheta = Math.cos(rad); 	sintheta = Math.sin(rad); 	 	//create object reference 	var el = document.getElementById(name); 	if(el) { 		//apply the filter 		el.style.filter = &#8220;progid:DXImageTransform.Microsoft.Matrix()&#8221;; 		 		//set up the properties 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).SizingMethod = &#8220;auto expand&#8221;; 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).FilterType = &#8220;bilinear&#8221;;  		//apply the rotation matrix transformation 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).M11 = costheta; 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).M12 = -sintheta; 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).M21 = sintheta; 		el.filters.item(&#8221;DXImageTransform.Microsoft.Matrix&#8221;).M22 = costheta; 	} }  var angle = 0; function doRotate() { 	//check to make sure angle is between 0 and 360 degrees 	if(angle>360) angle-=360; 	//increment angle 	angle+=15; 	 	//do rotation 	rotate(&#8221;aDiv&#8221;,angle); 	 	//recentre div using offset values 	var el = document.getElementById(&#8221;aDiv&#8221;) 	el.style.top = 25 - (el.offsetHeight/2); 	el.style.left = 25 - (el.offsetWidth/2); 		 	setTimeout(&#8221;doRotate();&#8221;,10); }  var pi = Math.PI; function degToRad(x) { return ( x/(360/(2*pi)) ); } function radToDeg(x) { return ( x*(360/(2*pi)) ); }  if(bw.ie &#038;&#038; !bw.mac &#038;&#038; !bw.ie4) doRotate() //&#8211;></script>Example only works on explorer 5+ on windows. This example uses the rotation matrix described above to cause the box to spin. It should be noted that the code has to take into account that the dimensions of the container change size in order to keep the box centred.</p>
<p>Here&#8217;s the code for the function that will rotate an object by an arbitrary angle:</p>
<pre>function rotate(name, angle){ //convert angle into radians
    var rad = degToRad(angle);

    //calculate cos and sin of the angle
    costheta = Math.cos(rad);
    sintheta = Math.sin(rad);

    //create object reference
    var el = document.getElementById(name);
    if(el) {
        //apply the filter
        el.style.filter = "progid:DXImageTransform.Microsoft.Matrix()";

        //set up the properties
        el.filters.item("DXImageTransform.Microsoft.Matrix").SizingMethod = "auto expand";
        el.filters.item("DXImageTransform.Microsoft.Matrix").FilterType = "bilinear";

        //apply the rotation matrix transformation
        el.filters.item("DXImageTransform.Microsoft.Matrix").M11 = costheta;
        el.filters.item("DXImageTransform.Microsoft.Matrix").M12 = -sintheta;
        el.filters.item("DXImageTransform.Microsoft.Matrix").M21 = sintheta;
        el.filters.item("DXImageTransform.Microsoft.Matrix").M22 = costheta;
    }
}</pre>
<p>This code calls the rotation function and recentres the DIV. In order to do this we need to use the offset values since the style&#8217;s properties aren&#8217;t updated:</p>
<pre>var angle = 0;
function doRotate() {
    //check to make sure angle is between 0 and 360 degrees
    if(angle&gt;360) angle-=360;
    //increment angle
    angle+=15;

    //do rotation
    rotate("aDiv",angle);

    //recentre div using offset values
    var el = document.getElementById("aDiv");
    el.style.top = 25 - (el.offsetHeight/2);
    el.style.left = 25 - (el.offsetWidth/2);

    setTimeout("doRotate();",10);
}</pre>
<p>And there you have it!  Have fun playing, and if you want to get further information on the <a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/Matrix.asp" target="_blank">Matrix Filter</a> visit the MSDN site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/filters-and-transitions.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scripting for 5th Generation Browsers Part 1</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-1.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-1.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:29:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-1.php</guid>
		<description><![CDATA[Introduction
]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Introduction</h3>
<p> <a href="http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-1.php#more-9" class="more-link">(more&#8230;)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/scripting-for-5th-generation-browsers-part-1.php/feed</wfw:commentRss>
		</item>
		<item>
		<title>DHTML library</title>
		<link>http://www.dhtmlcentral.com/dhtmlog/dhtml-library.php</link>
		<comments>http://www.dhtmlcentral.com/dhtmlog/dhtml-library.php#comments</comments>
		<pubDate>Sun, 27 May 2007 21:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[DHTML Tutorials]]></category>

		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.dhtmlcentral.com/dhtmlog/dhtml-library.php</guid>
		<description><![CDATA[Object Oriented Programming (OOP) and DHTML
We&#8217;ll divide these lessons in 3 pages guiding you through the building of objects and association of funtions to them.  At the beginning we&#8217;ll just use pointer variables to explain what objects do, and then we&#8217;ll explain  how to properly build objects to assign functions and properties to [...]]]></description>
			<content:encoded><![CDATA[<h3 class="clWinHeading">Object Oriented Programming (OOP) and DHTML</h3>
<p class="clContent">We&#8217;ll divide these lessons in 3 pages guiding you through the building of objects and association of funtions to them.  At the beginning we&#8217;ll just use pointer variables to explain what objects do, and then we&#8217;ll explain  how to properly build objects to assign functions and properties to them, in order  to save up some space and make the code reusable. Finally, before we start to discuss the  library code, we&#8217;ll show you a simple, usable, example to move objects around the window.  So here we go.</p>
<p>Basically, just for starting, you can see an object like a pointer to a layer.  For instance, if you have layerA, using an object constructor you would avoid  having to refer to that layerA as: <code>document.layerA</code> for ns4,  <code>document.all.layerA</code> for ie4+ or  <code>document.getElementById('layerA')</code> for ns5 and ie5+ depending on the browser, everytime you want to use or do anything to that layer.</p>
<p>Once you get this, everything is easier. :-) As an example, a simple (very improveable) object constructor could be:</p>
<pre>if(bw.ns4) {lyrAObj= document.layerA}
if (bw.ie4 || bw.ie5) {document.all.layerA}
if (bw.ns5 || bw.ie55 || bw.ie6) {document.getElementById('layerA')}</pre>
<p>But this is too long, so we could use <strong>booleans</strong> to shorten this a little. A boolean is a way to compare different values in a true/false condition, giving different results depending on the comparison result. The basic use are as follow: <code>varA=(a==3)?1:0</code> will return <code>varA</code> being true if <code>a</code> is equal to <code>3</code> and false if not. To link different comparisons, we can use:</p>
<pre>varA=(a==1)?"case one":(a==2)?"case two":(a==3)?"case three":0</pre>
<p>and so on. In the first case, if a==3 <code>varA</code> will be true, whereas in case two will be &#8220;case three&#8221;. This way we can now look at the constructor again:</p>
<pre>lyrAObj= (bw.ns4)?document.layerA:(bw.ie4 || bw.ie5)?document.all.layerA:
  (bw.ns5 || bw.ie55 || bw.ie6)?document.getElementById('layerA'):0;</pre>
<p>or</p>
<pre>lyrAObj= (bw.ns4)?document.parentLayer.document.layers.layerA:
  (bw.ie4 || bw.ie5)?document.all.layerA:(bw.ns5 || bw.ie55 || bw.ie6)?
  document.getElementById('layerA'):0;</pre>
<p>for nested layers (very important issue in netscape 4), assuming of course you are using Thomas browsercheck function (more on this later).</p>
<p>As we can see, the comparison test would be &#8220;Is the object <code>bw.ns4</code> true?&#8221;. If it&#8217;s true, then the new object <code>lyrAObj</code> will have the value <code>document.layerA</code>, and so on.</p>
<p>Well, the example above tried to do a simple introduction to defining and using objects. But as I said before, the object constructor is a simple one. As you guessed it, if you want to make a new object you will have to write these lines for any object you would need. The solution is using a true object constructor that automatically retrieves all these informations and lets you use any object with any associated function easily.</p>
<h3 class="clWinHeading">Move method</h3>
<p class="clContent">I&#8217;ll start with a very basic example on how we can use this in the real world. Here we&#8217;ll make an object move around the page. The following code uses  the regular browsercheck script, so we&#8217;ll start with this one.</p>
<pre>//Browsercheck (needed) ***************
function lib_bwcheck(){
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")&gt;-1
  this.ie5=(this.ver.indexOf("MSIE 5")&gt;-1 &amp;&amp; this.dom &amp;&amp; !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")&gt;-1 &amp;&amp; this.dom &amp;&amp; !this.opera5)?1:0;
  this.ie4=(document.all &amp;&amp; !this.dom &amp;&amp; !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")&gt;-1
  this.ns6=(this.dom &amp;&amp; parseInt(this.ver) &gt;= 5) ?1:0;
  this.ns4=(document.layers &amp;&amp; !this.dom)?1:0;
  this.bw=(this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}
bw=new lib_bwcheck() //Browsercheck object</pre>
<p>As you can see the browsercheck is in fact an object constructor function <code>lib_bwcheck</code>,  several properties such as <code>ie5</code> or <code>ns4</code> and the instance that really builds  the object <code>bw</code> is <code>bw=new lib_bwcheck()</code>. This way, when the browser reads  this code it builds an object and assigns true to its actual case. For instance, if you&#8217;re surfing with ns4, the script will come out with <code>bw.ns4</code> as true. This is nice to make  comparisons later and use the appropiate code for each browser.</p>
<p>Now we are going to write the layer into the body. We make a div called divTest in the HTML code like this:</p>
<p id="divTest">This is a test div!</p>
<pre>&lt;div id="divTest" style="position:absolute; left:10; top:800; background-color:red; ; color:white"&gt;
This is a test div!
&lt;/div&gt;</pre>
<p>Then below that we add this code (inside a script tag):</p>
<pre>function lib_moveIt(x,y){
  this.css.left=x;
  this.css.top=y;
}

function lib_obj(obj){
  if(bw.ns4)this.css=document.layers[obj]
  else if(bw.ie4)this.css=document.all[obj].style
  else if(document.getElementById) this.css=document.getElementById(obj).style
  this.moveIt=lib_moveIt
  return this
}
oDiv=new lib_obj('divTest')</pre>
<p><script> function moveIt(x,y){   this.css.left=x;   this.css.top=y; }  function lib_obj_(obj){   if(bw.ns4)this.css=document.layers[obj]   else if(bw.ie4)this.css=document.all[obj].style   else if(document.getElementById) this.css=document.getElementById(obj).style   this.moveIt=moveIt   return this } oDiv=new lib_obj_(\\\'divTest\\\') </script>  And we call the <code>moveIt</code> method of the object to move the object around like this with  the arguments <code>x</code> and <code>y</code> which are the left and top values we want to move the object to:</p>
<p>That worked very well now didn&#8217;t it? The big advantage here is that this is very reusable code  and you make as many objects like this you want in a page.</p>
<p>This code should more or less explain itself. It&#8217;s the same as the previous examples except  that we make the <code>this.css</code> property, which is different depending on which  browser the user is using. You&#8217;ll have to see this as the path the browser takes to reach  the layers, which of course, due to the differences among browsers and their implementation  of DOM, is different for each. The <code>this.css</code> points to the already existing object in the browser, so we can use the already existing properties and methods of  that object like we want. Like in the <code>lib_moveIt</code> function where we use  the regular <code>.left</code> and <code>.top</code> properties of the object.</p>
<p>Let me try and explain what happens here, first if the browser is <strong>Netscape 4</strong> this is how it will behave/look:</p>
<pre>function lib_moveIt(x,y){
  this.css.left=x
  this.css.top=y
/*
When this function is called with NS4
(NOTE: This is a function, but it's a method of the lib_obj objects!)
this.css = document.layers["divTest"]
Therefore when I assign a value to this.css.left I am basically
just assigning a value to document.layers["divTest"].left
*/
}

function lib_obj(obj){
  if(bw.ns4)this.css=document.layers[obj] //NS4
  else if(bw.ie4)this.css=document.all[obj].style //IE4 - IE5
  else if(bw.dom) this.css=document.getElementById(obj).style
  this.moveIt=lib_moveIt
return this
}
oDiv=new lib_obj('divTest')
/*
NS4 Will return an object with these properties and methods:
oDiv = [object object]
oDiv.css = document.layers["divTest"]
oDiv.moveIt=lib_moveIt (calls the lib_moveIt function)
*/</pre>
<p>If you have <strong>Explorer 4</strong> it will look like this:</p>
<pre>function lib_moveIt(x,y){
  this.css.left=x
  this.css.top=y
/*
When this function is called with IE4
this.css = document.all["divTest"].style
Therefore when I assign a value to this.css.left I am basically just
assigning a value to document.all["divTest"].style.left
*/
}
function lib_obj(obj){
  if(bw.ns4)this.css=document.layers[obj] //NS4
  else if(bw.ie4)this.css=document.all[obj].style //IE4 - IE5
  else if(bw.dom) this.css=document.getElementById(obj).style //NS6
  this.moveIt=lib_moveIt
  return this
}
oDiv=new lib_obj('divTest')
/*
IE4 Will return an object with these properties and methods:
oDiv = [object]
oDiv.css = document.all["divTest"].style
oDiv.moveIt=lib_moveIt (calls the lib_moveIt function)
*/</pre>
<p>If you have <strong>Explorer 5+ or Netscape 6</strong> it will look like this:</p>
<pre>function lib_moveIt(x,y){
  this.css.left=x
  this.css.top=y
/*
When this function is called with IE5+ or NS6
this.css = document.getElementById(obj).style
Therefore when I assign a value to
this.css.left
I am basically just assigning a value to
document.getElementById(obj).style.left
*/
}
function lib_obj(obj){
  if(bw.ns4)this.css=document.layers[obj] //NS4
  else if(bw.ie4)this.css=document.all[obj].style //IE4 - IE5
  else if(bw.dom) this.css=document.getElementById(obj).style //NS6
  this.moveIt=lib_moveIt
  return this
}
oDiv=new lib_obj('divTest')
/*
IE5+ or NS6 Will return an object with these properties and methods:
oDiv = [object]
oDiv.css = document.getElementById(obj).style
oDiv.moveIt=lib_moveIt (calls the lib_moveIt function)
*/</pre>
<p>We know that this might be hard to understand, but really don&#8217;t know what more to say. Try  and play with this code, add and remove properties and methods to figure out how this works.</p>
<p>We&#8217;ll do 2 more things before we look at the &#8220;real&#8221; code of the library. First off, taking the code  from the top of this page and compress it a little to make it a little nicer:</p>
<pre>function lib_moveIt(x,y){
  this.css.left=x; this.css.top=y
}
function lib_obj(obj){
  this.css=bw.ns4?document.layers[obj]:bw.ie4?document.all[obj].style:
    bw.dom?document.getElementById(obj).style:0;  //This is one line!
  this.moveIt=lib_moveIt
return this
}
oDiv=new lib_obj('divTest')</pre>
<p>We had previously seen the use of booleans, so this should sound logical. It&#8217;s basically the  same as using <code>if / else</code> statements but shorter and more elegant.</p>
<p>Then we will use the <strong>prototype</strong> property of any javascript object that makes it possible  to add methods and properties to an object constructor (and therefore to ALL objects created with  that constructor), without being defined inside the constructor itself. This is helpful because  we can create objects and then assign new properties to them. In this case the constructor  is the <code>lib_obj</code> function. This makes it simpler to add functions:</p>
<pre>function lib_obj(obj){
  this.css=bw.ns4?document.layers[obj]:bw.ie4?document.all[obj].style:
  bw.dom?document.getElementById(obj).style:0; //This is one line!
  return this
}
lib_obj.prototype.moveIt = function(x,y){
  this.css.left=x; this.css.top=y
}
oDiv=new lib_obj('divTest')</pre>
<p>As you can see the object constructor doesn&#8217;t need the <code>this.moveIt= lib_moveIt</code> anymore. The syntax is the following:</p>
<pre>constructorname.prototype.methodname = function(arguments) { }</pre>
<h3 class="clWinHeading">The code</h3>
<pre>Go to project library to see the code</pre>
<p>When you have looked through this one you can go to my new library section where you can go trough each function and get them explained.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dhtmlcentral.com/dhtmlog/dhtml-library.php/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
