$(document).ready(function(){
	
	// Fix IE
	//$(document).pngFix(); 

	// Preload all rollovers
	$("#nav img").each(function(){
		// Set the original src
		rollsrc = $(this).attr("src");
		rollON = rollsrc.replace(/.gif$/ig,"_on.gif");
		$("<img>").attr("src", rollON);
	});
	// Navigation rollovers
	$("#nav a").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/_on/);
		// don't do the rollover if state is already ON
		if (!matches) {
		imgsrcON = imgsrc.replace(/.gif$/ig,"_on.gif"); // strip off extension
		$(this).children("img").attr("src", imgsrcON);
		}
		
	});
	$("#nav a").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
	
	// Tab Navigation
	$("#tabs a").click(function(e) {
		e.preventDefault();
		// hide the old content
		$("#tab_content div.content").each(function(){ $(this).hide(); });
		// deselect all tabs
		$("#tabs img").each(function(){
			new_src = $(this).attr("src").replace(/_on.gif$/ig,".gif");
			$(this).attr("src", new_src);
		});
		// swap the image
		img = $(this).children("img").eq(0);
		new_src = img.attr("src").replace(/.gif$/ig,"_on.gif");
		img.attr("src", new_src);
		// show the new content
		div = $(this).attr("href");
		$(div).show();
	});
	// Show the first tab
	$("#tabs a:first").trigger("click");
	
	// Warn users about external links
	$("ol.references a").click(function(){
		alert('You are now leaving the mederma.com website.');
	});
	
	// More detailed warning
	$("#store_list a").click(function(){
		alert('Note: You are leaving Mederma.com. Merz Pharmaceuticals, LLC does not have control over this web site and does not make any representations or warranties. Merz has received no compensation for providing this link.');
	}); 
	
});

function show_video(the_vid) {
	
	$('#video_container').show();
	$('#video_container').append('<div id="video_close"><a href="javascript:hide_video();"><img src="/images/closebox.png" /></a></div><div id="video"></div>');
	var params = { 
		allowscriptaccess: "always", 
		allowfullscreen: "true",
		flashvars: "file=/swf/" + the_vid + ".flv"
	}
	swfobject.embedSWF("/swf/player.swf", "video", "328", "200", "8", false, false, params);
}

function hide_video() {
	$('#video_container').empty().hide();
}