﻿/*	setup_page.js

	This script sets up the banner elements on the top level pages.
*/

window.onload = init;

var images;
var currentImage = 0;		// Keeps track of the currenty visible image
var animators = new Array();
var timerID;

function init() {

	// Set page ID for the menu system to work
	//
    var b = document.getElementsByTagName("body")[0];
    
    if (document.URL.indexOf("archive.aspx") != -1) {
        pageID = "pagenews1"
    }
    b.setAttribute('id', pageID);

    // Set up a 'failsafe' to ensure that our dynamic menu system
    // gets restored when the user mouses out of the menu
    //
    var c = document.getElementById("content");
    c.onmouseover = restoreMenu;
    
	// Now set up the page banner
	// 'pageHeading' is the h2 element in the banner that contains our page title
	//
	var title = document.title;
	var heading = document.getElementById("pageHeading");

	if (heading) {
	    // If we are on a blog or author page, need to set the page heading dynamically at runtime
	    //
	    if (pageID.indexOf("pagenews") != -1) {
	        var title = document.title;
	        //var pageHeading = title.substr(45);

	        heading.innerHTML = title.replace("Washington State Hunter Jumper Association | ", "");
	        // This is necessary to fix up the menu highlighting
	        //
	    }
	}

	// Make sure that show calendar selector is set to current year on page load
	// Necessary to override browser caching
	//
	var selector = document.getElementById('calendarSelect');
	if (selector) {
	
		for (var i = 0; i < selector.options.length; i++) {
			if (selector.options[i].value == activeYear) {
				selector.selectedIndex = i;			
			}
		}
	}

	// Bing map control. The map is hosted in an iframe.  We set the content after the initial page load so as not to
	// delay the initial page render
	//	
	var mapref = "http://dev.virtualearth.net/embeddedMap/v1/silverlight/road?zoomLevel=11&center=47.674_-122.12"; 		
	var map = document.getElementById("bingmap");
	if (map) {
		map.src = mapref;
	}	

	// Added second map to Evergreen Equestrian Park	
	mapref = "http://dev.virtualearth.net/embeddedMap/v1/silverlight/road?zoomLevel=13&center=47.867477143938174_-121.99044899999995&pushpins=47.867477143938174_-121.99044899999995"; 		
	map = document.getElementById("bingmap-evergreenfairgrounds");
	if (map) {
		map.src = mapref;
	}	

	// Added third map to Remlinger Equestrian Park	
	mapref = "http://dev.virtualearth.net/embeddedMap/v1/silverlight/road?zoomLevel=13&center=47.6609916687012_-121.893211364746&pushpins=47.6609916687012_-121.893211364746"; 		
	map = document.getElementById("bingmap-remlinger");
	if (map) {
		map.src = mapref;
	}	

} 

	
	// Shows a "preview" of the submenu when the user mouses over the top level tab
	// This is controlled in CSS via an ID descriptor on the 'body' tag
	//
	function peekMenu(obj) {
	
		var b = document.getElementsByTagName("body")[0];
		var s = obj.id;
		
		if (s != 'linkhome') {
		
			b.setAttribute('id', s.replace('link', 'page'));
		
			if (b.id.substring(4,7) == pageID.substring(4,7)) {
				b.setAttribute('id', pageID);
			}
		}
	}
	
	// Restores the menu to its default state
	//
	function restoreMenu(e) {	
		var b = document.getElementsByTagName("body")[0];
		if (b.id != pageID) {
			b.setAttribute('id', pageID);
		}
		return;
	}
	


	// --------------------------------------------------------------------------------------------------
	// Event handlers for the show calendar pages:
	// Manage loading of the correct calendar page
	//
	function loadCalendar(obj, rootname) {
	
		var i = obj.selectedIndex;
		var choice = obj.options[i].value;
		
		if (i == 0) {
			self.location.href = rootname + '.aspx';
		}
		else {
			self.location.href = rootname + ' (' + choice + ').aspx';
		}
	}

	// Load the correct show details based on the selected show
	//
	function loadShowDetails(obj) {

		var cells = document.getElementById('showCalendar').getElementsByTagName('td');
		var divs = document.getElementById('sidebar').getElementsByTagName('div');
		var divID;
		var e;
		
		for (var i=0; i<cells.length; i++) {
			cells.item(i).className = cells.item(i).className.replace('selectedShow', '');
		}

		for (var j=0; j<divs.length; j++) {
			divID = divs.item(j).id;
			if (divID.indexOf('-SB') != -1) {
				divs.item(j).className = 'hidden';
			}
		}

		obj.className += ' selectedShow';
		divID = obj.id + '-SB';
		e = document.getElementById(divID);
		if (e) {
			document.getElementById(divID).className = '';
		}
		
		/* self.frames['showDescription'].location.href='/content/shows/details/' + obj.id + '.html'; */
		
	}
	// --------------------------------------------------------------------------------------------------
	

// Utility function for creating obfuscated email addresses
//
function writeEmail(user, site, subject) {
		document.write('<a href=\"mailto:' + user + '@' + site);
		if (subject) {
			document.write ('?subject=' + subject);
		}
		document.write('\">');
		document.write(user + '@' + site + '</a>');
}

// Utility function to parse elements by ID
//
function $(id)
{
	return document.getElementById(id);
}

function animateNext() {
	if (currentImage < images.length) {
		fadeIn(images[currentImage]);
		currentImage++;
		timerID = window.setTimeout(animateNext, 300);
	}
}


function fadeIn(img) {
		var animator;

		animator = new Animator({duration: 300}).addSubject(new CSSStyleSubject(img, "opacity: 1;"));
		animator.seekTo(1);
}

// Function to manage display of expandable FAQ entries
//
function dsp(loc){
   if(document.getElementById) {
      var foc=loc.firstChild;
      foc=loc.firstChild.innerHTML?
         loc.firstChild:
         loc.firstChild.nextSibling;
      loc.style.color=foc.innerHTML=='+' ? '#800080' : '';
      foc.innerHTML=foc.innerHTML=='+'?'-':'+';
      
      foc=loc.parentNode.nextSibling.style?
         loc.parentNode.nextSibling:
         loc.parentNode.nextSibling.nextSibling;
         
       	 foc.style.display=foc.style.display=='block'?'none':'block'; 
   	}
}


