

function doOnLoad() {

	// preload images


}

function preload(imgsrc) {
	if(!window.preloadedImage) window.preloadedImage = new Array();
	var i = window.preloadedImage.length;
	window.preloadedImage[i] = new Image();
	window.preloadedImage[i].src = imgsrc;
}

function writeBreadcrumbs() {
	var tit = document.title.replace(/Vintner's Collective:\s*/i, '');

	var buf = '';
	buf += '<a href="/home.html" style="text-decoration:none">Home</a>';
	buf += ' - ' + tit;
	document.write(buf);
}

function writePanoramaImage(img) {
	if(img == '' || !img) {
		var m = document.location.href.match(/([^\/]+?)\.[^\.]+$/i);
		var pagename = m[1];

		switch(pagename) {
			case 'about':
			case 'about2':
				img = 'aboutus'; break;
	
			case 'about_mike':
				img = 'mikeblack'; break;
	
			case 'about_pfeiffer':
				img = 'pfeifferbldg'; break;
	
			case 'about_garret':
				img = 'garret'; break;
	
			case 'tasting_room_hours':
			case 'tasting_room_map':
			case 'tasting_room_newsletter':
				img = 'tastingroom'; break;
	
			case 'wine_club_intro':
				img = 'wineclub1'; break;
	
			case 'wine_club_connoisseur':
			case 'wine_club_collector':
				img = 'wineclub3'; break;
	
			case 'contact_us':
				img = 'contact'; break;
				
			case 'rsvp':
			case 'rsvp_thanks':
				img = 'rsvp'; break;

			case 'vintners':
				img = 'vintners'; break;
				
			case 'we_suggest2':
			case 'we_suggest_list':
			    img = "wesuggest"; break;
				
			case 'news_events_news':
			case 'concierge_services':
			    img = "news"; break;

			default: img = 'home'; break;
		}
	}
	if (document.location.href.match('/vcshop/')) {
		img = "shop";
	}
	if (document.location.href.match('/gallery/')) {
		img = "gallery";
	}
	if (document.location.href.match('harvest2006')) {
		img = "harvest2006";
	}
	if (document.location.href.match('speakeasy')) {
		img = "speakeasy";
	}
	if (document.location.href.match('reconnect')) {
		img = "reconnect";
	}
	if(img.indexOf('panorama_') == -1) img = 'panorama_' + img;
	if(img.indexOf('.') == -1) img = img + '.jpg';

	var buf = '<img src="/assets/pics/'+img+'" alt="'+document.title+'" width="770" height="130" border="0">';
	document.write(buf);

}


// error class
function Errors() {
	this.errors = new Array();

	this.add = function(msg) {
		this.errors[this.errors.length] = msg;
	}
	this.alert = function() {
		if(!this.errors.length) return false;

		var msg = 'The following error(s) have occurred:\n\n';

		for(var i=0; i<this.errors.length; ++i) {
			msg += '*  ' + this.errors[i];
			if(i < this.errors.length - 1) msg += '\n\n';
		}

		alert(msg);
		return true;
	}
}

function validate_email(email) {
	if(email.length <= 5) return false;
	if(email.indexOf('@', 0) == -1) return false;
	return true;
}




// Show / Hide

window.content_toggle_duration = 2000;


function getdivheightfx(id) {
	divid = 'contentdiv_' +id;
	div = $(divid);
	if(!div) return;

	if(!window.divfx) window.divfx = new Array();
	if(!window.divfx[id]) window.divfx[id] = new Array();

	var divheightfx = window.divfx[id]['divheightfx'];

	if(!divheightfx) {
		var duration = div.getAttribute('expandheight') * (window.content_toggle_duration / 1000);

		window.divfx[id]['divheightfx'] = new fx.Height(
			div, {
				duration: duration,
				onComplete: function() {
					if(this.now <= 1) this.el.style.display = 'none';
	
				}
			}
		);
		divheightfx = window.divfx[id]['divheightfx'];
		divheightfx.hide();
	}

	return divheightfx;

}
function getdivopacityfx(id) {
	divid = 'contentdiv_' +id;
	div = $(divid);

	if(!window.divfx) window.divfx = new Array();
	if(!window.divfx[id]) window.divfx[id] = new Array();

	var divopacityfx = window.divfx[id]['divopacityfx'];

	if(!divopacityfx) {
		var duration = div.getAttribute('expandheight') * (window.content_toggle_duration / 1000);

		window.divfx[id]['divopacityfx'] = new fx.Opacity(
			div, {
				duration: duration,
				onComplete: function() {
	
	
				}
			}
	
		);
		divopacityfx = window.divfx[id]['divopacityfx']
		divopacityfx.hide();
	}
	return divopacityfx;
}


function content_toggle(id) {
	divid = 'contentdiv_' +id;
	div = $(divid);

	var divheightfx = getdivheightfx(id);
	var divopacityfx = getdivopacityfx(id);

	if(divheightfx.now <= 1) content_show(id);
	else content_hide(id);
}

function content_hide(id) {
	if(id.indexOf('contentdiv_') == 0) {
		id = id.substr(11);
	}
	divid = 'contentdiv_' +id;
	div = $(divid);

	var divheightfx = getdivheightfx(id);
	var divopacityfx = getdivopacityfx(id);

	divheightfx.custom(divheightfx.now * 1, 1);
	divopacityfx.custom(1, 0);
}

function content_show(id) {
	divid = 'contentdiv_' +id;
	div = $(divid);

	var divheightfx = getdivheightfx(id);
	var divopacityfx = getdivopacityfx(id);

	if(divheightfx.now > 1) return;

//	for(var n in window.divfx) {
//		if(n == id) continue;
//		if(!window.divfx[n]['divheightfx']) continue;

//		window.divfx[n]['divheightfx'].clearTimer();
//		window.divfx[n]['divopacityfx'].clearTimer();
//		content_hide(window.divfx[n]['divheightfx'].el.id);
//	}


	div.style.display = '';
	divheightfx.custom(1, div.getAttribute('expandheight'));
	divopacityfx.custom(0, 1);
}


// simple show / hide

function showhide(id,textmore,textless) {
	var what = document.getElementById(id);
	var link = document.getElementById('linktext');
	if(what.style.display == 'none') {
		what.style.display = '';
		link.innerHTML = textless;
	}
	else {
		what.style.display = 'none';
		link.innerHTML = textmore;
	}
}






