//JavaScript Document
var currentview = 0; // This is the variable that holds the currently open
// view node.


function showview(theview) { // this shows or hides the view selected from
	// the
	// left column
	var viewname = "#listbox" + theview;
	var itemname = "#view" + theview;
	var fullname = viewname + ".viewitembox";
	if (theview == currentview) { // this means the open node was clicked
		// again
		$("#view1,#view2,#view3,#view4,#view5").removeClass("viewselected");
		currentview = 0;
		$(".viewitembox").hide();
	} else {
		// first lets hide all the open ones
		$(".viewitembox").hide(200);
		$(viewname).show(200);
		$(fullname).addClass("block");
		$("#view1,#view2,#view3,#view4,#view5").removeClass("viewselected");
		$(itemname).addClass("viewselected");
		currentview = theview
	}
}

function changeThumbSize(newsize) {
	if (newsize <= 120) {
		$("div.captionbox").hide();
		$("div.controlcaption").hide();
	} else {
		$("div.captionbox").show();
		$("div.controlcaption").show();
	}
	var newsizevar = newsize + "px";
	$("div.picturebox").css( {
		'height' : newsizevar,
		'width' : newsizevar
	})
}
function showDialog(url, title, width, height) { //shows the dialog using Jquery UI dialog
        if( width == undefined)
            width = 920;
        if( height == undefined)
            height = 640;

	$('#dialog').dialog( {
                width : width,
                height : height,
		modal : true,
		draggable : true,
                title : title,
		resizable : false,
		buttons : {
			"Close" : function() {
				$(this).dialog("close");
			}
		}
	});
	// place target file into dialogcontents and set up the tabs in the dialog
	$('#dialog').load( url, function() {
	});
}

function showDialogNoButtons(url, title, width, height) { //shows the dialog using Jquery UI dialog
        if( width == undefined)
            width = 920;
        if( height == undefined)
            height = 640;

	$('#dialog').dialog( {
                width : width,
                height : height,
		modal : true,
		draggable : true,
                title : title,
		resizable : false,
		buttons : null
	});
	// place target file into dialogcontents and set up the tabs in the dialog
	$('#dialog').load( url, function() {
	});
}

function hideDialog() {
	$('#dialog').dialog("close");
	clearDialog();
}
function setTab(theTab) { // This manages the selected tab, hides the others
							// and
	// sets the right styles
	// First lets make all the tabs non selected
	$("#tabstrip li").removeClass("selected");
	// hide all the tabbody divs
	$("div.tabbody").hide();
	// select the clicked one
	var clickedone = "#tab" + theTab;

	$(clickedone).addClass("selected");
	// show the right div
	var theTabBody = "#tb" + theTab;
	$(theTabBody).show();
}

function vselect(theView) { // sets the controller for the right view and then
	// calls the right view
	var theoffset = "left " + (theView - 1) * -22 + "px";
	var viewfiles = [ "list-thumbs.htm", "list-table.htm", "list-cards.htm" ];
	$("#viewselect").css( {
		'background-position' : theoffset
	});
	// code to actually change the views including a functioncall to set up
	// the tooltip connection\
	$("#listarea").load(viewfiles[theView - 1], function() {
		setUpInfoTips();
	});

}


function callEdit(theview, theevent, file, title, width, height) {
	// this is called when the user chooses
	// to edit a view list.
//	clearDialog();
	if (width == undefined)
		width = 330;
	if (height == undefined)
		height = 320;

	$('#dialog').dialog( {
		width : width,
		height : height,
		modal : true,
		draggable : true,
		title : title,
		resizable : false,
		buttons : {
			"New" : function() {
				addItem();
			},
			"Update" : function() {
				updateItem()
			},
			"Delete" : function() {
				deleteItem();
			}
		}

	});
	// place target file into dialogcontents
	$('#dialog').load(file);

	stopThePropagation(theevent); // this is used so we don't trigger the
	// onclick
	// of the parent div

}

function stopThePropagation(e) {
	if (!e)
		var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}
function setRights() { // shows the right pane for the rights selection
	var theValue = $('#rightstype').val();
	$("#royalty5").hide();
	$("#royalty6").hide();
	if (theValue == 5) {
		$("#royalty5").show();
	}
	if (theValue == 6) {
		$("#royalty6").show();
	}
}

function itemListClick() { // copies the selected item to edit field
	var theString = $('#itemlist :selected').text();
	$("#itementer").val(theString);
	$("#itementer").focus();
}

function deleteItem() { // will delete an item from the itemlist
	$('#itemlist :selected').remove();
	$("#itementer").val("");
}

function addItem() { // adds an item to the itemlist
	var thestring = $("#itementer").val();
	var thevalue = $('#itemlist').append(
			$("<option></option>").attr("value", thevalue).text(thestring));
	$("#itementer").val("");
}

function updateItem() { // updates the selected item
	$('#itemlist :selected').text($("#itementer").val());
}

function clearDialog(){
    $('#dialog').html('');
}