$(document).ready(function(){
	$("<div id='viewOverlay'></div>")
		.css({
			 opacity : 0.5,
			 position: "absolute",
			 top: 0,
			 left: 0,
			 backgroundColor: "#fff",
			 width: "100%",
			 height: $(document).height(),
			 zIndex: 100,
			 display: "none"
		})
		.appendTo($("body"));
	
	$("<div id='viewWrapper'></div>")
		.css({
			 position: "absolute",
			 top: 25,
			 left: 0,
			 width: "100%",
			 height: $(document).height(),
			 zIndex: 150,
			 display: "none"
		})
		.appendTo($("body"));

	
	$("<div id='viewWindow'></div>")
		.css({
			 position: "relative",
			 top: 20,
			 width: "940px",
			 height: "574px",
			 zIndex: 200,
			 margin: "auto",
			 display: "none"
		})
		.appendTo($("#viewWrapper"));


	$("<div id='popupOverlay'></div>")
		.css({
			opacity :0.54,
			position: "absolute",
			top: 0,
			left: 0,
			backgroundColor: "#fff",
			width: "100%",
			height: $(document).height(),
			zIndex: 100,
			display: "none"
		})
		.appendTo($("body"));
	$("<div id='popupWrapper'></div>")
		.css({
			position: "absolute",
			top: 25,
			left: 0,
			width: "100%",
			height: $(document).height(),
			zIndex: 150,
			display: "none"
		})
		.appendTo($("body"));

	$("<div id='popupWindow'></div>")
		.css({
			position: "relative",
			top:20,
			width: "500px",
			zIndex: 200,
			margin: "auto",
			display: "none"
		})
		.appendTo($("#popupWrapper"));

	$.fn.media.mapFormat('mp3', 'quicktime');
});

function clearIDInput(e)
{
	/*$('#loginid').keydown(function(event)
	{
		if(event.keyCode == 9)
		{
			alert('clear');
			changePW();
		}
	});
	*/
	if (e.value==e.name || e.value=="E-mail or RCI ID") e.value="";
}

function changePW()
{	
	$('#pw1').hide();
	$('#pw2').show(0,function(){$('#password').focus()});

}

function restorePW()
{
	if($('#password').val() =="")
	{
		$('#pw2').hide();
		$('#pw1').show();
	}
}

function unclearIDInput(e){
//alert('double');
if(e.value=='')e.value=e.name;
}

function unclearLoginInput(e){
if(e.value=='')e.value="E-mail or RCI ID";
}

function popupOpen(screen)
{
	$("#popupWrapper").css({display: "block"});
	$("#popupWindow").fadeIn(300);
	$("#popupOverlay").fadeIn(300);

	if (screen=="fb")
		$("#popupWindow").load('../template/view_feedback.php');
	if (screen=="uv")
		$("#popupWindow").load('../template/upload_video.php');
	if (screen=="up")
		$("#popupWindow").load('../template/upload_photo.php');
	if (screen=="ua")
		$("#popupWindow").load('../template/upload_audio.php');
	if (screen=="cn")
		$("#popupWindow").load('../template/create_note.php');
	if (screen=="ce")
		$("#popupWindow").load('../template/create_event.php');
	if (screen=="cm")
		$("#popupWindow").load('../template/post_comment.php');
	if (screen=="ee"){
		$("#popupWindow").load('../template/edit_event.php'); 
		populate_event_popup();
		}
}

function popupClose()
{	
	$("#popupOverlay").fadeOut(300);
	$("#popupWindow").fadeOut(300, function()
		{
			$("#popupWrapper").css({display: "none"});
		});
}

function viewOpen()
{
	$.ajax({
 		url: '/ajax/get_view.php',
 		dataType: 'json',
  		success: view_launch 
	});
}

function view_launch(resp)
{
	if (resp.view == "B")
	{
		view_blog(resp.eid);
	}
	else if (resp.view == "S")
	{
		view_scrapbook(resp.eid);
	}
	else if (resp.view == "M")
	{
		view_mapview(resp.eid);
	}
	else if (resp.view == "T")
	{
		view_timeline(resp.eid);
	}
}

function blogOpen()
{
	$("#viewWrapper").css({display: "block"});
	$("#viewWindow").fadeIn(300);
	$("#viewOverlay").fadeIn(300);

	$("#viewWindow").load('../template/view_blog.php');
}

function bookOpen()
{
	$("#viewWrapper").css({display: "block"});
	$("#viewWindow").fadeIn(300);
	$("#viewOverlay").fadeIn(300);

	$("#viewWindow").load('../template/view_scrapbook.php');
}

function timelineOpen()
{
	$("#viewWrapper").css({display: "block"});
	$("#viewWindow").fadeIn(300);
	$("#viewOverlay").fadeIn(300);

	$("#viewWindow").load('../template/view_timeline.php');
}

function mapviewOpen()
{
	$("#viewWrapper").css({display: "block"});
	$("#viewWindow").fadeIn(300);
	$("#viewOverlay").fadeIn(300);

	$("#viewWindow").load('../template/view_mapview.php');
}

function viewClose() 
{
	$("#viewOverlay").fadeOut(300);
	$("#viewWindow").fadeOut(300, function()
		{
		  $("#viewWrapper").css({display: "none"});
		});
}

function change_view(view, eid)
{
	if (view == 3)
		$("#viewWindow").fadeOut(300, function() { view_scrapbook(eid); } );
	else if (view == 4)
		$("#viewWindow").fadeOut(300, function() { view_blog(eid); } );
	else if (view == 2)
		$("#viewWindow").fadeOut(300, function() { view_timeline(eid); } );
	else if (view == 1)
		$("#viewWindow").fadeOut(300, function() { view_mapview(eid); } );
}

