/* initializer.js 
    this is just a simple script to enqueue initialization methods
    
    */
var podomatic = {}    
function initializer()
{
    var queue       = {};
    var t           = this;
    var isLoading   = false;
    
    this.add = function (/*function*/ func){
        queue[func.toString()] = func    
    }
    this.init   = function(){
    	if(isLoading)
    		return;
        isLoading = true;
        for (func in queue)
                queue[func]();                  
    } 
    this.ie     = function(){
        if (document.readyState == "interactive")
            if(!isLoading)
                t.init();
    }
    this.moz    = function(){
             if(!isLoading)
                t.init();
            
    }
}    
/* run initialization on page load*/
podomatic.init = new initializer(); 
var isInit = false
if (typeof (document.onreadystatechange) != "undefined")
{
   document.onreadystatechange = podomatic.init.ie
   isInit = true 
}
if (document.addEventListener) 
{
	document.addEventListener("DOMContentLoaded", podomatic.init.moz, false);
    isInit = true 
} 
    window.onload = podomatic.init.init;
    

/* 	base hashmap functions. 	
	these functions will streamline the process of looking up arrays of shit.
/* stores an element to a js_Hash object*/
function add_Entry(s_key,s_value)
{
	var retVal = false
	if (typeof s_key == "string")
	{
		this[s_key] = s_value
		retVal		= true
	}	
	return retVal
}
/* add a bunch of strings-- helpful for me*/
function add_String_Entries(arr_values)
{
	for (var i=0;i <  arr_values.length; i++)
	{
		this.add(arr_values[i],arr_values[i]); 
	}
}

/* returns an element given a key	*/			
function get_Entry(s_key)
{
	return this[s_key]
}

/* basic hash structure*/
function js_Hash()
{
	this.name		= "a hash";
	this.add 		= add_Entry;
	this.get 		= get_Entry;
	this.addStrings = add_String_Entries; 
}				


/* EXTRA ARRAY FUNCTIONS------------------------------------------------------*/
/*	Purpose; these functions allow me to perform basic boolean operations on 
	arrays which I can use for some types of operations. I also added some basic 
	lookup operations.
/* indexof retreives the index of an item in an array given a value*/
function indexOfValue(Key)
{
    array1 = this;
	for (var i = 0; i < array1.length; i++)
	{
	    var array_value 			= array1[i];
		var array_key				= null
		switch (typeof(array_value))
		{
			case "string":
				array_key			= array_value;
				break;
			case "undefined":
				//alert("array undefined")
				break;
			case "object":
				array_key			= array_value.id;
			default:
				//alert(typeof(array_value))	
		}
        if (array_key == Key)
        {
            return i
        }
     }
     //alert("no match")
     return null    
}

function removeValue(value)
{
	this.splice(this.getIndex(value),1)
}


/* match string contenets of for arrays I modified this to also try and 
	match against the id property of a returned object. 
	this method returns the object matching the key, or false */
function matchString(Key)
{
	var tmpIndex = this.getIndex(Key)
	if (tmpIndex == null)
		return false;
	else	
		return this[tmpIndex]
}	

/* some simple set functions for Arrays these functions will work
	only on arrays of strings right now*/
function unionArrays(array2)
{
	var ret_array 	= []
	var tmp_hash	= {}
	var array1 		= this
	//build first array
	for (var i = 0; i < array1.length; i++)
	{
		var array_value 			= array1[i];
		var array_key 				= (typeof array_value.ci_id !="undefined" ? 
													array_value.ci_id :array_value )	 
		tmp_hash[array_key] 		= array_value;
		ret_array[ret_array.length] 	= array_value;
	}
	//compare entries between second array and hash and append extras
	for (var i = 0; i < array2.length; i++)
	{
		var array_value = array2[i]
		var array_key 	= (typeof array_value.ci_id !="undefined" ? 
									array_value.ci_id :array_value )	
		if (typeof tmp_hash[array_key] == "undefined") 
		{
			ret_array[ret_array.length] = array_value;
		}
	}
	return ret_array;
}				

/* returns the intersection of array1 and array2*/
function intersectionArrays(array2)
{
	var ret_array 	= []
	var tmp_hash	= {}
	var array1 		= this
	//build first array
	for (var i = 0; i < array1.length; i++)
	{
		var array_value 			= array1[i];
		var array_key 				= (typeof array_value.ci_id !="undefined" ? 
													array_value.ci_id :array_value )	 
		tmp_hash[array_key] 		= array_value;
	}
	//compare entries between second array and hash and append extras
	for (var i = 0; i < array2.length; i++)
	{
		var array_value = array2[i]
		var array_key 	= (typeof array_value.ci_id !="undefined" ? 
											array_value.ci_id :array_value )	 
		if (typeof tmp_hash[array_key] != "undefined") 
		{
			ret_array[ret_array.length] = array_value;
		}
	}
	return ret_array;
}
/* returns items in (1) not in (2)*/
function differenceArrays(array2)
{
	var ret_array 	= []
	var tmp_hash	= {}
	var array1 		= this
	//build first array
	for (var i = 0; i < array2.length; i++)
	{
		var array_value 			= array2[i];
		var array_key 				= (typeof array_value.ci_id !="undefined" ? 
													array_value.ci_id :array_value )	 
		tmp_hash[array_key] 		= array_value;
	}
	//compare entries between second array and hash and append extras
	for (var i = 0; i < array1.length; i++)
	{
		var array_value = array1[i]
		var array_key 	= (typeof array_value.ci_id !="undefined" ? 
										array_value.ci_id :array_value )	 

		if (typeof tmp_hash[array_key] == "undefined") 
		{
			ret_array[ret_array.length] = array_value;
		}
	}
	return ret_array;
}
			
Array.prototype.union 			= unionArrays;
Array.prototype.intersection 	= intersectionArrays;
Array.prototype.difference 		= differenceArrays;			
Array.prototype.match			= matchString;
Array.prototype.getIndex      	= indexOfValue;
Array.prototype.remove 			= removeValue;

/* removes an entry from a hash*/
Object.removeEntry	= function(source_object,s_key){
	var return_object = {}
	for (s_attribute_name in source_object)
	{
		if (s_attribute_name != s_key)
			return_object[s_attribute_name] = source_object[s_attribute_name];
	}	
	return return_object;
}

/*******************************************************************************
UTILITY METHODS
*******************************************************************************/
/* this function walks the dom tree from one object to find another bearing
	a named attribute. if no attribute found it returns null*/
function getElementByAttribute(element,s_attribute)
{
	var retVal = null
	if (element.tagName != "HTML")
	{
		if (element.getAttribute(s_attribute)!= null)
		{
			retVal = element;
		}
		else
		{
			retVal = getElementByAttribute(element.parentNode,s_attribute);
		}
	}
	return retVal;
}
/* this function gets an element by classname.*/
function getParentByTag(element,tagName)
{
	var retVal = null
	if (element.tagName != "HTML")
	{
		if (element.tagName == tagName)
		{
			retVal = element;
		}
		else
		{
			retVal = getParentByTag(element.parentNode,tagName );
		}
	}
	return retVal;
}
/* extracts an array of integers from a string*/
function  parseIntArray (tmpArray) 				 
	{
		for (var i =0 ;i< tmpArray.length; i++)	
		{
			tmpArray[i] = parseInt(tmpArray[i])
		}
		return tmpArray
	}
    /** removes a viewport object from the viewport array. Windowmanager utilizes
        this method as part of the process of queueing and dequeuing scaling.*/
    
podomatic.getXOffset = function (el){
            if (el == null ) return 0;
            return (el.offsetLeft + podomatic.getXOffset(el.offsetParent))
        }
podomatic.getYOffset =function(el){
        if (el == null ) return 0;
        
        var foo =  (el.offsetTop + podomatic.getYOffset(el.offsetParent))
        return foo
        }
      