jQuery.noConflict(); //so as not to conflict with prototype library w/ lightwindow script

//js to swap image for webcam link

jQuery.fn.swapDiv = function(id2swap, href2replace)
{
	//id2swap contains a passed id value for the img for whom to swap the src attribute
	
	var counter = 0;
	
	//---- do the following on initial fcn call: -----/
	jQuery(this).each(function()
	{
		//first store the href
		var anchorHref = jQuery(this).attr('href');
		
		var anchorCaption = jQuery(this).attr('title');
		
		//replace href with a # so that those w/ js enabled don't see the image by itself in a new window
		jQuery(this).attr('href','#');
	
		//make a new attribute rel to store former href
		jQuery(this).attr('rel',anchorHref);
	
		//----- on click of the anchor, swap the src attribute of id2swap img --------- /
		jQuery(this).click(function()
  		{
			//below added due to needed to password protected the northlake webcam imgs
			//therefore, if the webCamImage had an anchor with an href="#", IE would still
			//try to display an empty lightwindow
			
			//solution: wrap the #webCamImage with the anchor only when the webcam is clicked
			if(counter == 0) //only do the following once...
			{
				jQuery(id2swap).wrap('<a id="'+href2replace.replace("#","")+'" class="lightwindow" title="Some Title" caption="Some Caption" href="#"></a>');
				
				lightwindowInit(); //call lightwindow
				
				jQuery('#webCamLinks').append('<br /><em class="small_copy">Click image for larger version.</em>');
				
				++counter; //increment counter
			}
			
			//remove class of current from all links
			jQuery(this).parent().children('a').not(this).removeClass('current');
			
			//add class of 'current' to current clicked link
			jQuery(this).addClass('current');
			
			var currentTitle = jQuery('#webCamLinks a.current').attr('title');
			
			//replace current caption with title from clicked anchor
			jQuery(href2replace).attr('caption', currentTitle);
			
			//replace current title with title from clicked anchor
			jQuery(href2replace).attr('title', currentTitle);
			
			//replace current href with title from clicked anchor
			//jQuery(href2replace).attr('caption',jQuery(this).attr('title'));
		
			//store this again since it gets updated below
			var anchorRel = jQuery(this).attr('rel');
		
			//swap the image src
			jQuery(id2swap).attr('src',anchorRel);
		
			//swap href of #bigImg
			var newBigHref = anchorRel; //this calling anchor's href
			
			var lastSlash = newBigHref.lastIndexOf("/") + 1;
			
			newBigHref = newBigHref.slice(0,lastSlash);
			
			newBigHref = newBigHref + '800x600.jpg';
			
			jQuery(href2replace).attr('href', newBigHref);
		});
	});
	
	return this; //chainable
}

jQuery(document).ready(function()
{
	//replace current caption with title from clicked anchor
	//jQuery('#bigImg').attr('caption', jQuery('#webCamLinks a.current').attr('title'));
	
	jQuery('#webCamLinks a').swapDiv('#webCamImage','#bigImg'); //'#webCamImage','#bigImg'
});