$(function() {
 	$("body").addClass("js")
	
	if ($.browser.msie && $.browser.version < 7) {
		$('img[@src$=.png]').ifixpng();
	}
	$("a[title^='New Window: ']").each(function(){
		var newtitle = String($(this).attr('title')).substr(String("New Window: ").length)
		$(this).attr('title',newtitle).click(function() {
			var newwin = window.open(this.href,"newwindow");
			newwin.focus();
			return false;
		});
	});
	
	
PreviewBox = {
	$popup:$("#media_popup"),
	Init:function() {
		PreviewBox.currentvid=1;
			PreviewBox.$popup.children('p').remove();
			PreviewBox.$popup.children('h2').remove();
			$("#media_popup-content").css({width:"388px",height:"265px",position:"relative",top:0,left:0,overflow:"hidden"});
			$("#media_popup-col1").append("<object width=\"320\" height=\"265\"><param name=\"movie\" value=\"http://www.youtube.com/v/l94-rfw4pp0&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/l94-rfw4pp0&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"265\"></embed></object>");
		$("#media_popup-col2").append("<object width=\"320\" height=\"265\"><param name=\"movie\" value=\"http://www.youtube.com/v/FmnUQXC7rNI&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/FmnUQXC7rNI&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"265\"></embed></object>");
		$("#media_popup-col3").append("<object width=\"320\" height=\"265\"><param name=\"movie\" value=\"http://www.youtube.com/v/pXT1lQKLMRQ&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/pXT1lQKLMRQ&amp;hl=en&amp;fs=1&amp;rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"320\" height=\"265\"></embed></object>");
			$('#media_popup-cols').css({width:"320px",position:"absolute",left:"32px",top:"0px"}).children('div').hide();
			$("#media_popup-col"+PreviewBox.currentvid).show();
			PreviewBox.$popup.appendTo('body').dialog({
				modal:true,
				height:324,
				width:418,
				autoOpen:false,
				overlay:{background:"#000000",opacity:0.6},
				resizable:false,
				draggable:false
			});
			$("#ui-dialog-title-media_popup").text("The Circularity of Life: Interview Part "+PreviewBox.currentvid)
			$("<button title=\"Previous\">&laquo; <span>Previous</span></button>").css({position:"absolute",color:"#fff",left:"0px",top:"0px",width:"24px",height:"265px",border:"1px #999 solid",background:"#444",cursor:"pointer"}).hover(function() { $(this).css({background:"#777"}); },function() { $(this).css({background:"#444"}); }).click(function() { PreviewBox.Previous(); return false; }).appendTo('#media_popup-content').children('span').css({'display':'none'});
			$("<button title=\"Next\"><span>Next</span> &raquo;</button>").css({position:"absolute",color:"#fff",left:"360px",top:"0px",width:"24px",height:"265px",border:"1px #999 solid",background:"#444",cursor:"pointer"}).hover(function() { $(this).css({background:"#777"}); },function() { $(this).css({background:"#444"}); }).click(function() { PreviewBox.Next(); return false; }).appendTo('#media_popup-content').children('span').css({'display':'none'});
	},
	HandleKeyDown:function(e) { 
		/*if(e.keyCode == 27) { // escape
			PreviewBox.Hide();
		}else */if(e.keyCode == 13){ // enter
			PreviewBox.Hide();
		}else if(e.keyCode == 38){ // arrow up
			PreviewBox.Previous();
		}else if(e.keyCode == 40){ // arrow down
			PreviewBox.Next();
		}else if(e.keyCode == 37){ // arrow left
			PreviewBox.Previous();
		}else if(e.keyCode == 39){ // arrow right
			PreviewBox.Next();
		}
	},
	Show:function() {
		PreviewBox.$popup.dialog("open")
		$(document).bind('keydown.pbHandleKeyDown',PreviewBox.HandleKeyDown).bind('click.pbHide',PreviewBox.Hide);
	},
	Hide:function() {
		PreviewBox.$popup.dialog("close")
		$(document).unbind('keydown.pbHandleKeyDown').unbind('click.pbHide');
	},
	Next:function() {
		PreviewBox.currentvid++;
		if(PreviewBox.currentvid>3){
			PreviewBox.currentvid = 1;
		}
		$("#ui-dialog-title-media_popup").text("The Circularity of Life: Interview Part "+PreviewBox.currentvid)
		$('#media_popup-cols').children('div').hide();
		$("#media_popup-col"+PreviewBox.currentvid).show();
	},
	Previous:function() {
		PreviewBox.currentvid--;
		if(PreviewBox.currentvid<1){
			PreviewBox.currentvid = 3;
		}
		$("#ui-dialog-title-media_popup").text("The Circularity of Life: Interview Part "+PreviewBox.currentvid)
		$('#media_popup-cols').children('div').hide();
		$("#media_popup-col"+PreviewBox.currentvid).show();
	}
}
	
	
	if($("#showvids").length>0){
		PreviewBox.Init()
		$('#showvids').unbind('click').click(function() { PreviewBox.Show(); return false; });
	}
	
 });

function showquote(quote_num) {
	//document.getElementById(in_obj).className = 'selected';
	blockquotes = document.getElementsByTagName('blockquote');
	for(var i = 0; i<blockquotes.length;i++){
		bq_span = blockquotes[i].getElementsByTagName('span');
		if(blockquotes[i].id=="quote_"+quote_num){
			bq_span[0].style.display = "inline";
			bq_span[1].style.display = "none";
		}else{
			bq_span[1].style.display = "inline";
			bq_span[0].style.display = "none";
		}
	}
}
function hide_infobox() {
	document.getElementById('quotebox').style.display = 'none';
}
	