function booking_pop(URL) {
var win = window.open('', 'bookpop', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=910,height=570,left='+((screen.availWidth/2) - (910 / 2))+',top =' + ((screen.availHeight/2) - (570 / 2)));
return win;
}


function clear_elements(arr) {
	
	if (arr.length > 0) {
		for (i in arr) {
			if (i == 'compareArrays') continue;
			if (document.getElementById(arr[i])) {
				removeElement(arr[i]);
			}
		}
	}
/*			
	for (var i = 1; i <= max_header; i++) {
		document.getElementById('topimg'+i).src = '';		
		document.getElementById('header'+i).style.visibility = "hidden";		
		document.getElementById('header'+i).style.display = "none";		
	}
	document.getElementById('header1').style.visibility = "visible";		
	document.getElementById('header1').style.display = "";			
*/
}

function navigateTo(elm, main_id, sub_id) {
	if (elm && typeof elm == 'object') {
		elm.blur();
	}
	
	var image2load = new Array();

	if (selected_sub_id > 0) {
		document.getElementById('con'+selected_main_id+'_'+selected_sub_id).className = "";		
	}
	if (selected_main_id > 0) {
		document.getElementById('cat'+selected_main_id).className = "";
	}
	document.getElementById('cat'+main_id).className = "navi_selected";
	load_subnavi(main_id);
	load_content(sub_id);
	
	if (sub_id > 0) {
		document.getElementById('con'+main_id+'_'+sub_id).className = "subnavi_selected";
	}
		
	if (page_fade_arr[sub_id]) {
		
		image2load = page_fade_arr[sub_id].split(",");
		
	} else if (cat_fade_arr[main_id]) {
		
		image2load = cat_fade_arr[main_id].split(",");
		
	} 

	load_image_arr(image2load);
	
	selected_sub_id = sub_id;
	selected_subnotsub_id = sub_id;
	selected_main_id = main_id;	

}

function subnavigateTo(elm, main_id, sub_id, is_sub) {
	elm.blur();
	
	var image2load = new Array();
	
	if (page_fade_arr[sub_id]) {
		
		image2load = page_fade_arr[sub_id].split(",");
				
	} 

	load_image_arr(image2load);

	if (selected_sub_id > 0) {
		//console.log("selected_sub_id = "+selected_sub_id);
		document.getElementById('con'+main_id+'_'+selected_sub_id).className = "";
		/*
		if (!is_sub && document.getElementById('sub'+main_id+'_'+selected_sub_id)) {
			document.getElementById('sub'+main_id+'_'+selected_sub_id).style.display = 'none';
		}
		*/
	}
	if (!is_sub && selected_subnotsub_id > 0 && document.getElementById('sub'+main_id+'_'+selected_subnotsub_id)) {	
		document.getElementById('sub'+main_id+'_'+selected_subnotsub_id).style.display = 'none';	
	}
	
	document.getElementById('con'+main_id+'_'+sub_id).className = "subnavi_selected";	
	
	if (!is_sub && document.getElementById('sub'+main_id+'_'+sub_id)) {
		document.getElementById('sub'+main_id+'_'+sub_id).style.display = '';
	}
	
	load_content(sub_id);	
	selected_sub_id = sub_id;
	if (!is_sub) {
		selected_subnotsub_id = sub_id;
	}
}

function load_content(sub_id) {	
	
	document.getElementById('content_main').innerHTML = '';
	document.getElementById('right_main').innerHTML = '';
	document.getElementById('content_hl').innerHTML = page_title_arr[sub_id];
	
	AjaxRequest.get({
	  	'url':'index.php?load_page='+sub_id,
	    'onSuccess':function(req){ 
	    	 var t_data = eval('(' + req.responseText + ')');
	    	 document.getElementById('content_main').innerHTML = t_data['main'].toString();
	    	 document.getElementById('right_main').innerHTML = t_data['right'].toString();
			if (document.getElementById('firstimg')) { 
				/*
				document.getElementById('rimg2_'+sub_id).onload = function() {	
					//cf3 = new Crossfader( new Array('r1_'+sub_id,'r2_'+sub_id), 800, 1000 );					
				};
				*/
				if (document.getElementById('firstimg') && document.getElementById('firstimg').value > 0) {					
					selected_image_id = document.getElementById('firstimg').value;
					document.getElementById('firstimg').value = '';
					
					//document.getElementById('rimg2_'+sub_id).src = 'images/'+selected_image_id+'.jpg';
					var old_mid_arr = mid_arr;
					mid_arr = new Array();
					var randid = get_random_id();
					
					var newdiv = document.createElement('div');					
				    newdiv.setAttribute('id', 'r1_'+randid);
				    newdiv.setAttribute('class', 'cf_element2');
				    newdiv.style.visibility = 'hidden';
				    newdiv.style.display = 'none';
				    newdiv.innerHTML = '<img id="rimg1_'+randid+'" src="img/spacer.gif" width="440" height="286">';
					document.getElementById('mid_wrapper').appendChild(newdiv);
					mid_arr[0] = 'r1_'+randid;			
		
					var newdiv = document.createElement('div');
				    newdiv.setAttribute('id', 'r2_'+randid);
				    newdiv.setAttribute('class', 'cf_element2');
				    newdiv.style.visibility = 'hidden';
				    newdiv.style.display = 'none';
				    newdiv.innerHTML = '<img id="rimg2_'+randid+'" src="images/'+selected_image_id+'.jpg" width="440" height="286">';
					document.getElementById('mid_wrapper').appendChild(newdiv);
					mid_arr[1] = 'r2_'+randid;	
									
					clear_elements(old_mid_arr);
					//cf3 = new Crossfader( mid_arr, 800, 1000 );
					document.getElementById('rimg2_'+randid).onload = function() {
						cf3 = new Crossfader( mid_arr, 800, 1000 );
					}
					//cf3 = new Crossfader( new Array('r1','r2'), 800, 1000 );
				}
			}	    	 
	    	 
	    }
	  });	

}


function load_intern(sub_id) {	
	
	
	
	var image2load = new Array();

		
	if (page_fade_arr[sub_id]) {
		
		image2load = page_fade_arr[sub_id].split(",");

	} 
	
	load_image_arr(image2load);		
	
	document.getElementById('content_main').innerHTML = '';
	document.getElementById('content_hl').innerHTML = page_title_arr[sub_id];
	
 	if (sub_id == 154) {
 		document.getElementById('right_main').innerHTML = '';
 	}	
	
	AjaxRequest.get({
	  	'url':'index.php?load_page='+sub_id,
	    'onSuccess':function(req){ 
	    	 var t_data = eval('(' + req.responseText + ')');
	    	 if (t_data['main']) {
	    	 	document.getElementById('content_main').innerHTML = t_data['main'].toString();	    	 	    	 
	    	 }
	    }
	  });	
	
	 return true;
}


function load_intern2(main_id, id1, id2) {	
	
	
	
	var image2load = new Array();

	if (selected_sub_id > 0) {
		document.getElementById('con'+selected_main_id+'_'+selected_sub_id).className = "";		
	}
	if (selected_main_id > 0) {
		document.getElementById('cat'+selected_main_id).className = "";
	}
	document.getElementById('cat'+main_id).className = "navi_selected";
	load_subnavi(main_id);
	if (cat_first_arr[main_id] && cat_first_arr[main_id] > 0 && cat_first_arr[main_id] != id1) {		
		document.getElementById('con'+main_id+'_'+cat_first_arr[main_id]).className = "";	
	}
	
	document.getElementById('con'+main_id+'_'+id1).className = "subnavi_selected";	
	if (id2 > 0) { // is sub...
		
		document.getElementById('sub'+main_id+'_'+id2).style.display = '';
		selected_subnotsub_id = id2;
		load_content(id1);				
	} else {
		selected_subnotsub_id = id1;
		load_content(id1);
	}
	
		
	if (page_fade_arr[id1]) {
		
		image2load = page_fade_arr[id1].split(",");
		
	} else if (cat_fade_arr[main_id]) {
		
		image2load = cat_fade_arr[main_id].split(",");
		
	} 

	load_image_arr(image2load);
	
	selected_sub_id = id1;
	
	selected_main_id = main_id;	
}

function rimage(image_id, text) {
	
	if (selected_image_id == image_id) return;
	
	if (!document.getElementById('mid_wrapper')) return;
	
	selected_image_text = text;
	
	var old_mid_arr = mid_arr;
	mid_arr = new Array();
	var randid = get_random_id();
	
	var newdiv = document.createElement('div');					
    newdiv.setAttribute('id', 'r1_'+randid);
    newdiv.setAttribute('class', 'cf_element2');
    newdiv.style.visibility = 'hidden';
    newdiv.style.display = 'none';
    newdiv.innerHTML = '<img id="rimg1_'+randid+'" src="img/spacer.gif" width="440" height="286">';
	document.getElementById('mid_wrapper').appendChild(newdiv);
	mid_arr[0] = 'r1_'+randid;			

	var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'r2_'+randid);
    newdiv.setAttribute('class', 'cf_element2');
    newdiv.style.visibility = 'hidden';
    newdiv.style.display = 'none';
    newdiv.innerHTML = '<img id="rimg2_'+randid+'" src="images/'+image_id+'.jpg" width="440" height="286">';
	document.getElementById('mid_wrapper').appendChild(newdiv);
	mid_arr[1] = 'r2_'+randid;	
					
	clear_elements(old_mid_arr);
	document.getElementById('imgtxt').innerHTML = '';
	//cf3 = new Crossfader( mid_arr, 800, 1000 );	
	document.getElementById('rimg2_'+randid).onload = function() {
		cf3 = new Crossfader( mid_arr, 800, 1000 );
	}	
	/*
	document.getElementById('rimg2_'+selected_sub_id).src = 'images/'+image_id+'.jpg';
	document.getElementById('imgtxt').innerHTML = '';
	cf3 = new Crossfader( new Array('r1_'+selected_sub_id,'r2_'+selected_sub_id), 800, 1000 );
	*/
	//document.getElementById('imgtxt').innerHTML = text;
	
	
	selected_image_id = image_id;
	
}

function rimage2(image_id, text) {
	
	if (selected_image_id == image_id) return;
	if (!document.getElementById('mid_wrapper')) return;
	/*
	if (document.getElementById('firstimg') && document.getElementById('firstimg').value > 0) {
		selected_image_id = document.getElementById('firstimg').value;
		document.getElementById('firstimg').value = '';
	}
	*/
	
	selected_image_text = text;
	
	if (document.getElementById('imglink'+selected_image_id)) {
		document.getElementById('imglink'+selected_image_id).className = "";
	}
	
	document.getElementById('imglink'+image_id).className = "subnavi_selected";
	
	
	var old_mid_arr = mid_arr;
	mid_arr = new Array();
	var randid = get_random_id();
	
	var newdiv = document.createElement('div');					
    newdiv.setAttribute('id', 'r1_'+randid);
    newdiv.setAttribute('class', 'cf_element2');
    newdiv.style.visibility = 'hidden';
    newdiv.style.display = 'none';
    newdiv.innerHTML = '<img id="rimg1_'+randid+'" src="img/spacer.gif" width="440" height="286">';
	document.getElementById('mid_wrapper').appendChild(newdiv);
	mid_arr[0] = 'r1_'+randid;			

	var newdiv = document.createElement('div');
    newdiv.setAttribute('id', 'r2_'+randid);
    newdiv.setAttribute('class', 'cf_element2');
    newdiv.style.visibility = 'hidden';
    newdiv.style.display = 'none';
    newdiv.innerHTML = '<img id="rimg2_'+randid+'" src="images/'+image_id+'.jpg" width="440" height="286">';
	document.getElementById('mid_wrapper').appendChild(newdiv);
	mid_arr[1] = 'r2_'+randid;	
					
	clear_elements(old_mid_arr);
	document.getElementById('imgtxt').innerHTML = '';
	//cf3 = new Crossfader( mid_arr, 800, 1000 );	
	document.getElementById('rimg2_'+randid).onload = function() {
		cf3 = new Crossfader( mid_arr, 800, 1000 );
	}	
	/*
	selected_image_text = text;
	document.getElementById('rimg2_'+selected_sub_id).src = 'images/'+image_id+'.jpg';
	document.getElementById('imgtxt').innerHTML = '';
	cf3 = new Crossfader( new Array('r1_'+selected_sub_id,'r2_'+selected_sub_id), 800, 1000 );
	*/
	//document.getElementById('imgtxt').innerHTML = text;
	
	
	selected_image_id = image_id;
	
}

 function get_random_id() {
     var randomkey1 = Math.floor(Math.random()*4013);
     var randomkey2 = Math.floor(Math.random()*5142);
     return "rid" + (10016486 + (randomkey1 * 2242))+"_" + (20000000 + (randomkey2 * 327));
 }
 
function removeElement(elemId) {
  var d = document.getElementById(elemId);
  d.parentNode.removeChild(d);
}
 

function load_image_arr(image2load) {	
	//console.log('load_image_arr()');
	if (image2load.length == 0) {
		return;
	}
	if (!image2load.compareArrays(topimg_arr)) {
		//console.log('!image2load.compareArrays(topimg_arr)');
		/*
		stop_img_load = true;
		stop_img_load2 = true;
		
		if(typeof cf1 == 'object') {
			clearInterval(cf1.nID1);
			//clearInterval(cf1.nID2);			
		}
		if(typeof cf2 == 'object') {
			cf2.lastFade = true;
			clearInterval(cf2.nID1);
			
			//clearInterval(cf2.nID2);			
		}
		*/
		if (image2load.length > 1) {
			var old_header_arr = header_arr;			

			header_arr = new Array();
			var x = 0;
			var firstid = '';
			for (var i in image2load) {
				if (i == 'compareArrays') continue;
				//console.log(i+': '+image2load[i]);
				x++;
				
				var newdiv = document.createElement('div');
				var randid = get_random_id();
			    newdiv.setAttribute('id', 'header_'+randid);
			    newdiv.setAttribute('class', 'cf_element');
			    newdiv.style.visibility = 'hidden';
			    newdiv.style.display = 'none';
			    if (firstid == '') {
			    	firstid = 'topimg_'+randid;
			    }
			    newdiv.innerHTML = '<img id="topimg_'+randid+'" src="images/'+image2load[i]+'.jpg" width="900" height="230">';
				document.getElementById('header_wrapper').appendChild(newdiv);
				//document.getElementById('topimg'+x).src = 'images/'+image2load[i]+'.jpg';	
				header_arr[header_arr.length] = 'header_'+randid;
				
			}
			//stop_img_load2 = false;	
			//clear_elements(old_header_arr);
			//cf2 = new Crossfader2(header_arr, 1800, 3600 );
			document.getElementById(firstid).onload = function() {
				clear_elements(old_header_arr);
				cf2 = new Crossfader2(header_arr, 1800, 3600 );				
			}
			
		} else if (image2load.length == 1) {
			var old_header_arr = header_arr;
			
			header_arr = new Array();

			var newdiv = document.createElement('div');
			var randid = get_random_id();
		    newdiv.setAttribute('id', 'header_'+randid);
		    newdiv.setAttribute('class', 'cf_element');
		    newdiv.style.visibility = 'hidden';
		    newdiv.style.display = 'none';
		    newdiv.innerHTML = '<img id="topimg_'+randid+'" src="img/spacer.gif" width="900" height="230">';
			document.getElementById('header_wrapper').appendChild(newdiv);
			header_arr[header_arr.length] = 'header_'+randid;			

			var newdiv = document.createElement('div');
			var randid = get_random_id();
		    newdiv.setAttribute('id', 'header_'+randid);
		    newdiv.setAttribute('class', 'cf_element');
		    newdiv.style.visibility = 'hidden';
		    newdiv.style.display = 'none';
		    newdiv.innerHTML = '<img id="topimg_'+randid+'" src="images/'+image2load[0]+'.jpg" width="900" height="230">';
			document.getElementById('header_wrapper').appendChild(newdiv);
			header_arr[header_arr.length] = 'header_'+randid;		

			//clear_elements(old_header_arr);
			//cf1 = new Crossfader(header_arr, 800, 1000);		
			document.getElementById('topimg_'+randid).onload = function() {
				clear_elements(old_header_arr);
				cf1 = new Crossfader(header_arr, 800, 1000);		
			}
			/*
			document.getElementById('topimg1').src = 'images/'+image2load[0]+'.jpg';
			cf1 = new Crossfader(new Array('header2', 'header1'), 800, 1000);
			stop_img_load = false;
			*/
			
		}
		
	} else {
		//console.log('image2load.compareArrays(topimg_arr)');
	}
	topimg_arr = image2load;	
	
}

Array.prototype.compareArrays = function(arr) {
    if (this.length != arr.length) return false;
    for (var i = 0; i < arr.length; i++) {
        if (this[i].compareArrays) { //likely nested array
            if (!this[i].compareArrays(arr[i])) return false;
            else continue;
        }
        if (this[i] != arr[i]) return false;
    }
    return true;
}


function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

	function hide_gallery() {
		gal_play = false;
		var old_imgarr = topimg_arr;
		topimg_arr = new Array();
		document.getElementById('container').style.display = 'block';	
		document.getElementById('lang').style.display = 'block';	
		load_image_arr(old_imgarr);	
		document.getElementById('gallery').style.display = 'none';		
		
	}
	
	function show_gallery() {
		
		// first start!
		if (document.getElementById('galimg2').src == '' || document.getElementById('galimg2').src == web_dir || document.getElementById('galimg2').src == web_dir+'img/spacer.gif') {
			cf4 = new Crossfader(new Array('gal2', 'gal1'), 1000, 1000);
		}
		
		document.getElementById('gallery').style.display = 'block';
		document.getElementById('container').style.display = 'none';
		document.getElementById('lang').style.display = 'none';
		
		if(typeof cf1 == 'object') {
			clearInterval(cf1.nID1);
			clearInterval(cf1.nID2);			
		}
		if(typeof cf2 == 'object') {
			clearInterval(cf2.nID1);
			clearInterval(cf2.nID2);			
		}
		if(typeof cf3 == 'object') {
			clearInterval(cf2.nID1);
			clearInterval(cf2.nID2);			
		}
		//clear_header_images();
		clear_elements(header_arr);	
		clear_elements(mid_arr);	

		if (gal_play) {
			setTimeout(function() { load_next_gallery(false); }, 4000);
		}
	}
	
	function load_next_gallery(manual) {
		
		if (!manual && !gal_play) {
			return;
		}
		gal_fade_active = true;
		var id2use, active_id;
		//if (document.getElementById('galimg2').src == '' || document.getElementById('galimg2').src == web_dir) {
		if (gal_active_id == 1) {
			id2use = 2;
			active_id = 1;
		} else {
			id2use = 1;
			active_id = 2;
		}
		
		cf4 = new Crossfader3(new Array('gal'+active_id, 'gal'+id2use), 2000, 1);
		var next_id = get_next_gallery_image_id(active_id);
		//console.log('next_id = '+next_id);
		document.getElementById('galimg'+id2use).src = 'images/'+gallery_arr[next_id]+'.jpg';
		gal_active_id = id2use;
		
		if (gal_play) {
			setTimeout(function() { load_next_gallery(false);  }, 4000);
		}
	}
	function gallery_stop() {
		gal_play = false;
	}
	function gallery_play() {
		gal_play = true;
		if (!gal_fade_active) {
			load_next_gallery();	
		}		
	}
	function gallery_back() {
		gal_play = false;
		if (!gal_fade_active) {
			load_previous_gallery();	
		}		
	}
	function gallery_forward() {
		gal_play = false;
		if (!gal_fade_active) {
			load_next_gallery(true);	
		}
	}		
	function load_previous_gallery() {
		gal_play = false;
		var id2use, active_id;
		gal_fade_active = true;
		if (gal_active_id == 1) {
			id2use = 2;
			active_id = 1;
		} else {
			id2use = 1;
			active_id = 2;
		}
		cf4 = new Crossfader3(new Array('gal'+active_id, 'gal'+id2use), 2000, 1);
		var previous_id = get_previous_gallery_image_id(active_id);
		//console.log('previous_id = '+previous_id);
		document.getElementById('galimg'+id2use).src = 'images/'+gallery_arr[previous_id]+'.jpg';
		gal_active_id = id2use;

	}	
	
	function get_previous_gallery_image_id(active_id) {
		var counter = 0;
		var last_img = 0;
		var i = gallery_arr.length-1;
		var notfound = true;
		while (notfound) {
			counter++;
			//console.log(document.getElementById('galimg'+active_id).src+' == '+web_dir + 'images/'+last_img+'.jpg');
			if (document.getElementById('galimg'+active_id).src == web_dir + 'images/'+last_img+'.jpg') {
				return i;
			}
			last_img = gallery_arr[i];
			i--;
			if (i < 0) {
				i = gallery_arr.length-1;
			}
			if (counter > 999) {
				notfound = false;
				return 0;
			}
		}
		
		return 0;
	}
		
	function get_next_gallery_image_id(active_id) {
		var counter = 0;
		var last_img = 0;
		var i = 0;
		var notfound = true;
		while (notfound) {
			counter++;
			//console.log(document.getElementById('galimg'+active_id).src+' == '+web_dir + 'images/'+last_img+'.jpg')
			if (document.getElementById('galimg'+active_id).src == web_dir + 'images/'+last_img+'.jpg') {
				return i;
			}
			last_img = gallery_arr[i];
			i++;
			if (i >= gallery_arr.length) {
				i = 0;
			}
			if (counter > 999) {
				notfound = false;
				return 0;
			}
		}
		
		return 0;
	}