// ********************************
// MODAL WINDOW CONTROLS
// ********************************
if (!topWin){
	alert("topWin is not set.  You must set in order to use this liberay");
}

var modalSizes	= $H({
	regWindow:	{width: 400, height: 370},
	tagWindow:	{width: 350, height: 360},
	blocked:	{width: 400, height: 200},
	loginWin:	{width: 350, height: 130},
	thanksWin:	{width: 400, height: 35},
	embedCode:	{width: 370, height: 330},
	regThank:	{width: 425, height: 120},
	createVoki:	{width: 400, height: 260},
	publish:	{width: 375, height: 260},
	sceneSet:	{width: 375, height: 200},
	editorWin:	{width: 570, height: 436},
	changePass:	{width: 300, height: 200},
	forgotPass:	{width: 400, height: 250},
	STAF:		{width: 350, height: 425},
	partTNC:	{width: 500, height: 360},
	partThanks:	{width: 500, height: 260},
	TACWindow:	{width: 375, height: 360}	
});

function getContentProperties() {
	if ($('tblFrame'))
		contentHolder = $('tblFrame');
	else
		contentHolder = document.body;

	contentHeight 	= contentHolder.offsetHeight;
	contentWidth 	= contentHolder.offsetWidth;
}

function detectTopScroll() {
	var scroll_Y;
	if (document.documentElement) {scroll_Y = document.documentElement.scrollTop + document.body.scrollTop;}
	if (window.scrollY) {scroll_Y = window.scrollY;}
	return scroll_Y;
}

function openModalIframe(frameSrc, modalWidth, modalHeight, modalTitle){
	var modalWin	= topWin.Windows.getWindow('modal_window');	
	if (modalWin){		
		resizeModal(modalWidth, modalHeight, modalTitle);
		modalWin.setURL(frameSrc);
		modalWin.setTitle(modalTitle);
		return;
	}

	var win = new Window('modal_window', {
			className:	 	"modalVoki",
			url: 			frameSrc,
			width: 			modalWidth,
			height: 		modalHeight,
			zIndex: 		1000,
			opacity: 		100,
			title:			modalTitle,
			recenterAuto:	true,
			destroyOnClose:	true,
			resizable: 		false,
			maximizable: 	false,
			minimizable: 	false
		}
	);
	
	win.showCenter();
	win.setDestroyOnClose();
	win.show(true);
	$('modal_window_content').allowTransparency = false;
}

function openScrollerIframe(frameSrc, modalWidth, modalHeight, closeCB){
	if (topWin.Windows.getWindow('vk_scroller')){
		topWin.Windows.getWindow('vk_scroller').setURL(frameSrc);
		resizeModal(modalWidth, modalHeight);
		return;
	}

	pageSize	= getPageSize();
	left = Math.floor((pageSize.windowWidth - modalWidth) / 2);
	
	var scroll = new Window('vk_scroller', {
			className:	 	"scroll",
			url: 			frameSrc,
			width: 			modalWidth,
			height: 		modalHeight,
			zIndex: 		1000,
			opacity: 		100,
			bottom:			10,
			left:			left,			
			title:			'My Voki Characters',
			recenterAuto:	false,
			destroyOnClose:	true,
			resizable: 		true,
			maximizable: 	false,
			minimizable: 	false
			}
		);
	
	if (closeCB){
		scroll.setCloseCallback(closeCB);
	}

	scroll.setDestroyOnClose();
	scroll.show(true);
}

function resizeScroller(modalWidth, modalHeight, modalTitle){
	scrollWin	= topWin.Windows.getWindow('vk_scroller');	
	if (!scrollWin){
		return false;
	}
	
	scrollWin.setSize(modalWidth, modalHeight);
	
	if (modalTitle){
		scrollWin.setTitle(modalTitle);
	}		
}

function resizeModal(modalWidth, modalHeight, modalTitle){
	modalWin	= topWin.Windows.getWindow('modal_window');	
	if (!modalWin){
		return false;
	}
	
	modalWin.setSize(modalWidth, modalHeight);
	modalWin.showCenter();
	
	if (modalTitle){
		modalWin.setTitle(modalTitle);
	}		
}

function getModalDem(){
	modalWin	= topWin.Windows.getWindow('modal_window');	
	if (!modalWin){
		return false;
	}

	return modalWin.getSize();	
}

function openModalContent(content, modalWidth, modalHeight, modalTitle){
	modalWin	= topWin.Windows.getWindow('modal_window');
	if (modalWin){
		topWin.Windows.closeAll();
	}

	var win = new Window('modal_window', {
		className:	 	"modalVoki",		
		width: 			modalWidth,
		height: 		modalHeight,
		zIndex: 		1000,
		opacity: 		100,
		title:			modalTitle,
		recenterAuto:	true,
		destroyOnClose:	true,
		resizable: 		false,
		maximizable: 	false,
		minimizable: 	false});
	
	win.getContent().innerHTML 	= content;
	win.getContent().align 		= 'center';
	
	win.showCenter();
	win.setDestroyOnClose();
	win.show(true);
}

function closeModal(){
	if (topWin.Windows.getWindow('modal_window') || topWin.Windows.getWindow('vk_scroller'))
		topWin.Windows.closeAll();
}

/*
function openModalContent(content, modalWidth, modalHeight){

	//content = content + '<input type="button" onclick="voki_edt.SetReturnValue(\'<undefined/>\');" value="click me" />';

	if (topWin.Windows.getWindow('modal_window'))
		topWin.Windows.closeAll();

	if (!contentHolder) {getContentProperties();}

	if(self.innerHeight) {var winHeight = self.innerHeight;}
	else {var winHeight = document.body.clientHeight;}



	if(checkIt('safari') || checkIt('mac') && checkIt('firefox')) {hideFlash();}

	var win = new Window('modal_window', {
		className: 		"modalVoki",
		width:			modalWidth,
		height:			modalHeight,
		zIndex:			150,
		opacity:		1,
		left: 			winLeft,
		top: 			winTop,
		recenterAuto:	false,
		resizable: 		false,
		maximizable: 	false,
		minimizable: 	false});

	win.getContent().innerHTML = content;

	if(checkIt('safari') || checkIt('mac') && checkIt('firefox')) {win.setCloseCallback(showFlash);}

	if (contentHeight > winHeight) {win.showCenter();}
	win.setDestroyOnClose();
	win.show(true);
}
*/


/* universal JS centered window-opening function
function windowOpen(url, winName, width, height, peripherals){

	var screenW = screen.width;
	var screenH	= screen.height;

	// adjust for window sizes that are larger than the user's screen:
	if (width > (screenW - 50)) 	width = screenW - 50;
	if (height > (screenH - 50))	height = screenH - 50;

	// determine x,y for centered window
	var winLeft	= ((screenW - width) / 2) - 16;
	var winTop	= (screenH - height) / 2;

	// open it (peripherals may include resizable, scrollbars, menubar, toolbar, etc)
	var win = window.open(url, winName, "width=" + width + ",height=" + height + ",left=" + winLeft + ",top=" + winTop + (peripherals ? "," + peripherals : ""));
	win.focus();

	return false;
}*/