// Link and image swap Javascript - Jonathan Vincent, 09.17.2010 01:55:58AM
//
// This Javascript replaces the source of an image on the page as well as altering the link applied to it and the title of that link, all simultaneously.
// Permission is given freely by the author to use/modify/redistribute this JavaScript at will.  I don't care. jv
//
// Declaring all the variables used in the image/link swapping function below.
var m1
var m2
var m3
var img
var link
		      
    // Simple linkswapping function.						
	function linkswap(m1,m2,m3) {  // Syntax: linkswap(Link ID, Preview frame ID, Preview frame thumbnail location)
	img = m2 + 'pic' ; link = m2 + 'link';
	document.getElementById(img).src = m3; // Set the source picture of the preview frame to the string contained in m3.
	document.getElementById(link).href = document.getElementById(m1).href;  // Set the href of the picture frame to match the calling link.
    document.getElementById(link).title = document.getElementById(m1).title;  // Set the title of the picture frame to match the calling link.
	// Sadly, it's easier to pass the information here manually using the m1 variable than it is to use the event object across different browser standards.
	return true;	
	}

// Here's an example of how this works:
//
// First, the linked image:
// <a title="My dog Sparky." id="sparkylink" href="sparkypicture1.jpg">
// <img id="sparkypic" src="sparkythumbnail1.jpg" width="1000" height="1000" /></a>
//
// Then, the mouseover link that changes it:
// <a title="Another picture of Sparky" id="1" href="sparkypicture2.jpg" onMouseOver="linkswap('1','sparky','sparkythumbnail2.jpg')">Another picture!</a>
//
// Upon triggering the mouseover, the script appends 'pic' and 'link' to sparky (m2), saves them as variables (img) and (link)
// Then, the script changes the SRC of "sparkypic" (img) to match (m3)which is 'sparkythumbnail2.jpg'
// At which point it sets the HREF of (link) to the HREF of the link with the id of "1" (m1)
// It then sets the TITLE of (link) to the TITLE of the link with the id of "1" (m1)
//
// Resulting in these changes to the linked image for the browser:
// <a title="Another picture of Sparky" id="sparkylink" href="sparkypicture2.jpg">
// <img id="sparkypic" src="sparkythumbnail2.jpg" width="1000" height="1000" /></a>


