﻿// JScript File

/* Defines Filter Manager Object  */
var filterManager = {
    init: function(mode){
        // Get all options
        this.optionLinks = $$('table.options')[0].getElements('tr.option');
        
        // Init and add event handlers
        this.optionLinks.each(function(el){
            // Init
            el.enabled = true;

            el.getElements("td.toggle img")[0].setProperty("src", "/_images/icons/checkmark.gif");
            // Event handlers
            el.addEvent('mouseenter', function(){
                this.setStyle("backgroundColor", "#3E4130");
            });
            el.addEvent('mouseleave', function(){
                this.setStyle("backgroundColor", "transparent");
            });
            
            el.addEvent('click', function(){
                if (this.enabled)
                {
                    this.getElements("td.toggle img")[0].setProperty("src", "/_images/icons/crossmark.gif");
                    this.enabled = false;
                    
                    // Get filter
                    var filter = this.getProperty("id");
                    
                    // Get all items that match filter
                    if (mode == "incidentsAndEvents")
                    {
                        var items = $$('ul.incidentsAndEvents li div.' + filter);
                        
                        // Turn off items
                        items.each(function(el){
                            el.parentNode.style.display = "none";
                        });
                    }
                    else
                    {
                        var items = $$('div.columnLarge div.' + filter);
                        // Turn off items
                        items.each(function(el){
                            el.style.display = "none";
                        });
                    }
                }
                else
                {
                    this.getElements("td.toggle img")[0].setProperty("src", "/_images/icons/checkmark.gif");
                    this.enabled = true;
                    
                    // Get filter
                    var filter = this.getProperty("id");
                    
                    // Get all items that match filter
                    if (mode == "incidentsAndEvents")
                    {
                        var items = $$('ul.incidentsAndEvents li div.' + filter);
                        
                        // Turn off items
                        items.each(function(el){
                            el.parentNode.style.display = "block";
                        });
                    }
                    else
                    {
                        var items = $$('div.columnLarge div.' + filter);
                        
                        // Turn off items
                        items.each(function(el){
                            el.style.display = "block";
                        });
                    }
                }
            });
        });
    }
}

/*******************************************************************************
Section:     Global Functions
Purpose:     Defines common functions used throughout the Superfeet website.
*******************************************************************************/
/* FUNCTION DEFINITIONS */
// cross-browser createElement
function createElement(element){
    if (typeof document.createElementNS != 'undefined') return document.createElementNS('http://www.w3.org/1999/xhtml', element);
    if (typeof document.createElement != 'undefined') return document.createElement(element);
    return false;
}

/* GENERAL FUNCTIONS */
function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function openWindow(url)
{
    var options = "width=360,height=390,toolbar=0,location=0,status=0,scrollbars=0"
    var newWindow = window.open(url, "videostreamer", options);
}

/* LOAD FUNCTIONS */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/******************************************************************************
Section:    Google Analytics 
Purpose:    Load Google Analytics without stalling site
*******************************************************************************/
function loadGoogleAnalyticsHttp() {
    var head = document.getElementsByTagName('head').item(0);
    script = createElement('script');
    script.src = "http://www.google-analytics.com/urchin.js";
    script.type = 'text/javascript';
    script.id = 'googleAnalytics';
    void(head.appendChild(script));
}
function pingGoogleAnalyticsHttp(){
    if(typeof(_uacct) == "undefined") setTimeout("pingGoogleAnalyticsHttp()", 100);
    else {
    _uacct = "UA-515918-1";
    urchinTracker();
    }
}
function loadGoogleAnalyticsHttps() {
    var head = document.getElementsByTagName('head').item(0);
    script = createElement('script');
    script.src = "https://ssl.google-analytics.com/urchin.js";
    script.type = 'text/javascript';
    script.id = 'googleAnalytics';
    void(head.appendChild(script));
}
function pingGoogleAnalyticsHttps(){
    if(typeof(_uacct) == "undefined") setTimeout("pingGoogleAnalyticsHttps()", 100);
    else {
    _uacct = "UA-515918-1";
    urchinTracker();
    }
}
