var IE = (navigator.appName=="Microsoft Internet Explorer")? true:false;
var OPERA = (window.opera)? true:false;
var LeftScreen,TopScreen,clipX, clipY;

ContactPic = new Image();
AdressePic = new Image();
NewsMenuPic = new Image();
CustomPic = new Image();
var LeftBg;
var timer1,timerloading,timermenu;
var Landing=false;
AD = new Object;
Theme = new Array();
Destination = new Array();
TOURS = new Array();
HomePics = new Array();
ThemeSlideImages = new Array();
HomeSlidePics = new Array();
StaffSlidePics = new Array();
for (i=0;i<6;i++){
	ThemeSlideImages[i] = new Image();
	StaffSlidePics[i] = new Image();
	}

activateHome = function(){
xDisplay('preload','none');xDisplay('animation','none');
HomePics.push(new Image());
HomePics[0].src = xGetElementById('screen_pic').src;
xGetElementById('screen_pic2').src = HomePics[0].src;
getHomeSlidePics();
LeftBg = xGetComputedStyle('page_setup', "left",true);
AD  = new activeDisplay(10,150,'control');//counterspeed,menuspacing,displaybox
//xClip('control',0,xWidth('control'),0,0);
//xClip('ContactForm',0,xWidth('ContactForm'),0,0);
//xClip('CustomForm',0,xWidth('CustomForm'),0,0);
xClip('control',xHeight('control'),xWidth('control'),xHeight('control'),0);
xClip('ContactForm',xHeight('ContactForm'),xWidth('ContactForm'),xHeight('ContactForm'),0);
xClip('CustomForm',xHeight('CustomForm'),xWidth('CustomForm'),xHeight('CustomForm'),0);
xShow('TextBox');xShow('highlights');xShow('heading');xShow('logo');
xOpacity('navigation',0.1);

removeBlankNodes('browser');//remove blank spaces (which are taken as nodes by FireFox) through the all tree of the element
removeBlankNodes('tourinfo');
removeBlankNodes('scroller');
removeBlankNodes('topnav');
removeBlankNodes('loadingbar');

positionne();
var name = testFormRedirect('form');//test form redirect
var hometext = xGetElementById('home');
if (name) hometext.innerHTML = formThankYou(name);
else Landing = testLandingPage('D');//Destination
if (!name && !Landing) Landing = testLandingPage('T');//Countries
if (!name && !Landing) Landing = testLandingPage('C');//Tour
if (!Landing){
	AD.activebox.displaybox = 'home';
	AD.activebox.slideImages = HomeSlidePics;
	}
xShow('top_frame');xShow('film_frame');xShow('screen_pic');xShow('screen_pic2');
if (!Landing) xDisplay("home","block"); else xDisplay("home","none");
timerloading = setTimeout(function(){loading(0,1)},1000);
loadPackages();
}

function testLandingPage(varname){
var url = window.location.href;
var qparts = url.split("?");
if (qparts.length<=1) return false;
var vars = qparts[1].split("&");
ld = new Object();
for (i=0;i<vars.length;i++){
  var parts = vars[i].split("=");
  if (parts[0] == varname){
		ld.page = varname;
		ld.index = parts[1];
		ld.index = unescape(ld.index);// Convert escape code
		ld.index.replace(/\+/g," ");// Convert "+"s to " "s
		break;
  		}
  } 
return ld.page?ld:false;
}

function activateMenus(){
setCustomForm('CountryChoiceForm');
setCustomForm('ActivityChoiceForm');
xDisplay('packages','block');
AD.homemenu=setMainMenu('topnav');
spaceNavigation();
var timerselection  = setTimeout(function(){activateMainMenu();flipMenu(true);xDisplay("home_navigation",'block');rotateHomePics(0);preloadSlidePics();},300);
if (Landing) {
	clearTimeout(timerloading);
	resetLoading();
	var delay=1;
	if (Landing.page == 'D') {
		var selection = Destination[Landing.index].links;
		selection.sectiontitle = Destination[Landing.index].tname;
		AD.refmainmenu.previous = selection;
		setSelectionTitle(selection.sectiontitle);
		}
	if (Landing.page == 'T') {
		var selection = Theme[Landing.index].links;
		selection.sectiontitle = Theme[Landing.index].tname;
		AD.refmainmenu.previous = selection;
		setSelectionTitle(selection.sectiontitle);
		}
	if (Landing.page == 'C') {var selection = TOURS[Landing.index];selection.index = Landing.index;selection.rst=true;}
	selection.preloadSlides = true;
	if (!selection.notready) clearTimeout(timerselection);
		else selection.rst=false;delay=700;
	setTimeout(function(){loadSelection(selection);},delay);
	}
}

function getHomeSlidePics(){
slideroot=xGetElementById('slidenav');
var spacer = xGetElementsByClassName('slidespacer',slideroot,'div');
var DivWidth=0;
var tr = xGetElementsByClassName('picSlide',slideroot,'img');
for (i=0; i<tr.length; i++) {
	var img = tr[i].src.indexOf("#");
	if (img==-1) {
		DivWidth += tr[i].width+14;
		HomeSlidePics.push(new Image());
		HomeSlidePics[HomeSlidePics.length-1].src = tr[i].src;
		xWidth(spacer[i],tr[i].width+2);
		} else xDisplay(tr[i].parentNode,"none");
	}
xWidth('slidenav',DivWidth);
}

function spaceNavigation(){
var IconLeft = 0;
var X;
for (i=0; i< AD.homemenu.length; i++) if (AD.homemenu[i].parentNode.className=="firstlevel"){//1st Level
		xLeft(AD.homemenu[i],IconLeft*AD.menuspacing);
		IconLeft++;		
		}
xShow('navigation');
}

function activeDisplay(counterspeed,menuspacing,displaybox) {
this.counterspeed = 20+counterspeed;
this.screencounter=10;
this.menucounter=1;
this.slidecounter = 10;
this.textocounter=1;//home showing
this.menuspacing=menuspacing;
this.displaybox = displaybox;
this.activebox=new Object();//this set the home layer as showing on the home page
this.refmainmenu = new Object();//active buttons reference
this.reftourmenu = new Object();//active buttons reference
}

function displayLoading(){
loading(100,1);
xDisplay("animation","block");
}

function loading(inc,dir){
var bar = xGetElementById('loadingbar');
xDisplay(bar,"block");
if(inc<xWidth(bar)){
	inc+=5*dir;
	bar.firstChild.style.marginLeft = inc + "px"; 
	timerloading = setTimeout(function(){loading(inc,dir)},200);
	} else {clearTimeout(timerloading);resetLoading();}
}

function resetLoading(){
var bar = xGetElementById('loadingbar');
bar.firstChild.style.marginLeft = 100 + "px";
xDisplay(bar,"none");
}

function removeBlankNodes(ele){
var e = xGetElementById(ele);
e.nodecounter=0;
cleanBlankNodes(e);
}

function cleanBlankNodes(ele){//3 is node type TextNode!!!
if (ele.nodeName == "SPAN") return; 
for (i=0; i<ele.childNodes.length;i++) if (ele.childNodes[i].nodeType == 3) ele.removeChild(ele.childNodes[i]); else ele.childNodes[i].nodecounter=0; 
while (ele.nodecounter<ele.childNodes.length) {
	ele.nodecounter++;	
	if(ele.childNodes[ele.nodecounter-1].lastChild) cleanBlankNodes(ele.childNodes[ele.nodecounter-1]);
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function positionne(){
if (xClientWidth() < xWidth('positionable_layer')+LeftBg){
	xWidth('page_setup',xClientWidth()-LeftBg);
	xLeft('page_setup',Math.round(LeftBg/2));
	xLeft('positionable_layer', xWidth('page_setup')-xWidth('positionable_layer'));
	}
	else {
		xLeft('positionable_layer',0);
		xWidth('page_setup',xWidth('positionable_layer'));
		xLeft('page_setup',Math.round((xClientWidth()-xWidth('positionable_layer'))/2));
	}
if (xClientHeight() > xHeight('page_setup')) xTop('page_setup',Math.round((xClientHeight()-xHeight('page_setup'))/2)); else xTop('page_setup',0);
}

function waitFrameLoading(ele,iframe){
if(!iframe.loaded) iframe.timer=setTimeout(function(){waitFrameLoading(ele,iframe);},40);
	else {clearTimeout(iframe.timer);ele.readSelectedPage();}
}

window.onscroll = function(){setTimeout("positionne()",50)};
window.onresize = function(){setTimeout("positionne()",50)};
