var where,who,hrefCode,styleClass,styleInfo,onClickCode,hrefTarget,linkText=null;
function ll(obj)
{
	var lk = '<a href="';
	with(obj)
	{
		if(where && who)
			lk += 'mailto:'+ who + '@' +where;
		else if(hrefCode)
			lk += hrefCode;
		lk += '"';
		if(styleClass)
			lk += ' class="'+styleClass+'"';
		if(styleInfo)
			lk += ' style="'+styleInfo+'"';
		if(onClickCode)
			lk += ' onclick="'+onClickCode+'"';
		if(hrefTarget)
			lk += ' target="'+hrefTarget+'"';
		lk += '>';
		if(linkText)
			lk += linkText;
		else if(!linkText && (where && who))
			lk += who + '@' +where;
	}
	lk += '</a>';
	return lk;
}

function robertsLink()
{
	document.write('If Robert took your photo on a Sierra Club hike, <a href="http://www.swt.org/hikesierra/" target="_blank" class="external">this is where he put it</a>.');
}
//cross browser window width getter
function getWidth()
{
	if (window.innerWidth)
		return window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		return document.documentElement.clientWidth;
	else if (document.body.offsetWidth)
		return document.body.offsetWidth;
	else if (document.body)
		return document.body.clientWidth;
}
//cross browser window height getter
function getHeight()
{
	if (window.innerHeight)
		return window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		return document.documentElement.clientHeight;
	else if (document.body.offsetHeight)
		return document.body.offsetHeight;
	else if (document.body)
		return document.body.clientHeight;
}
//Emulate full Array object support in browsers that don't provide full support already, such as Mac IE5
if(typeof Array.prototype.shift=='undefined') 
	Array.prototype.shift=function()
	{
		var firstElem=this[0];
		for(i = 0;i < this.length-1;i++)
			this[i]=this[i+1];
		this.length--;
		return firstElem;
	};
if(typeof Array.prototype.push=='undefined') 
	Array.prototype.push=function()
	{
		var arg = arguments[0];
		this[this.length++] = arg;
	};
function domBrowser()
{
	return document.getElementById;
}
//generic toggle function
function toggleDisplay(div)
{
	if(!domBrowser()) 
		return; 
	else 
	{
		thediv = document.getElementById(div);
		if(thediv.style.display == null || thediv.style.display == 'block')
			thediv.style.display = 'none';
		else 
			thediv.style.display = 'block'; 
	}
}
function send()
{
	var recip = document.forms['milkmaids'].recipient;
	var myemail = "%64%69%61%6E%65%40%73%61%6E%74%61%62%61%72%62%61%72%61%68%69%6B%65%73%2E%63%6F%6D";
	recip.value=unescape(myemail);
}
function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener)
  {
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } 
  else if (elm.attachEvent)
  {
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } 
  else 
  {
    //alert("Handler could not be removed");
  }
}
function externalLinks()
{
	var hyperlinks = document.links;
	for(i=0;i<hyperlinks.length;i++)
	{
		if(/http:\/\//i.test(hyperlinks[i].href) == true && /condortrail/i.test(hyperlinks[i].href) == false)
		{//we got one
			if(/<img/i.test(hyperlinks[i].innerHTML) == false){
				//not if it's a link on an image
				hyperlinks[i].className = 'external';
			}
			var the_href = redirectLinks(hyperlinks[i].href);
			var the_title = hyperlinks[i].getAttribute('title') ? hyperlinks[i].getAttribute('title') : "";
			the_title += ' ' + hyperlinks[i].href;
			hyperlinks[i].setAttribute('title','External:' + the_title);
			hyperlinks[i].setAttribute('target','_blank');
			hyperlinks[i].href = the_href;
		}
	}
}

function redirectLinks(the_href){
	var the_checked_href = the_href;
	//I only want to track these
	var to_track = [
	"http://www.sixmoondesigns.com",
	"http://www.equinoxltd.com",
	"http://www.gossamergear.com",
	"http://www.golite.com",
	"http://www.tarptent.com",
	"http://www.jacksrbetter.com",
	"http://www.mountainlaureldesigns.com",
	"http://www.ula-equipment.com",
	"http://www.zpacks.com",
	"http://zenstoves.net",
	"http://marmot.com",
	"http://www.montbell.us",
	"http://www.westernmountaineering.com",
	"http://www.nunatakusa.com",
	"http://www.froggtoggs.com",
	"http://www.integraldesigns.com"
	];
	if(the_href.charAt(the_href.length-1) == '/')
		the_checked_href = the_href.substring(0,the_href.length-1);
	for(var j in to_track){
		if(to_track[j] == the_checked_href){
			the_checked_href = the_checked_href.replace('http://','');
			the_checked_href = '/_i/redirect.php?url='+the_checked_href;
			return the_checked_href;
		}
	}
	return the_href;
}

function startList() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		for (var i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
function fileLoader(filename, filetype, media, id){
 if (filetype=="js"){
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("media", media);
  fileref.setAttribute("href", filename);
 }
 else if (filetype=="cssimport"){
  var fileref=document.createElement("style");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("media", media);
  try{
  t = document.createTextNode('@import url('+filename+');');
  fileref.appendChild(t);
  } catch(e){ }
 }
 if (typeof fileref!="undefined"){
 	node = document.getElementsByTagName("head")[0];
 	if(node)
  	node.appendChild(fileref);
 }
}
function scriptWriter(jssrc){
	document.write("<scr"+"ipt type='text/javascript'  charset='utf-8' src='"+jssrc+"'><\/scr"+"ipt>");
}

function sidebarAds(){
	//local books
	scriptWriter("http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822/US/sanbarhik-20/8001/849ce8c4-fdb0-415b-bbb9-2a0275d70f33");
	document.write('<br />');
	//google
	google_ad_client = "pub-6728273547478240";
	google_ad_slot = "5782694975";
	google_ad_width = 125;
	google_ad_height = 125;
	scriptWriter("http://pagead2.googlesyndication.com/pagead/show_ads.js");
	document.write('<br />');
	document.write('<br />');
	//good gear
	scriptWriter("http://ws.amazon.com/widgets/q?ServiceVersion=20070822&MarketPlace=US&ID=V20070822/US/sanbarhik-20/8001/e5666d1c-694c-4b87-8ccf-2284dc96c572");
	document.write('<br />');
}

function aboutAds(){
	var info = '<html><body style="background:#fff;font-size:12px;font-family:sans-serif;">If you go to Amazon through my ads and buy things, even if they are not the things I advertise, I get a small bit of money.<br /><br />So if you would like to support Santa Barbara Hikes and are planning to buy something from Amazon anyway, why not click on one of my ads to get there?</body></html>';
	var win = window.open('','ad','width=250,height=140,scrollbars');
	win.document.write(info);
	win.focus();
}

if(document.getElementById)
{
	addEvent(window, "load", startList);
	addEvent(window, "load", externalLinks);
}

google_ad_client = "pub-6728273547478240";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "CCCC66";
google_color_bg = "FFFFFF";
google_color_link = "669966";
google_color_text = "000000";
google_color_url = "FF6600";

