var catalogus_id = 0;
var catalogus_flash;

function OpenCatalogus(id) {
	catdiv = $("flipflash_catalog");
	FadeToBlack("show");
	catdiv.show();	
	catalogus_id  = id;
	url = "/flipflash/front/get_catinfo.asp?id=" + encodeURIComponent(id);
	$("flipflash_title").innerHTML = "Catalogus";
	$("flash").innerHTML = "Catalogus wordt ingeladen... Even geduld..";
	
	new Ajax.Request(url, {
		method: 'post',
		onSuccess: function(transport) {
			var xotree = new XML.ObjTree();			
			var catxml = xotree.parseDOM(transport.responseXML.documentElement);
			
			flash_width = catxml.catalogus.flash_width;
			flash_height = catxml.catalogus.flash_height;
			box_width = catxml.catalogus.box_width;
			box_height = catxml.catalogus.box_height;
			
			
			catdiv.style.width = box_width + "px";
			catdiv.style.height = box_height + "px";
			catdiv.style.marginLeft = "-" + (box_width / 2) + "px";
			catdiv.style.marginTop = "-" + (box_height / 2) + "px";
		
			$("flipflash_title").innerHTML = catxml.catalogus.title;
			
			flashurl = encodeURIComponent("/flipflash/front/get_cat.asp?id=" + id);
			var FO = {	
					movie:"/flipflash/front/pageviewer.swf",
					width: flash_width,
					height: flash_height,
					majorversion:"7",build:"0",						
					flashvars:"xmlFile=" + flashurl
					};		
			catalogus_flash = UFO.create(	FO, "flash");
	
		},
		onFailure: function(transport) {
			alert("Failed to load catalog.\n" + transport.responseText);		
		}

	});
		
}

function CloseCatalog() {
	FadeToBlack("hide");
	catalogus_flash = null;
	$("flipflash_catalog").hide();	
}


function FadeToBlack(action) {
	DivBlack = $("flipflash_black");
	
	if (action == "show") {
		DivBlack.show();	
	} else {
		DivBlack.hide();	
	}
}

function CenteredPopupWindow(url, name, winw, winh, style) { // Centered popup
	var winl = (screen.width - winw) / 2;
	var wint = (screen.height - winh) / 2;
	if (style == '') {
		wstyle = ',location=0,menubar=0,resizable=1,toolbar=0,status=1,scrollbars=1,modal=1';
	} else { wstyle = ',' + style; }
	rwin = window.open(url, name, 'left='+ winl +',top='+ wint +',height='+ winh + ',width=' + winw + wstyle);
	return rwin;
}

function openPage(id) {
	if (id != 0) {
		// alert("Open page" + id);
		CenteredPopupWindow("/flipflash/front/catalogus.asp?action=showpage&page=" + id + "&id=" + catalogus_id , "pageviewer", 640, 480, "");
	}
}

function ShowWaitText(id) {
	$("catlink_" + id).innerHTML = "Even wachten de download wordt gestart..";
}

