/**
 * @author Marvin Brouwer
 */
// All you have to set is the language, the rest is set in the Css file.
SS_Language = "NL"



if (SS_Language =="NL"){
	SS_LA_Close = "Sluiten"
	SS_Build();
}
if (SS_Language =="EN"){
	SS_LA_Close = "Close"
	SS_Build();
}
if (SS_Language =="FA"){
	SS_LA_Close = "Fermer"
	SS_Build();
}
if (SS_Language =="DE"){
	SS_LA_Close = "Slie&szlig;en"
	SS_Build();
}

window.onload = function SS_SetupLinks(){
	SS_Setup();
	choosePic();
	for (i=0; i < document.links.length; i++) { 
		if(document.links[i].getAttribute('target') == 'SplashScreen'){	
					document.links[i].onclick = function(){
						//get image size:
						var myImage = new Image();
						myImage.onload = function(){
							SS_SLW = myImage.width;
							SS_SLH = myImage.height;
							//Overwrite if atribute of link is defined:
						if(this.getAttribute('W')){SS_SLW = this.getAttribute('W')}
						if(this.getAttribute('H')){SS_SLH = this.getAttribute('H')}
						if(this.getAttribute('title')){SS_SetTitle(this.getAttribute('title'));}
						if(SS_SLW){SS_SetWidth(SS_SLW);};
						if(SS_SLH){SS_SetHeight(SS_SLH)};
						if(this.getAttribute('S')){SS_SetScrl(this.getAttribute('S'))};
						SS_Show();
						}
						myImage.onerror = function(){
							SS_SLW = SS_Standard_WidthVar;
							SS_SLH = SS_Standard_HeightVar;
							//Overwrite if atribute of link is defined:
						if(this.getAttribute('W')){SS_SLW = this.getAttribute('W')}
						if(this.getAttribute('H')){SS_SLH = this.getAttribute('H')}
						if(this.getAttribute('title')){SS_SetTitle(this.getAttribute('title'));}
						if(SS_SLW){SS_SetWidth(SS_SLW);};
						if(SS_SLH){SS_SetHeight(SS_SLH)};
						if(this.getAttribute('S')){SS_SetScrl(this.getAttribute('S'))};
						SS_Show();
						}
						myImage.src = this.href;
					};
					document.links[i].className = 'SS_SplashLink';
		}
		
	} 
}

function SS_Set(SS_Title,SS_W,SS_H,SS_Scrl){
	if(SS_Title){SS_SetTitle(SS_Title);}
	if(SS_W){SS_SetWidth(SS_W);};
	if(SS_H){SS_SetHeight(SS_H)};
	if(SS_Scrl){SS_SetScrl(SS_Scrl)};
	SS_Show();
}
function SS_Show(){
//	Define Elements.												//
	element1 = document.getElementsByTagName('body');
	element2 = document.getElementsByTagName('html');
	element3 = document.getElementById('SS_preCenter');
//	Get scrollpos.													//
//	Special thanks to: 												//
//	http://www.sitepoint.com/article/javascript-from-scratch/6/		//
	 var ScrollPos = 0; 
	 if (typeof window.pageYOffset != 'undefined') 
	 { 
	   ScrollPos = window.pageYOffset 
	} 
	 else if (typeof document.documentElement.scrollTop 
	     != 'undefined' && document.documentElement.scrollTop > 0) 
	 { 
	   ScrollPos = document.documentElement.scrollTop 
	} 
	else if (typeof document.body.scrollTop != 'undefined') 
	 { 
	   ScrollPos = document.body.scrollTop 
	 } 
//	Show Stuff.														//
				element3.style.display = 'block';
				element3.style.position = 'absolute';
				element3.style.top = ScrollPos+'px';
				SS_HideBar();
}
function SS_Close(){
//	Define Elements.												//
	element1 = document.getElementsByTagName('body');
	element2 = document.getElementsByTagName('html');
	element3 = document.getElementById('SS_preCenter');
//	Hide Stuff.														//
				element3.style.display = 'none';
//	Reset Everyting													//
				SS_ShowBar();
				SS_SetTitle('');
				SS_SetWidth(SS_Standard_WidthVar);
				SS_SetHeight(SS_Standard_HeightVar);
				frames['SplashScreen'].location.href = 'about:blank';
}

function SS_SetTitle(SS_TitleVar){
	document.getElementById('SS_Title').innerHTML = SS_TitleVar;
}
function SS_Setup(){
// This gets the widhts and heights of the elements around the iframe to keep te shape.
	//Get the Widths
	SS_L_WidthVar = parseInt(SS_CSS_GetProp('SS_L', 'width'));
	SS_R_WidthVar = parseInt(SS_CSS_GetProp('SS_R', 'width'));
	SS_M_WidthVar = parseInt(SS_CSS_GetProp('SS_M', 'width'));
	SS_SplashScreen_WidthVar = parseInt(SS_CSS_GetProp('SS_SplashScreen', 'width'));
	SS_Splash_WidthVar = parseInt(SS_CSS_GetProp('SS_Splash', 'width'));
	//Get the Heights
	SS_Titlebar_HeightVar = parseInt(SS_CSS_GetProp('SS_Titlebar', 'height'));
	SS_T_HeightVar = parseInt(SS_CSS_GetProp('SS_T', 'height'));
	SS_B_HeightVar = parseInt(SS_CSS_GetProp('SS_B', 'height'));
	SS_M_HeightVar = parseInt(SS_CSS_GetProp('SS_M', 'height'));
	SS_SplashScreen_HeightVar = parseInt(SS_CSS_GetProp('SS_SplashScreen', 'height'));
	SS_Splash_HeightVar = parseInt(SS_CSS_GetProp('SS_Splash', 'height'));
	//For the reset: (normal else did not work)
	//Standard Height
	if(SS_M_HeightVar){SS_Standard_HeightVar = SS_M_HeightVar;};
		//Else
		if(!SS_M_HeightVar){
			if(SS_SplashScreen_HeightVar){SS_Standard_HeightVar = SS_SplashScreen_HeightVar;};
		};
			//Else
			if (!SS_M_HeightVar && !SS_SplashScreen_HeightVar) {
				SS_Standard_HeightVar = SS_Splash_HeightVar*1 - (SS_T_HeightVar*1 + SS_B_HeightVar*1);
			}
	
	//Standard Width
	if(SS_M_WidthVar){SS_Standard_WidthVar = SS_M_WidthVar;};
		//Else
		if(!SS_M_WidthVar){
			if(SS_SplashScreen_WidthVar){SS_Standard_WidthVar = SS_SplashScreen_WidthVar;};
		};
			//Else
			if (!SS_M_WidthVar && !SS_SplashScreen_WidthVar) {
				SS_Standard_WidthVar = SS_Splash_WidthVar*1 - (SS_L_WidthVar*1 + SS_R_WidthVar*1);
			}
}
function SS_SetWidth(SS_WidthVar){
	document.getElementById('SS_SplashScreen').style.width = SS_WidthVar+'px';
	document.getElementById('SS_Titlebar').style.width = SS_WidthVar+'px';
	document.getElementById('SS_T').style.width = SS_WidthVar+'px';
	document.getElementById('SS_M').style.width = SS_WidthVar+'px';
	document.getElementById('SS_B').style.width = SS_WidthVar+'px';
	document.getElementById('SS_Splash').style.width = SS_WidthVar*1+SS_L_WidthVar*1+SS_R_WidthVar*1+'px';
}

function SS_SetHeight(SS_HeightVar){
	document.getElementById('SS_SplashScreen').style.height = SS_HeightVar+'px';
	document.getElementById('SS_L').style.height = SS_HeightVar+'px';
	document.getElementById('SS_M').style.height = SS_HeightVar+'px';
	document.getElementById('SS_R').style.height = SS_HeightVar+'px';
	document.getElementById('SS_Splash').style.height = SS_HeightVar*1+SS_Titlebar_HeightVar*1+SS_T_HeightVar*1+SS_B_HeightVar*1+'px';
}

function SS_SetScrl(SS_ScrlVar){
	if (SS_ScrlVar == "no") {
		document.getElementById('SS_SplashScreen').setAttribute("Scrolling", "no");
		document.getElementById('SS_SplashScreen').setAttribute("Scroll", "no");
	}
	if (SS_ScrlVar == "yes") {
		document.getElementById('SS_SplashScreen').setAttribute("Scrolling", "yes");
		document.getElementById('SS_SplashScreen').setAttribute("Scroll", "yes");
	}
	else{
		return false;
	}
}

function SS_Build(){
	document.write("" +
	"<script>" +
	"	function SS_HideBar(){" +
	//	Define Elements.												//
	"	element1 = document.getElementsByTagName('body');" +
	"	element2 = document.getElementsByTagName('html');" +
	//	Define Scrollbarwidth.											//
	"	ScrlBr = (document.getElementById('ScrlOut').offsetWidth - document.getElementById('ScrlIn').offsetWidth)+'px';" +
	//	Check if Element exists											//
	"		for (i = 0; i < element1.length; i++) {" +
	//	Check if 1/0, show/hide.										//
	//	Show Stuff.														//
	"			element1[i].style.paddingRight = ScrlBr;" +
	"			element2[i].style.overflowY = 'hidden';" +
	"		}" +
	"	}" +
	"	" +
	"	function SS_ShowBar(){" +
	//	Define Elements.												//
	"	element1 = document.getElementsByTagName('body');" +
	"	element2 = document.getElementsByTagName('html');" +
	//	Check if Element exists											//
	"		for (i = 0; i < element1.length; i++) {" +
	//	Check if 1/0, show/hide.										//
	//	Hide Stuff.														//
	"			element1[i].style.paddingRight = '0px';" +
	"			element2[i].style.overflowY = 'scroll';;" +
	"		}" +
	"	}" +
	"" +
	"</script>" +
	"<div id=\"ScrlOut\"><div id=\"ScrlIn\"></div></div>" +
	"<div id=\"SS_preCenter\">" +
	"<div id=\"SS_Shade\" onclick=\"SS_Close();\"></div>" +
	"	<table id=\"SS_Center\" border=\"0\" width=\"100%\" height=\"100%\" cellpadding=\"0\" cellspacing=\"0\">" +
	"		<tr>" +
	"			<td align=\"middle\" valign=\"center\">" +
	"				<div id=\"SS_Splash\" style=\"border:0px none; margin:auto;\">" +
	"				<div id=\"SS_TLT\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"					<div id=\"SS_Titlebar\" style=\"border:0px none; white-space:nowrap; float:left; display:block;\">" +
	"						<div id=\"SS_Title\" style=\"float:left; overflow-x:hidden; white-space:nowrap; width:auto;\"></div>" +
	"						<div id=\"SS_Close\" style=\"width:auto; float:right;\"><a href=\"javascript:;\" onclick=\"SS_Close();\" title=\"" +
	SS_LA_Close +
	"\">" +
	SS_LA_Close +
	"</a></div>" +
	"					</div>" +
	"				<div id=\"SS_TRT\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"				" +
	"				<div id=\"SS_LT\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"				<div id=\"SS_T\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"				<div id=\"SS_RT\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"				" +
	"				<div id=\"SS_L\" style=\"border:0px none; float:left; display:block;\"></div>" +
	"					<div id=\"SS_M\" style=\"border:0px none; float:left; display:block;\">" +
	"						<iframe name=\"SplashScreen\" id=\"SS_SplashScreen\" scrolling=\"auto\" src=\"about:blank\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" style=\"padding:0px; margin:0px;\"></iframe>" +
	"					</div>" +
	"				<div id=\"SS_R\" style=\"border:0px none; float:left; display:block;\"></div>" +
	"				" +
	"				<div id=\"SS_LB\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"				<div id=\"SS_B\" style=\"border:0px none; float:left; display:block;\"></div>" +
	"				<div id=\"SS_RB\" style=\" border:0px none; float:left; display:block;\"></div>" +
	"					<span style=\"clear:all;\"></span></div>" +
	"			</td>" +
	"		</tr>" +
	"	</table>" +
	"</div>" +
	"");
};
	
// We need this function from: 'http://www.webdeveloper.com/forum/archive/index.php/t-32415.html'; to get the startwidth defined in te css.
// Other scripts required style="etc" instead of external css.
// So I have googled until I had found a working script.
function SS_CSS_GetProp(id, property){
	if (document.all) {
	/* IE */
	SS_el = document.all(id);
	}
		else if (document.getElementById) {
		/* W3C DOM */
		SS_el = document.getElementById(id);
		}
			
	if (SS_el.currentStyle) {
	/* IE */
	return SS_el.currentStyle[property];
	}
		else if (window.getComputedStyle) {
		/* W3C DOM */
		var SS_elstyle = window.getComputedStyle(SS_el, "");
		return SS_elstyle.getPropertyValue(property);
		}
} 