﻿/* Element Retrieval Methods
===================================================================================== */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
function getElementsBySelector(all_selectors) {
	var selected = new Array();
	if(!document.getElementsByTagName) return selected;
	all_selectors = all_selectors.replace(/\s*([^\w])\s*/g,"$1");
	var selectors = all_selectors.split(",");
	// Grab all of the tagName elements within current context	
	var getElements = function(context,tag) {
		if (!tag) tag = '*';
		// Get elements matching tag, filter them for class selector
		var found = new Array;
		for (var a=0,len=context.length; con=context[a],a<len; a++) {
			var eles;
			if (tag == '*') eles = con.all ? con.all : con.getElementsByTagName("*");
			else eles = con.getElementsByTagName(tag);

			for(var b=0,leng=eles.length;b<leng; b++) found.push(eles[b]);
		}
		return found;
	}

	COMMA:
	for(var i=0,len1=selectors.length; selector=selectors[i],i<len1; i++) {
		var context = new Array(document);
		var inheriters = selector.split(" ");

		SPACE:
		for(var j=0,len2=inheriters.length; element=inheriters[j],j<len2;j++) {
			//This part is to make sure that it is not part of a CSS3 Selector
			var left_bracket = element.indexOf("[");
			var right_bracket = element.indexOf("]");
			var pos = element.indexOf("#");//ID
			if(pos+1 && !(pos>left_bracket&&pos<right_bracket)) {
				var parts = element.split("#");
				var tag = parts[0];
				var id = parts[1];
				var ele = document.getElementById(id);
				if(!ele || (tag && ele.nodeName.toLowerCase() != tag)) { //Specified element not found
					continue COMMA;
				}
				context = new Array(ele);
				continue SPACE;
			}

			pos = element.indexOf(".");//Class
			if(pos+1 && !(pos>left_bracket&&pos<right_bracket)) {
				var parts = element.split('.');
				var tag = parts[0];
				var class_name = parts[1];

				var found = getElements(context,tag);
				context = new Array;
 				for (var l=0,len=found.length; fnd=found[l],l<len; l++) {
 					if(fnd.className && fnd.className.match(new RegExp('(^|\s)'+class_name+'(\s|$)'))) context.push(fnd);
 				}
				continue SPACE;
			}

			if(element.indexOf('[')+1) {//If the char '[' appears, that means it needs CSS 3 parsing
				// Code to deal with attribute selectors
				if (element.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?['"]?([^\]'"]*)['"]?\]$/)) {
					var tag = RegExp.$1;
					var attr = RegExp.$2;
					var operator = RegExp.$3;
					var value = RegExp.$4;
				}
				var found = getElements(context,tag);
				context = new Array;
				for (var l=0,len=found.length; fnd=found[l],l<len; l++) {
 					if(operator=='=' && fnd.getAttribute(attr) != value) continue;
					if(operator=='~' && !fnd.getAttribute(attr).match(new RegExp('(^|\\s)'+value+'(\\s|$)'))) continue;
					if(operator=='|' && !fnd.getAttribute(attr).match(new RegExp('^'+value+'-?'))) continue;
					if(operator=='^' && fnd.getAttribute(attr).indexOf(value)!=0) continue;
					if(operator=='$' && fnd.getAttribute(attr).lastIndexOf(value)!=(fnd.getAttribute(attr).length-value.length)) continue;
					if(operator=='*' && !(fnd.getAttribute(attr).indexOf(value)+1)) continue;
					else if(!fnd.getAttribute(attr)) continue;
					context.push(fnd);
 				}

				continue SPACE;
			}

			//Tag selectors - no class or id specified.
			var found = getElements(context,element);
			context = found;
		}
		for (var o=0,len=context.length;o<len; o++) selected.push(context[o]);
	}
	return selected;
}
function getChild(startParent) {
  EndChild = startParent.firstChild ;
  while(EndChild.nodeType != 1){
    EndChild = EndChild.nextSibling ;
  }
  return EndChild;
}

/* Flash Border Removal
===================================================================================== */
function initFlashBorders() {
    if (document.body.outerHTML && (document.getElementsByTagName('object')).length) {
		var objs = document.getElementsByTagName('object') ;
		var i = objs.length - 1 ;
		do {
			if (objs[i].getAttribute('type') == 'application/x-shockwave-flash') {
				var o = objs[i] ;
				var h = o.outerHTML ;
				var params = '' ;
				var j = o.childNodes.length - 1 ;
				do {
					var p = o.childNodes[j] ;
					if (p.tagName == "PARAM") params += p.outerHTML ;
				} while (j--) ;
				var tag = h.split(">")[0] + ">" ;
				o.outerHTML = tag + params + o.innerHTML + " </object>" ;
			}
		} while (i--)
	}
}

/* Form Element Methods
===================================================================================== */
function initClearInputs() {
  inputs = document.getElementsByTagName('input');
  for (i = 0; i < inputs.length; i++) {
    if ((inputs[i].getAttribute('value')) && (inputs[i].getAttribute('type') == 'text')) {
            inputs[i].setAttribute('default',inputs[i].getAttribute('value'));
            inputs[i].onfocus = function() {
				if (this.value == this.getAttribute('default')) {
					this.value = '' ;
				}
			}
			inputs[i].onblur = function() {
				if (this.value == '') {
					this.value = this.getAttribute('default');
				}
			}
    }
  }
}

/* The DOM Loaded Event Queue
===================================================================================== */
var _loadQueue = new Array();

function addLoadEvent(func){
    _loadQueue.push(func);
}

/* The DOM Loaded Script */

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", processEventQueue, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    if (window.location.protocol != 'https:')
    {
        document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
        var script = document.getElementById("__ie_onload");
        script.onreadystatechange = function() {
            if (this.readyState == "complete") {
                processEventQueue(); // call the onload handler
            }
        };
    }
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            processEventQueue(); // call the onload handler
        }
    }, 10)
}

/* for other browsers */
window.onload = processEventQueue;

/* dom loaded call */
function processEventQueue() {
    // quit if this function has already been called
	if (arguments.callee.done) return;
    
    // flag this function so we don't do the same thing twice
	arguments.callee.done = true;
    
    // kill the timer
	if (_timer) clearInterval(_timer);

    // process the event queue
    for (i = 0; i < _loadQueue.length; i++){
       setTimeout(_loadQueue[i],0);
    }
    
    // clear the event queue
    _loadQueue = new Array();
}
/*FLASH OPACITY============================================================================*/

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 


    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
        //setTimeout("changeVisible(" + i + ",'" + id + "')",(timer * speed)); 
        //var object = document.getElementsByName("fadebanner")
        //for (var i = 0; i < object.length; i++) {
        //    object[i].style.Visibility = "hidden"; 
            //object[i].style.z-order = "-1"; 
        //}

    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
         
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    /*var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
    */
    //alert(document.getElementById('fadebanner').name);
    var object = document.getElementsByName("fadebanner")
    //alert(test[1].name);
    //alert(test.length);    
    for (var i = 0; i < object.length; i++) {
        object[i].style.opacity = (opacity / 100); 
        object[i].style.MozOpacity = (opacity / 100); 
        object[i].style.KhtmlOpacity = (opacity / 100); 
        object[i].style.filter = "alpha(opacity=" + opacity + ")"; 
    }
} 

var mytime
var timeout
timeout = 1
function TimeofFade() { 
    if(timeout==1)
    {
        mytime = setTimeout("opacity('fadebanner', 100, 0, 500);",1000);
        timeout = 2;
        //alert(timeout);
        setTimeout("TimeofFade();",1000)
    }
    else if(timeout==3)
    {
        mytime = setTimeout("opacity('fadebanner', 0, 100, 500);",1000);
        timeout = 4;
        //alert(timeout);
        setTimeout("TimeofFade();",1000)
    }
    else if(timeout==2)
    {
        clearTimeout(mytime);
        timeout = 3;
        //alert(timeout);
        setTimeout("TimeofFade();",2000)
    }
    else if(timeout==4)
    {
        clearTimeout(mytime);
        timeout = 1;
        //alert(timeout);
        setTimeout("TimeofFade();",2000)
    }    
}
