jQuery(document).ready(function(){
	
	jQuery(".video-panel:not(:first)").hide();

	jQuery(".video-panel:first").show();
	
	jQuery("#thumbs a").click(function(){
		stringref = jQuery(this).attr("href").split('#')[1];

		jQuery('.video-panel:not(#'+stringref+')').hide();

		$(this.parentNode).addClass("selected");
		
		if (jQuery.browser.msie && jQuery.browser.version.substr(0,3) == "6.0") {
			jQuery('.video-panel#' + stringref).show();
		}
		else 
			jQuery('.video-panel#' + stringref).fadeIn();
		
		return false;
	});
	
});

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
	var parent = targetElement.parentNode;
	
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

function preparePlaceholder() {
	
	try {
		
		var placeholder = document.createElement("img");
		placeholder.setAttribute("id","placeholder");
		placeholder.setAttribute("src","http://www.inthesaucepan.com/clients/boyer/media/video/video-01.png");
		placeholder.setAttribute("alt","Featured Video");
		
		var description = document.createElement("p");
		description.setAttribute("id","description");
	
		var desctext = document.createTextNode("A Selection of Featured Videos");
		description.appendChild(desctext);
		
		var gallery = document.getElementById("thumbs");
		
		//	New Code
		
		gallery.parentNode.insertBefore(placeholder,gallery);
		gallery.parentNode.insertBefore(description,gallery);
		
		//	End New Code
		
		
		/* Orginal Code
		insertAfter(placeholder,gallery);
		
		insertAfter(description,placeholder);
		*/
	
	} catch(e) {
		//return false;		
	}
	
}

function prepareGallery() {

	try {	
		var gallery = document.getElementById("thumbs");
		var links = gallery.getElementsByTagName("a");
		
		for ( var i=0; i < links.length; i++) {
			
			links[i].onclick = function() {
		  		return showPic(this);
			}
			
			links[i].onkeypress = links[i].onclick;
		}
	} catch(e) {
		return false;
	}
	
}

function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
  if (description.firstChild.nodeType == 3) {
    description.firstChild.nodeValue = text;
  }
  return false;
}

addLoadEvent(preparePlaceholder);
addLoadEvent(prepareGallery);
