<?php
	$title = "smokinggun | SOURCE CODE";
	
	$nav_link = "/demos/index.php";
	$nav_image = "title_source.png";
	
# this should be stripped out when put on the live site
	require("../path_to_lib.php");

#
# tool for managaing catalog categories
# 

	require($path_to_lib."sg_main.php"); 		# main library

# include the html snippets for drawing the interface
	include($path_to_lib."html/public_html.php");

echo $public_header;

echo <<<HTML

Swaps two DOM objects.
<br><br>

<a href="#" onclick="toggleObjectDisplay('info')">Info</a> |

<a href="#" onclick="toggleObjectDisplay('source')">Source</a>


<fieldset id="source">
<legend>sg_swapNode source</legend>
	<pre>
	<samp id="samp">
	view source for the JS code
	</samp>
	</pre>
</fieldset>

<fieldset  id="info">
<legend>Info</legend>
Swaps object0 with object1.
<br>
<br>
This was meant as a solution to IE for Windows proprietary swapNode method.<br>
<br>
<b>Note:</b> Events are not cloned.  You will need to add event cloning to this, if required.
<br>

Could use better error detection.
<br>
<br>

<b>Syntax</b>
	<blockquote>
	<i>
	sg_swapNode(object0,object1);
	</i>
	</blockquote>
	<blockquote>
	<i>
	nObject0 = sg_swapNode(object0,object1); //will return the cloned object0
	</i>
	</blockquote>
	
<b>Example</b>
	<blockquote>
	<samp>
objA = document.getElementById("obj0");<br>
objB = document.getElementById("obj1");<br>
sg_swapNode(objA,objB);<br>
/* or */<br>
t = sg_swapNode(objA,objB);<br>
	</samp>
	</blockquote>
</fieldset>

<style type="text/css">
	.object {
		color:#FFFFFF;
		width:30px; height:30px; 
		
		border:1px #000000 solid; 
		text-align:right; 
		margin:5px;
		padding:5px}
		
	.parent {
		float:left;
		text-align:center;
		margin:5px;
		width:60px;
		border:1px #cccccc solid;
		padding:5px;
		height:100px;
		}
</style>
<p>
<a href="javascript:swapSameParent()">swap 0 &amp; 1</a> | <a href="javascript:swapDifferentParent()">swap 0 &amp; 2</a>
</p>
<div class="parent">
	<div id="obj0" class="object" style="background:#cccccc">0</div> 
	<div id="obj1" class="object" style="background:#999999">1</div>
</div>
<div class="parent">
	<div id="obj2" class="object" style="background:#99FF33">2</div> 
	<div id="obj3" class="object" style="background:#3399FF">3</div>
</div>
<div style="clear:both; font:1px mono">&nbsp;</div>



<script type="text/javascript" id="js_source">


/*

Copyright (C) 2001 John Weir www.smokinggun.com

This code is free for use.  If possible include the copyright.

*/

function sg_swapNode(objA,objB)
	{
	if (objA != null && objB != null)
		{
		tempObjB = objB.cloneNode(true);
		tempObjA = objA.cloneNode(true);
	
		objB.parentNode.insertBefore(tempObjA,objB);
		objA.parentNode.insertBefore(tempObjB,objA);
	
		objA.parentNode.removeChild(objA);
		objB.parentNode.removeChild(objB);
		
		return tempObjA;
		}
	
	//else handle error
	
	}
</script>

<script type="text/javascript" id="non_public">
function swapSameParent()
	{
	objA = document.getElementById("obj0");
	objB = document.getElementById("obj1");
	t = sg_swapNode(objA,objB);
	}
	
function swapDifferentParent()
	{
	objA = document.getElementById("obj0");
	objB = document.getElementById("obj2");
	sg_swapNode(objA,objB)
	}
</script>

HTML;

echo $public_footer;

?>

