var extendedDesign=false;

var timeTimer;
var objMiniFrame1;
var objMiniFrame2;
var objBigFrame1;
var objBigFrame2;
var objTargetFrame;
var objAboutFrame;
var objMoreBlock;
var objQuoteBlock;
var objTopLine;
var objTable;
var localMargin=10;
var usedTopBar=0;
var brWidth=3;
var usedH=0;
var usedW=0;
var toFadeFrame;
var otherFrame;
var dateSpan;
var timeSpan;
var usedLang = detectLanguage().toLowerCase();;
var csBase="http://www.8dimensions.com/index_cs.html?"

if (document.location.href.indexOf("?")>-1) {//specifically this language was requested
  usedLang="en"
  }
 else
  {
  if (usedLang.indexOf('cs') > -1) {
    //use czech localization
		//+++document.location.href=csBase
	  usedLang="en"
		}
	 else {//use english
	  usedLang="en"
	  }	
  }

function writeDateTime() {
 dateSpan.innerHTML = getDateStr();
 timeSpan.innerHTML = getTimeStr();
}

function checkSizes() {
 if (!extendedDesign) return; //nothing to do
 
 var l_width=winW();
 var l_height=winH()
 var l_topBar=objTopLine.offsetHeight+objTopLine.offsetTop+2;
 if (l_height==usedH && l_width==usedW && l_topBar==usedtopBar)
   return; //same size don't change anything
	else
	 {
	 usedH=l_height;
	 usedW=l_width;
	 }
	 
 if (usedTopBar!=l_topBar) {
   usedtopBar=l_topBar;
   } 
	  
 var l_centerH=l_width/2;
 var l_centerV=(l_height-l_topBar)/2;
 var l_w= Math.floor(l_centerH-1.5*localMargin-2*brWidth);
 var l_h=Math.floor(l_centerV-1.5*localMargin-2*brWidth);
 l_centerV+=l_topBar;
 l_height-=l_topBar+2*localMargin+2*brWidth;
 l_width-=2*localMargin+2*brWidth;
 //MiniFrame1 
 objMiniFrame1.style.width=l_w+"px";
 objMiniFrame1.style.height=l_h+"px";
 objMiniFrame1.style.top=localMargin+l_topBar+"px";
 objMiniFrame1.style.left=Math.round(l_centerH+localMargin/2)+"px";
 
 //MiniFrame2 
 objMiniFrame2.style.width=l_w+"px";
 objMiniFrame2.style.height=l_h+"px";
 objMiniFrame2.style.top = Math.round(l_centerV+localMargin/2)+"px";
 objMiniFrame2.style.left = localMargin+"px";

 //Table
 objTable.style.top = objMiniFrame1.style.top;
 objTable.style.left = objMiniFrame2.style.left;
 objTable.style.width = objMiniFrame2.style.width;
 objTable.style.height = objMiniFrame1.style.height; 
 
 //MoreDiv
 var l_borderWidth=3;
 objMoreBlock.style.width = objMiniFrame2.style.width;
 objAboutFrame.width = objMiniFrame2.style.width;
 objAboutFrame.height = (l_h-objMoreBlock.offsetHeight+"px");

 //QuoteDiv
 objQuoteBlock.style.left = objMiniFrame1.style.left;
 objQuoteBlock.style.top = objMiniFrame2.style.top;
 objQuoteBlock.style.width = objMiniFrame1.style.width;
 objQuoteBlock.style.height = objMiniFrame2.style.height;
 
 if (transparencySupported) {
   //big frames
   objBigFrame1.style.top = objMiniFrame1.style.top;
   objBigFrame1.style.left = objMiniFrame2.style.left;
   objBigFrame1.style.width=l_width+"px";
   objBigFrame1.style.height=l_height+"px"; 

   objBigFrame2.style.top = objMiniFrame1.style.top;
   objBigFrame2.style.left = objMiniFrame2.style.left;
   objBigFrame2.style.width=l_width+"px";
   objBigFrame2.style.height=l_height+"px";
	 }
	else { //the target frame is the valid one 
   objTargetFrame.style.top = objMiniFrame1.style.top;
   objTargetFrame.style.left = objMiniFrame2.style.left;
   objTargetFrame.style.width=l_width+"px";
   objTargetFrame.style.height=l_height+"px"; 
	 }  
}

function fadeInDocument(in_Window) {
 //fade in document
 if (!extendedDesign)
   return false; //simple style
 if (in_Window.name=='tt_frame') {
	 if (in_Window.location.search=="?stay")
	   return true;//no redirecting, initial value
	 //set links to localizations correctly	 
	 var l_activeDoc=fileOfHref(in_Window.location.href);
   document.getElementById("Link2cs").href = csBase+l_activeDoc;
	 //change document	 	 
   if (transparencySupported) {
	   if (toFadeFrame.name=="ff1_frame") {
  		 window.ff1_frame.location.replace(in_Window.location.href);
			 //window.ff1_frame.location.href=in_Window.location.href;
			 }
			else 
			 {
			 //window.ff2_frame.location.href=in_Window.location.href;
  		 window.ff2_frame.location.replace(in_Window.location.href);
			 }
 /*    toFadeFrame.src=in_Window.document.location.href;*/
     fadeIn(toFadeFrame,300,fadeInFinished,0.05);
     toFadeFrame.style.display='';
     toFadeFrame.style.zIndex++;
  	 return true;
		 }
		else {
	   objTargetFrame.style.display='';
		 objMiniFrame1.style.display='none';
	   objMiniFrame2.style.display='none';
		 return false;
		 }
 	 }
	else { //loaded into another frame, don't care
	 return false;
	 } 
}

function fadeOutDocument() {
 if (!extendedDesign)
   return; //simple style
 //change links to localized versions	 
 document.getElementById("Link2cs").href = csBase;
 //show document
 if (transparencySupported) {
   toFadeFrame.style.display = 'none'
   setOpacity(toFadeFrame,0);
	 fadeOut(otherFrame,300,fadeOutFinished,0.95);
   }
	else {
	 objTargetFrame.style.display = 'none';
	 objMiniFrame1.style.display='';
   objMiniFrame2.style.display='';
	 }  
}

function fadeInFinished(in_Obj) {
 setOpacity(otherFrame,0);
 otherFrame.style.display = 'none';
 
 var l_temp=toFadeFrame;
 toFadeFrame=otherFrame;
 otherFrame=l_temp;
}

function fadeOutFinished() {
 setOpacity(otherFrame,0);
 otherFrame.style.display = 'none'

 setOpacity(toFadeFrame,0);
 toFadeFrame.style.display = 'none';
}

var czFlags = new Array();

function init() {
   //set time display
   writeDateTime();
   timeTimer=setInterval(writeDateTime,333);
	 
	 //set size checking
   setInterval(checkSizes,40);
	 //quote
   document.getElementById('QuoteCell').innerHTML=randomQuote();
	 //proload flags
	 czFlags[0] = new Image();
	 czFlags[0].src='images/CzechFlag_bw.gif';
	 czFlags[1] = new Image();
	 czFlags[1].src='images/CzechFlag.gif';
	 //test if some subpage to be displayed
	 var l_subpage=window.location.search.substr(1);
	 if (l_subpage!="") {
		 //objTargetFrame.src=usedLang+"/"+l_subpage;
		 if (l_subpage.indexOf("guestbook")==0) //special handling for guestbook
  	   window.tt_frame.location.replace("guestbook/guestbook_"+usedLang+".php");
		  else
  	   window.tt_frame.location.replace(usedLang+"/"+l_subpage);
		 }
} 

function writeObjects() {
 document.write('<iframe name="tt_frame" id="Dim8TargetFrame" class="" src="en/about.html?stay" frameborder="0"></iframe>');
 if (!document.getElementById) return;
 document.write('<div id="MiniFrame2" class="idxfrm" scrolling="no" style="display:none;">');
 document.write('<iframe id="AboutFrame" class="idxfrm" scrolling="no" src="en/about.html" frameborder="0"></iframe>');
 document.write('<div id="MoreBlock"><a href="en/about.html">more...</a></div>');
 document.write('</div>');
 document.write('<iframe name="ff1_frame" id="FadingFrame1" class="idxfrm" style="display:none;width:200px;height:250px;filter:progid:DXImageTransform.Microsoft.alpha(opacity=0);opacity:0;-moz-opacity:0;-khtml-opacity:0;" frameborder="0"></iframe>');
 document.write('<iframe name="ff2_frame" id="FadingFrame2" class="idxfrm" style="display:none;width:200px;height:250px;filter:progid:DXImageTransform.Microsoft.alpha(opacity=0);opacity:0;-moz-opacity:0;-khtml-opacity:0;" frameborder="0"></iframe>'); 
 document.write('<table id="QuoteBlock" style="position:absolute;"><tbody><tr><td id="QuoteCell" style="text-align:left;vertical-align:middle;padding:10px"></td></tr></tbody></table>');
}

function identifyObjects() {
   dateSpan=window.document.getElementById("datespan");
   timeSpan=window.document.getElementById("timespan");

	 objBigFrame1=document.getElementById("FadingFrame1");
	 objBigFrame2=document.getElementById("FadingFrame2");
	 identifyTransparencyOnObject(objBigFrame1);
	 objMiniFrame1=document.getElementById("NewsBox");
	 objMiniFrame2=document.getElementById("MiniFrame2");
   objTopLine=document.getElementById("TopLine");
	 objTable=document.getElementById("Table8Dimensions");
	 objTargetFrame=document.getElementById("Dim8TargetFrame");
	 objMoreBlock=document.getElementById("MoreBlock");
	 objQuoteBlock=document.getElementById("QuoteBlock");
	 objAboutFrame=document.getElementById("AboutFrame");
	 
	 toFadeFrame=objBigFrame1;
	 otherFrame=objBigFrame2;

 if (objMiniFrame1)
   extendedDesign=true;
}

function visualizePage() {
 if (!extendedDesign)
   return;
//chnage overflow: hidden;
 document.body.style.overflow="hidden";
 //asign correct classes
 objMiniFrame1.className=objMiniFrame2.className;
 objTargetFrame.className=objMiniFrame2.className;
 //hide not interesting items & show correct
 checkSizes();
 objMiniFrame2.style.display = '';
 objTargetFrame.style.display = 'none';
 objTargetFrame.style.margin = '0px';
}

function fileOfHref(in_Href) {
 var l_pos=in_Href.lastIndexOf("/");
 if (l_pos==-1)
   return in_Href;
  else
   return in_Href.substr(l_pos+1);	
}
