//* Author  : Roy Whittle  (Roy@Whittle.com)
var AnimationRunning = false;
var FrameInterval    = 30;

function AnimatedImage(n, name, ext)
{
	if(document.images)
	{
		this.num_frames = n;
		this.name       = "t0"+name;
		this.index      = 0;
		this.state      = "CLOSED";

		for(var i=0 ; i<n ; i++)
		{
			this[i]=new Image();
			this[i].src = img_location+"t"+i+"_"+name+"x1"+ext;
		}
	}
	
}
function AnimatedDetail(name)
{
	if(document.images)
	{
		this.name       = name;
		this.index      = 0;
		this.state      = "OFF";

		this[0] = new Image();
		this[0].src = small_img_location + name + ".jpg";
	}
	
}


function Animate()
{	
	AnimationRunning = false;
	for(var i=0 ; i<Btn.numButtons ; i++)
		switch(Btn[i].state)
		{
			case "OPENING" :
				if(Btn[i].index < Btn[i].num_frames-1)
				{
					Btn[i].index++;
					document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
					AnimationRunning = true;
				}
				else
					Btn[i].state = "OPEN";

				break;

			case "OPEN_CLOSE" :
				if(Btn[i].index < Btn[i].num_frames-1)
				{
					Btn[i].index++;
					document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
				}
				else
					Btn[i].state = "CLOSING";

				AnimationRunning = true;
				break;

			case "CLOSING" :
				if(Btn[i].index > 0)
				{
					Btn[i].index--;
					document.images[Btn[i].name].src=Btn[i][Btn[i].index].src;
					AnimationRunning = true;
				}
				else
					Btn[i].state = "CLOSED";

				break;
		}
	if( AnimationRunning )
		setTimeout("Animate()",FrameInterval);
}
function start_animation()
{
	if(!AnimationRunning)
		Animate();
}
function turn_on(btn_name)
{
	for(var i=0; i<Btn.numButtons ; i++)
		if(Btn[i].name == btn_name )
		{
			switch(Btn[i].state)
			{
				case "CLOSED"     :
				case "CLOSING"    :
				case "OPEN_CLOSE" :
					Btn[i].state = "OPENING";
					start_animation();
					break;
				case "OFF" :
					document.images["detail"].src=Btn[i][0].src;
					Btn[i].state = "ON";
					break;
				default :
					break;
			}
		}

}
function turn_off(btn_name)
{

	for(var i=0; i<Btn.numButtons ; i++)
		if(Btn[i].name == btn_name )
		{
			switch(Btn[i].state)
			{
				case "OPEN"       :
					Btn[i].state = "CLOSING";
					start_animation();
					break;
				case "OPENING"  :
					Btn[i].state = "OPEN_CLOSE";
					start_animation();
					break;
				case "ON" :
					//document.images["detail"].src=Btn[i][0].src;
					document.images["detail"].src = ee.src;
					Btn[i].state = "OFF";
					break;
				default :
					break;
			}
		}
}
function detail(which) {
	if(document.images) {
		switch(which)
		{
			case "nelson" :
				document.m0.src = img_location + "rmap_nelson1.jpg";
				document.m2.src = img_location + "rmap_nelson2.jpg";
				break;
			case "picton" :
				document.m1.src = img_location + "rmap_picton1.jpg";
				document.m3.src = img_location + "rmap_picton2.jpg";
				break;
			case "blm" :
				document.m4.src = img_location + "rmap_blm2.jpg";
				document.m3.src = img_location + "rmap_blm1.jpg";
				break;
			case "clear" :
				document.m0.src = img_location + "rmap_3x1.jpg";
				document.m1.src = img_location + "rmap_2x2.jpg";
				document.m2.src = img_location + "rmap_4x1.jpg";
				document.m3.src = img_location + "rmap_4x2.jpg";
				document.m4.src = img_location + "rmap_5x1.jpg";
				break;
			default :
				break;
		}
	}
}
//function empty() {
//	if(document.images) {
//		document.images["detail"].src = ee.src;
//	}
//}

function go_to(which)
{
 return true;
}

function AnimatedButtons()
{
	this.numButtons = 7;
	this[0]=new AnimatedImage(4,3,".jpg");
	this[1]=new AnimatedImage(4,4,".jpg");
	this[2]=new AnimatedImage(4,5,".jpg");
	this[3]=new AnimatedImage(4,6,".jpg");
	this[4]=new AnimatedImage(4,7,".jpg");
	this[5]=new AnimatedImage(4,8,".jpg");
	this[6]=new AnimatedImage(4,9,".jpg");
}


// basic checks of the input fields:
function chkForm(which)
    {
     if (which == "acc") {
          // only with acc the name is mandatory
         if(document.Formular.name.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.name.value = "Please enter your name details!";
             document.Formular.name.focus();
             return false;
         }
     }


     // test email with every version.
     if(document.Formular.email.value == "")
      {
       //alert("Your e-mail address is a required input field!");
       document.Formular.email.value = "Please enter your email address!";
       document.Formular.email.focus();
       return false;
      }
     if(document.Formular.email.value.indexOf('@') == -1)
      {
       alert("Your e-mail address is of illegal format!");
       document.Formular.email.focus();
       return false;
      }


     // check dates
     if ((which == "acc") || (which == "enq")) {
          // only with acc and enq
         if(document.Formular.nr_of_people.options[0].selected == true)
         {
             alert("Please enter the number of people staying!");
             return false;
         }
         if(document.Formular.arrival_date.value == "MM/DD/YYYY")
         {
             alert("What is your date of arrival?");
             //document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.arrival_date.focus();
             return false;
         }
         if(document.Formular.departure_date.value == "MM/DD/YYYY")
         {
             alert("What is your date of departure?");
             //document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.departure_date.focus();
             return false;
         }
     }


     if (which == "acc") {
         if(document.Formular.Credit_Card.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
         if(document.Formular.Card_Number.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.Card_Number.value = "Credit Card number is missing!";
             document.Formular.Card_Number.focus();
             return false;
         }
         if(document.Formular.Card_Holder_Name.value == "")
         {
             //alert("Please enter your name details!");
             document.Formular.Card_Holder_Name.value = "Card holder name is missing!";
             document.Formular.Card_Holder_Name.focus();
             return false;
         }
         if(document.Formular.Expiration_Month.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
         if(document.Formular.Expiration_Year.options[0].selected == true)
         {
             alert("Please enter the expiration date of your Credit Card!");
             return false;
         }
     }



     if ((which != "acc") || (which == "enq")) {
          // only with acc the comment is mandatory
         if(document.Formular.comment.value == "")
         {
             //alert("What was your question / hint / comment again?");
             document.Formular.comment.value ="What was your question / hint / comment again?";
             document.Formular.comment.focus();
             return false;
         }
     }
    }

	
//------------------------------------------------------------

// Browser detection code, visit 'http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html' for more info.
var agent = navigator.userAgent.toLowerCase();
var is_gecko = (agent.indexOf('gecko') != -1);

var scr_wide = screen.width;
var scr_high = screen.height;

function preview (text) {
	if (is_gecko) {
		document.getElementById('caption_preview').innerHTML = text;
	} else {
		document.all.caption_preview.innerHTML = text;
	}
}

/* void zoom() function
	img_src = relative path to image file to display
	img_wide = actual width of image
	img_high = actual height of image
	use_caption = true (1) or false (0), if true will use captions.
	caption = caption to output if use_caption is true
*/
function zoom (img_src, img_wide, img_high, use_caption, caption) {
	// default settings
	var scrollbar = 'no';
	var win_properties = 'toolbar=0,status=0,menubar=0,resizable=0,directories=0,dependent=yes,';
//	var html_content = '<html><head><title>(' + img_src + ')</title><style>'
	var html_content = '<html><head><title>TheNikaus Image Gallery</title><style>'
					 + 'div.content{position:absolute;top:0;left:0;}'
					 + 'table{padding:0;border:0;width:100%;height:100%;background-color:' + cap_backcolor +';color:' + cap_forecolor + '}'
					 + 'tr{border:0;padding:0;}'
					 + 'td.image{border:0;padding:2px;width:' + img_wide + 'px;height:' + img_high + 'pxl}'
					 + 'td.caption{border:0;padding:2px;overflow:auto;font-family:arial,verdana,helvetica;font-size:8pt;text-align:' + cap_align + ';';
	var td_image = '<td class="image" onClick="self.close();"><img border="0" src="' + img_src + '" /></td>';
	var td_caption = '<td class="caption">' + caption + '</td>';
	// determine window properties & html styling
	if (img_wide > scr_wide) { var win_wide = scr_wide; win_high += 16; scrollbar = 'yes'; }
	else { var win_wide = img_wide; }
	if (img_high > scr_high) { var win_high = scr_high; win_wide += 16; scrollbar = 'yes'; }
	else { var win_high = img_high; }
	win_wide += 4;
	win_high += 4;
	if (use_caption) {
		switch (cap_float) {
			case 0: case 1:
				var cap_dims = 'width:100px;height:' + img_high;
				var cap_midpt = '</td>';
				win_wide += 100;
				break;
			case 2: case 3:
				var cap_dims = 'height:100px;width:' + img_wide;
				var cap_midpt = '</td></tr><tr>';
				win_high += 100;
		}
	} else {
		td_caption = '';
		var cap_midpt = '';
	}

	// generate html
	html_content += cap_dims + '}</style></head>'
					 + '<body leftmargin="0" topmargin="0"><div class="content"><table cellpadding="0" cellspacing="0"><tr>';
	switch (cap_float) {
		case 0: case 2:
			html_content += td_caption + cap_midpt + td_image;
			break;
		case 1: case 3:
			html_content += td_image + cap_midpt + td_caption;
	}

	html_content += '</tr></table></div></body></html>';

	// display
	if (win_wide >= scr_wide) { var x = 0; }
	else { var x = (scr_wide - win_wide) / 2; }
	if (win_high >= scr_high) { var y = 0; }
	else { var y = (scr_high - win_high) / 2; }
	win_properties += 'scrollbars=' + scrollbar + ',width=' + win_wide + ',height=' + win_high + ',top=' + y + ',left=' + x;
	var win_handle = window.open('', '_blank', win_properties);
	win_handle.document.open();
	win_handle.document.write(html_content);
	win_handle.document.close();
	win_handle.focus();
}




