var viewportSize = 5;
var currentPhoto = 1;
var currentLeft = 0;
var delta = 111 + 38;
	
function scroll( direction, numPhotos ) {	

	var v = document.getElementById( "viewport" )
	var l = document.getElementById( "scrollleft" )
	var r = document.getElementById( "scrollright" )
			
	if ( v ) {

		if ( numPhotos <= viewportSize ) { 
			alert( "Cannot move left or right." ); 
			return;
		}
		
		if ( ( direction < 0 ) && ( ( numPhotos - currentPhoto ) < viewportSize ) ) { 
			//alert( "Cannot move left." ); 
			return;
		}
		
		if ( ( direction > 0 ) && ( currentPhoto <= 1 ) ) { 
			//alert( "Cannot move right." ); 
			return;
		}
		
		currentPhoto += direction * -1;
		currentLeft = currentLeft + ( direction * delta );
		v.style.left = currentLeft + "px";
		
		if ( currentPhoto == 1 ) l.style.visibility = "hidden";
		else l.style.visibility = "visible";
		
		if ( currentPhoto > numPhotos - viewportSize ) r.style.visibility = "hidden";
		else r.style.visibility = "visible";
	}
}
	
function newPhoto( _path ) {	

	var p = document.getElementById( "photo" )
	p.style.backgroundImage = 'url("' + _path + '")';
}
	

function flipFrame( _s ) {

	var _screenshot = document.getElementById( _s )
	if ( _screenshot ) _screenshot.style.backgroundColor = "#ECF1F5";
}

function resetFrame( _s ) {

	var _screenshot = document.getElementById( _s )
	if ( _screenshot ) _screenshot.style.backgroundColor = "#26678F";
}

function blankBox( box ) {

	box.value = "";
}

function preloadImages() {

	var imageDir = "assets/images/menu/";
	var imageSfx = "_roll.gif";
	
	var home = imageDir + "home" + imageSfx;
	var food = imageDir + "food" + imageSfx;
	var drink = imageDir + "drink" + imageSfx;
	var parties = imageDir + "parties" + imageSfx;
	var sports = imageDir + "sports" + imageSfx;
	var directions = imageDir + "directions" + imageSfx;
	var calendar = imageDir + "calendar" + imageSfx;
	var reviews = imageDir + "reviews" + imageSfx;
	var contact = imageDir + "contact" + imageSfx;
	
	var bar1 = "assets/images/common/bar_bar_maroon.gif";
	var bar2 = "assets/images/common/bar_restaurant_maroon.gif";
	
	MM_preloadImages( home, food, drink, parties, sports, directions, calendar, reviews, contact, bar1, bar2 );
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
	var d=document; 
	if (d.images) { 
		if (!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0) {d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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();
}

function stripNonNumbers( _input ) {
	
	var result = "";
	var l = _input.length;
	var i = 0;

	for ( i=0; i<l; i++ ) {
		var c = _input.substr(i,1);
		if ( !isNaN( parseInt( c ) ) ) { result += c; }
	}

	return result;
}

function valid_phone( _currentValue ) {

	_currentValue = stripNonNumbers( _currentValue );
	if ( (_currentValue.length < 8) || (_currentValue.length > 32) ) { return false; }
	else { return true; }
}

function valid_phone( _currentValue, _min, _max ) {
	_currentValue = stripNonNumbers( _currentValue );
	if ( ( _currentValue.length < _min ) || ( _currentValue.length > _max ) ) { return false; }
	else { return true; }
}

function valid_email( _currentValue, min, max ) {

	var _emailError = isEmail( _currentValue );
	if ( _emailError.length > 0 ) { return false; }
	else { return true; }
}

function isEmail( _input, min, max ) {
	
	var err = "";
	var blankSpace = " ";
	var foundAt = false;
	var foundDot = false;

	var l = _input.length;
	var i = 0;

	if ( ( _input.length < (min*1) ) || ( _input.length > (max*1) ) ) {
		err = "Email address must use between " + min + " and " + max + " characters.";
		return err;
	}

	for ( i=0; i<l; i++ ) {
		var c = _input.substr(i,1);

		if ( c == blankSpace ) { 
			err = "Email address cannot contain spaces."	
			result = false;
		}
		if ( c == "@" ) { foundAt = true; }
		if ( c == "." ) { foundDot = true; }
	}

	if ( foundAt == false ) { err = "Email address must contain an \'@\' symbol to be valid.";  }
	if ( foundDot == false ) { err = "Email address must contain a \'.\' symbol to be valid.";  }

	return err;
}

function validateNewsletterForm( f, min, max ) {

	var _error_start = "Sorry, but there was a problem with the information you entered.  Please correct the following errors:\n\n";
	var _error_mid = "";
	var _error_end = "Click OK to continue.";
	var _tab = "- ";
	var _focusField = null;

	if ( !valid_email( f.email.value, min, max ) ) {
		if ( _focusField == null ) _focusField = f.email;
		_error_mid += _tab + 'Please enter a valid e-mail address where where the newsletter will be sent.\n';
	}

	if ( _error_mid.length > 0 ) {
		alert ( _error_start + _error_mid + "\n" + _error_end );
		_focusField.focus();
		return false;
	}
	
	return true;
}
