﻿function toggleMe(targetId){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if (target.style.display == "none"){
				target.style.display = "";
		} else {
			target.style.display = "none";
		}
	}	 
}
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);








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];}}
}


//==========================================================================================
// PHOTO GALLERY FUNCTIONS


function po(a,b){
	this.n = a;
	this.cap = b;

}

		var pxw = new Array();
		var p = new Array();
		
		pxw[0] = new po("5w","Superpic");			// set up wide photos
		
		p[0] = new po("1","Arctic Cat racing");				// set up regular square photos
		p[1] = new po("2","Group Tour");
		p[2] = new po("3","Back to camp");
		p[3] = new po("4","Having a blast");
		p[4] = new po("5","Plenty of snow in the woods!");
		p[5] = new po("6","Twin Mountain, NH");
		p[6] = new po("7","Twin Mountain, NH");
		p[7] = new po("8","Sunset over Attitash");
		p[8] = new po("9","View of Mt. Washington - Jan 2006");
		p[9] = new po("10","View of Mt. Washington - Jan 2006");
		p[10] = new po("11","Heading towards Mt. Washington");
		p[11] = new po("12","Cruising into the notch");
		p[12] = new po("13","New Sleds for 2006");

function imagegallery(){
		var i = 0;
		document.write("<a href=\"gallery.html\"><img src=\"images/gallery/");
		document.write(pxw[0].n);
		document.write(".jpg\" alt=\"\" height=\"72\" width=\"144\" border=\"0\"></a>");
	
		for (i = 0; i < 4; i++){
			document.write("<a href=\"gallery.html\"><img class=\"imagebar\" src=\"images/gallery/");
			document.write(p[i].n);
			document.write(".jpg\" alt=\"\" height=\"72\" width=\"72\" border=\"0\"></a>");	
		} 
}


function makegallery(){
		var b = 1;		// counter to flip rows
		var w = 5;		// photos per row
		for (i = p.length-1; i >= 0; i--){
			document.write("<a href=javascript:photoPop("+i+")><img class=\"gallery\" src=\"images/gallery/");
			document.write(p[i].n);
			document.write(".jpg\" alt=\"\" height=\"72\" width=\"72\" border=\"0\"></a>");
			if(b==w){
				document.write("<br />");
				b = 1;
			}
		} 


}

function photoPop(pic){
	var w = 500;		// window width
	var h = 500;		// window height
	var next = pic+1;
	var prev = pic-1;
	
	sx=window.open("","displayWindow","toolbar=no,width="+w+",height="+h+",directories=no,status=no,scrollbars=no,resize=yes,menubar=no");
	sx.document.write("<HEAD><link href=\"ss/styles.css\" rel=\"stylesheet\" media=\"screen\" title=\"sled1\"><TITLE>Northern Extremes Photo Gallery</TITLE></HEAD><BODY BGCOLOR=\"#000000\">");
	// PAGE CONTENT START
	
	sx.document.write("<center><img src=images/gallery/"+p[pic].n+".jpg border=1><p class='infopop'>"+p[pic].cap);
	sx.document.write("<p><input type=button onclick=window.close() value=\"Close Window\">");

	// PAGE CONTENT END
	sx.document.write("</body>");
	sx.document.close();


}

