String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/* newsletter */
function check_newsletter() {
	if ($('email').value == 'yourname@domain.com') return false;
	if ($('email').value.indexOf('@') == -1) return false;
	return true;
}

/* print */

function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	}else{
	 	//if (navigator.appName.indexOf("Microsoft")!=-1) {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}

function print_me(path) {
	uri = path
	wwidth = 636;
	wheight = 580;
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, 'print', "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=yes, resizable=no, directories=no");
}

/* mouse over */
function btn_over(obj, bg_pos) {
	obj.style.backgroundPosition = bg_pos;
}

/* form functions */

function clear_input(obj) {
	
	if  (typeof(obj.old_value) == "undefined") {
		obj.old_value = obj.value;
		obj.value = '';
	} else if (obj.value.trim() == '') {
		obj.value = obj.old_value;
		delete obj.old_value;
	}
}

/* msie control activation fix */

function write_flash(filename, w, h, param, transparent) {
	document.write('<object align="middle" type="application/x-shockwave-flash" data="'+filename+'" Width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+filename+'" />');
	document.write('<param name="FlashVars" value="'+param+'" />');
	if (transparent) {
		document.write('<param name="wmode" value="transparent" />');
	}
	document.write('</object>');
}

/* first page news ticker */

var newsitems = Array();
var scroll_index = 0;
var scroll_height = 64;
var s;
var scroll_timeout = 1;
var pause_timeout = 5000; 

function setup_scroller() {
	
	if ((s = document.getElementById('scroller')) != null) {
	
		newsitems = s.getElementsByTagName('DIV');
		
		if (newsitems.length > 0) {
			for (i=0; i<newsitems.length; i++) {
				newsitems[i].style.top = i * scroll_height + "px";
				newsitems[i].style.display = 'block';
			}
			
			if (newsitems.length > 1) {
				setTimeout(scroll, scroll_timeout);
			}
		}
	
	}
}

function pause() {
	setTimeout(scroll , pause_timeout);
}

function scroll() {
	do_pause = false;
	
	for (i=0; i<newsitems.length; i++) {
		
		current_top = parseInt(newsitems[i].style.top);
		
		if (current_top < -scroll_height) {
			newsitems[i].style.top = ((newsitems.length-1) * scroll_height) + "px";
			current_top =  ((newsitems.length-1) * scroll_height);
		}
		
		newsitems[i].style.top = (current_top - 1) + "px";
		
		if (current_top == 0) {
			do_pause = true;
		}

	}
	if (do_pause == true) {
		pause();
	} else {
		setTimeout(scroll, scroll_timeout);
	}
	
}


/* first page captain's info scroller */
/* first page news ticker */

var citems = Array();
var cscroll_index = 0;
var cscroll_height = 51;
var cs;
var cscroll_timeout = 1;
var cpause_timeout = 5000; 

function setup_cscroller() {
	
	if ((cs = document.getElementById('info_scroll')) != null) {
	
		citems = cs.getElementsByTagName('DIV');
		
		if (citems.length > 0) {
			for (i=0; i<citems.length; i++) {
				citems[i].style.top = i * cscroll_height + "px";
				citems[i].style.display = 'block';
			}
			
			if (citems.length > 1) {
				setTimeout(cscroll, cscroll_timeout);
			}
		}
	
	}
}

function cpause() {
	setTimeout(cscroll , cpause_timeout);
}

function cscroll() {
	do_pause = false;
	
	for (i=0; i<citems.length; i++) {
		
		current_top = parseInt(citems[i].style.top);
		
		if (current_top < -cscroll_height) {
			citems[i].style.top = ((citems.length-1) * cscroll_height) + "px";
			current_top =  ((citems.length-1) * cscroll_height);
		}
		
		citems[i].style.top = (current_top - 1) + "px";
		
		if (current_top == 0) {
			do_pause = true;
		}

	}
	if (do_pause == true) {
		cpause();
	} else {
		setTimeout(cscroll, scroll_timeout);
	}
	
}


/*	first page gallery functions */
var current_image = 0;
var image_timeout = 5000;
var image_count = 0;
var timer, temp_img, image_array;

var dummy = false;

var use_transitions = true;

var IS_IE = (navigator.userAgent.indexOf('MSIE') > -1) ?  true : false;

if (IS_IE) {
	var IE_VER = navigator.appVersion;
	if (IE_VER.indexOf('MSIE 5') > -1) use_transitions = false;
}


function start_slideshow(my_img_array) {

	if (typeof(image_array) == 'undefined' && typeof(my_img_array) != 'undefined') image_array = my_img_array;
	
	if (typeof(image_array) != 'undefined') {
		image_count = image_array.length;
		timer = setInterval("change_pic()", image_timeout);
	}
}

function stop_slideshow() {
	clearInterval(timer);
}


function change_pic() {

	current_image++;
	
	if (current_image > (image_count-1)) current_image = 0;
	indicator('show');

	temp_img = document.createElement('IMG');
	temp_img.style.display = 'none';
	
	ph = document.getElementById('image_ph');
	ph.appendChild(temp_img);
	temp_img.src = image_array[current_image];
	
	if (temp_img.complete){
		temp_img.img_loaded = img_loaded;
		temp_img.img_loaded();
	} else {
		temp_img.onload = img_loaded;
	}
	temp_img.onerror = change_pic;
	
	make_nav();
	
}

function step_pic(mode) {

	stop_slideshow();

	if (mode == 'prev') {
		
		if (current_image > 0) {
			current_image -=2;
		} else {
			current_image = image_count-2;
		}
	} 
	change_pic();
	start_slideshow();
	return false;
}

function img_loaded() {

	$('top_image').style.zIndex = '90';
	
	if (use_transitions) {
		var fadeout = $('top_image').effect('opacity', {
			onComplete: function() {
				frame = document.getElementById('top_image');
				frame.parentNode.removeChild(frame);
			}
		});
		fadeout.custom(1,0);
	} else {
		frame = document.getElementById('top_image');
		frame.parentNode.removeChild(frame);
	}
	
	this.id = 'top_image';
	this.style.display = 'block';
	this.style.zIndex = '80';

	indicator();
}


function indicator(action) {
	ind = document.getElementById('indicator');
	ind.style.display = (typeof(action) != 'undefined' && action == 'show') ? 'block' : 'none';
}


function make_nav() {

	while($('btns').hasChildNodes()) $('btns').removeChild($('btns').firstChild);
	
	for (var i = 0; i < image_array.length; i++) {
		tmp = document.createElement('INPUT');
		tmp.type = 'button';
		
		if ( i == current_image) {
			tmp.style.backgroundPosition = 'left bottom';
		} else {
			tmp.onmouseover = function() {
				this.style.backgroundPosition = 'left bottom';
			}
			
			tmp.onmouseout = function() {
				this.style.backgroundPosition = 'left top';
			}
			
		}
		
		tmp.imageIndex = i-1;	

		tmp.onclick = function() {
			current_image = this.imageIndex;
			step_pic('next');
			this.blur();
		}
		
		$('btns').appendChild(tmp);
	}
}


/* toggle font / line size */
/* set cookie */
//function setCookie(name, value, expires, path, domain, secure) {
function setCookie(name, value, days) {
  if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var text_sizes		= [1, 1.2, 1.4];
var line_heights	= [1.6, 1.8, 2];

var def_text_size = 0;
var def_line_height = 0;

var content_placeholder = 'content';


function change_line_height() {
	current_lh = getCookie('line_height');

	if (!current_lh) current_lh = def_line_height;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;

	setCookie('line_height', current_lh, 365);
	
	document.getElementById(content_placeholder).style.lineHeight = line_heights[current_lh] + "em";
}

function change_text_size() {
	current_ts = getCookie('text_size');
	if (!current_ts) current_ts = def_text_size;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	setCookie('text_size', current_ts, 365);
	document.getElementById(content_placeholder).style.fontSize = text_sizes[current_ts] + "em";
}

function init_text_properties() {
	current_text_size = getCookie('text_size');
	current_line_height = getCookie('line_height');
	
	if (current_text_size && (s = document.getElementById(content_placeholder)) != null) {
		s.style.fontSize = text_sizes[current_text_size] + "em";
	}	
	if (current_line_height && (s = document.getElementById(content_placeholder)) != null) {
		s.style.lineHeight = line_heights[current_line_height] + "em";
	}
	
}

window.addEvent('load', function() {
	setup_scroller();
	setup_cscroller();
	init_text_properties();
}
);
