$(document).ready(function(){

	// open external links in new window
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");  

	// place the items on the map according to the link's rel (x:y coordinates)
	$('#map li').each(function(){
		var coords = $(this).children('a:first').attr('rel');
		var coordArray = coords.split(':');
		var thisLeft = coordArray[0]+'px';
		var thisTop = coordArray[1]+'px';
		$(this).css({
			'top':thisTop,
			'left':thisLeft,
			'display':'block'
		});
	});

	// creates embed code
	function buildEmbedCode(id) {
		$('div#dialog').html('<object width="640" height="385">' + 
			'<param name="movie" value="http://www.youtube.com/v/'+id+'&amp;hl=en&amp;fs=1" />' + 
			'<param name="allowFullScreen" value="true" />' + 
			'<param name="allowscriptaccess" value="always" />' + 
			'<embed src="http://www.youtube.com/v/'+id+'&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed>' + 
		'</object>');
	}

	// Initialize the dialog box
	$('div#dialog').dialog({
		bgiframe: true,
		autoOpen: false,
		height: 450,
		width: 670,
		modal: true
	});

	// activate proper dialog box on click
	$('ul#map a[href]').click(function(){
		var urlParts = $(this).attr('href').split('?');
		var vidId = urlParts[1].substr(2);
		buildEmbedCode(vidId);
		$('div#dialog').dialog('option','title', 'Brutal Legend Item Guide: '+$(this).attr('title'));
		$('div#dialog').dialog('open');
		return false;
	});

});

function showMe (it, box) {
var vis = (box.checked) ? "visible" : "hidden";
document.getElementById(it).style.visibility = vis;
}

