﻿/* PAGELOCATOR */


function PageLocator(propertyToUse, dividingCharacter) {
	this.propertyToUse = propertyToUse;
	this.defaultQS = "itinerary";
	this.dividingCharacter = dividingCharacter;
}
PageLocator.prototype.getLocation = function() {
	return eval(this.propertyToUse);
}
PageLocator.prototype.getHash = function() {
	var url = this.getLocation();
	if(url.indexOf(this.dividingCharacter)>-1) {
		var url_elements = url.split(this.dividingCharacter);
		return url_elements[url_elements.length-1];
	} else {
		return this.defaultQS;
	}
}
PageLocator.prototype.getHref = function() {
	var url = this.getLocation();
	var url_elements = url.split(this.dividingCharacter)
	return url_elements[0];
}
PageLocator.prototype.makeNewLocation = function(new_qs) {
	return this.getHref() + this.dividingCharacter + new_qs;
}
/* END PAGELOCATOR */


/* UrlChecker */
function urlChecker() {
	this.locator = new PageLocator("window.location.href", "#");
	this.timer = new Timer(this);
	this.checkWhetherChanged(0);
}
urlChecker.prototype.checkWhetherChanged = function(location){
	if(this.locator.getHash() != location) {
		//showContent(this.locator.getHash());
	}
	//this.timer.setTimeout("checkWhetherChanged", 200, this.locator.getHash());
}
/* END UrlChecker */

function initializeUrlChecker() {
	if(!document.getElementById || !document.getElementsByTagName) return;
	fix = new urlChecker();
}

function showContent(id)
{
	if(!document.getElementById || !document.getElementsByTagName) return;
	
	// a dash in the id allows for second level of nav, we need to set nav on main and sub set as selected
	var main_section = id;
	var sections = new Array();
	if (id.indexOf('-') > -1)
	{
		sections = splitContentId(id);
		main_section = sections[0];
	}

	// hide the currently selected content and nav
	hideContent(currentContent);

	//var c = document.getElementById("content-" + id);
	//if (c) c.style.display = "block";
	
	var n = document.getElementById("nav-" + main_section);
	if (n) n.className = "selected";
	
	// if there is a sub section, then we need to set that element to selected as well
	if (id != main_section)
	{
		var ns = document.getElementById("nav-" + id);
		if (ns) ns.className = "selected";
	}

	currentContent = id;
}

function hideContent(id)
{
	if(!document.getElementById || !document.getElementsByTagName) return;

	var c = document.getElementById("content-" + id);
	if (c) c.style.display = "none";
	
	var n = document.getElementById("nav-" + id);
	if (n) n.className = "";
	
	// besides hiding the current section nav, if there are subsections, the parent nav must be hidden
	var sections = new Array();
	if (id.indexOf('-') > -1)
	{
		sections = splitContentId(id);
		var np = document.getElementById("nav-" + sections[0]);
		if (np) np.className = "";
	}
}

function splitContentId(id)
{
	var sub_array = new Array();
	sub_array = id.split("-");
	return sub_array;
}

function showPopup(id)
{
	if (currentPopup.length > 0)
		hidePopup();
		
	var p = document.getElementById("popup-" + id);
	if (p) p.style.display = "block";
		
	currentPopup = id;
	return false;
}

function hidePopup()
{
	var p = document.getElementById("popup-" + currentPopup);
	if (p) p.style.display = "none";
	return false;
}

var currentPopup = "";
var currentContent = "";
//addEvent(window, "load", initializeUrlChecker);

function leftScroll(images, counter, image)
{
    var countHid = document.getElementById(counter);
    var counter = countHid.value;
    var imageString = document.getElementById(images).value;
    var imageArray = imageString.split(",");
    var imageUrl = imageArray[0];
    var imageContainer = document.getElementById(image);

    counter--;
    if(counter < 0)
        counter += imageArray.length;
    imageUrl = imageArray[counter];
    countHid.value = counter.toString();
    displayImage(imageUrl, imageContainer);
}

function rightScroll(images, counter, image)
{
    var countHid = document.getElementById(counter);
    var counter = countHid.value;
    var imageString = document.getElementById(images).value;
    var imageArray = imageString.split(",");
    var imageUrl = imageArray[0];
    var imageContainer = document.getElementById(image);

    counter++;
    if(counter > imageArray.length - 1)
        counter = 0;
    imageUrl = imageArray[counter];
    countHid.value = counter.toString();
    displayImage(imageUrl, imageContainer);
}

function displayImage(url, imageContainer)
{
    imageContainer.src = url; 
}
