function showBk(a) {
	
	var motherOfAllDivs = document.getElementById("bk");
	
	var bgDiv = document.createElement("div");
	bgDiv.className = "background";
	bgDiv.id = "bk-background";
	bgDiv.style.display = "none";
	
	new Effect.Appear('bk-background',{from: 0, to: 0.5, duration: 2, fps:100, afterFinish: insertBk(a, bgDiv, false)});
	
	// insertBk(a, bgDiv);
	
	//showPopupSize("http://www.blaetterkatalog.de/demo/" + a + "/index.html", "Blaetterkatalog", 1024, 768, null);
}

function showBkStandard(a) {
	var motherOfAllDivs = document.getElementById("bk");
	
	var bgDiv = document.createElement("div");
	bgDiv.className = "background";
	bgDiv.id = "bk-background";
	bgDiv.style.display = "none";
	
	new Effect.Appear('bk-background',{from: 0, to: 0.5, duration: 2, fps:100, afterFinish: insertBk(a, bgDiv, true)});
	
	//insertBk(a, bgDiv);
}


function insertBk(bkName, backgroundElement, fixSizeForStandard) {
	/* var bkDemoBaseUrl = "http://localhost/blaetterkatalog-de/demos/"; --> Check with full quali-url */
	var bkDemoBaseUrl = "demo/";
	/* var bkDemoFilename = "index.php"; */
	var bkDemoFilename = "/index.html";

	// Disable Scrolling
	document.body.style.overflow = "hidden";
	document.body.scroll = "no";
	
	$top = getScroll();

	document.getElementsByTagName("html")[0].style.width = "100%";

	// Open Bk
	var motherOfAllDivs = document.getElementById("bk");
	
//	var bgDiv = document.createElement("div");
//	bgDiv.className = "background";
	var bgDiv = backgroundElement;

	bgDiv.style.width = "100%";
	bgDiv.style.margin = "0px 0px 0px 0px";
	bgDiv.style.padding = "0px 0px 0px 0px";

	var closeDiv = document.createElement("div");
	 if (fixSizeForStandard)
  {
	  closeDiv.className = "closeStd";
	  } else {
	  closeDiv.className = "close";
    }
	closeDiv.innerHTML = "<a href=\"#\" onclick=\"closeBK();return false;\">Fenster schlie&szlig;en</a>";
	
	var placeholderDiv = document.createElement("div");
	placeholderDiv.className = "placeholder";
	placeholderDiv.id = "placeholder";
	
	placeholderDiv.innerHtml = "";

	var prefix = bkDemoBaseUrl + bkName + "/";
	
	motherOfAllDivs.appendChild(closeDiv);
	motherOfAllDivs.appendChild(placeholderDiv);
	motherOfAllDivs.appendChild(bgDiv);

  if (fixSizeForStandard)
  {
	 placeholderDiv.style.width = "950px"; 
	 placeholderDiv.style.height = "560px"; 
	 placeholderDiv.style.left = "5%";
	 placeholderDiv.style.top = "5%";
	} else {
	 placeholderDiv.style.width = "90%"; 
	 placeholderDiv.style.height = "90%"; 
	 placeholderDiv.style.left = "5%";
	 placeholderDiv.style.top = "5%";
  }

	// Insert Demokatalog Flash object
	var so = new SWFObject(prefix + "blaetterkatalog/swf/blaetterkatalog.swf", "bkflash", "100%", "100%", "6.0.65", "#FFFFFF");
	so.addVariable("catalog_config", prefix + "blaetterkatalog/xml/");
	so.addVariable("pagenr", "1");
	so.addVariable("menu_path", "/demo/_demo_zum_selbst_blaettern/epaper/blaetterkatalog/menu/list.txt");
	so.addParam("allowScriptAccess", "always");
	so.addParam("allowFullscreen", "true");
	so.addParam("quality", "HIGH");
	so.addParam("bgcolor", "#FFFFFF");

	so.write("placeholder");	
}

function closeBK() {
	
	var bkDiv = document.getElementById("bk");
	
	while (bkDiv.hasChildNodes()) {
		bkDiv.removeChild(bkDiv.firstChild);
	}

	// Enable Scrolling
	document.body.style.overflow = "";
	document.body.scroll = "yes";
	bkDiv.style.width = "0";
	bkDiv.style.height = "0";
	

	
}

function getScroll(){
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){
		if (window.pageYOffset)
        	ScrollTop = window.pageYOffset;
   		else
	        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	return ScrollTop;
}

function toggleModule(mid) 
{	
	disableAllModule(mid);		
	Effect.toggle('mod_'+mid,'appear')
}

function disableAllModule(current_mid) {
	for(i = 0; i < 50; i++) {
		if (i!=current_mid)
		{
  		mod_id = 'mod_'+i;
  		if (document.getElementById(mod_id))
  		{
  			if (i<current_mid) document.getElementById(mod_id).style.display = 'none';	
  			else Effect.Fade(mod_id);
  	  }
		}
	}				
}


function openWhitepaper()
{
var swx = screen.width;
var shx = screen.height;

window.open("http://www.blaetterkatalog.de/content/whitepaper/index.html", "Whitepaper", "screenX=0,screenY=0,width="+swx+",height="+shx+",scrollbars=no,resizable=yes");
 
}


function showPopupSize(page, name, w_width, w_height, scroll) {
	var x = 0, y = 0; // default values
	var width = 660, height = 480; // defaults

	if (document.all) { // MSIE
		x = window.screenLeft;
		y = window.screenTop;
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	} else if (document.layers) { //Netscape
		x = window.screenX;
		y = window.screenY;
		width = window.innerWidth;
		height = window.innerHeight;
	}

	var posX = x + width/2 - w_width/2;
	var posY = y + height/2 - w_height/2;
	var posY = y + height/2 - w_height/2;
	
	// Problem with some browser
	if (posY > 600) {
		posY = 150;
	}
	
    if (scroll == null) {
        scroll = "yes";
    }

	upload = window.open(page, name, "width=" + w_width + ", height=" + w_height + ", top=" + posY + ", left=" + posX + ", resizable=1, scrollbars=" + scroll);
}
