

var fNavO = function(oSource, sOriginalState, bOn){
	if(oSource.getAttribute('init_state') != 'on'){
		if(bOn){
			oSource.src = aNavImages_on[oSource.getAttribute('navindex')].src;
		}else{
			oSource.src = aNavImages_off[oSource.getAttribute('navindex')].src;
		}
	}
}

var fPopUp = function(sHref, nMode){
	var winPopup = [];
	
	switch(nMode){
		case 1: // RTE
			winPopup[nMode] = window.open(sHref, 'winPopup' + nMode, 'dependant=yes, toolbar=no, status=no, menubar=no, scrollbars=yes, movable=yes, resizable=yes, width=600, height=500');
			break;
		default:
			winPopup[nMode] = window.open(sHref, 'winPopup' + nMode, '');
			break;
	}
}

var fFitWindowSize = function(oContainer){
	window.resizeTo(oContainer.offsetWidth + 20, oContainer.offsetHeight + 85);
}

var fCenterWindow = function(oWindow){
	var nY = new Number((window.screen.availHeight - oWindow.document.body.offsetHeight) / 2 - 200);
	var nX = new Number((window.screen.availWidth - oWindow.document.body.offsetWidth) / 2);
	oWindow.moveTo(nX, nY);
}

var fCenterElement = function(sElement){
	var oElement = $(sElement);
	oElement.setStyle('top', (document.body.offsetHeight / 2) - (oElement.getSize().size.y / 2));
	oElement.setStyle('left', (document.body.offsetWidth / 2) - (oElement.getSize().size.x / 2));
}

var fCheckEmail = function(sEmail){
	var reFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (reFilter.test(sEmail)){
		return true;
	}else{
		return false;
	}
}

function fCronusMonthChanged(sElement){
    var oDays = $('txtDay_' + sElement);
    var oMonths = $('txtMonth_' + sElement);
    var oYears = $('txtYear_' + sElement);
    var nDays = new Number(oDays.getChildren().length);

    oDays.empty();
    
    switch(oMonths.value){
        case '1':
        case '3':
        case '5':
        case '7':
        case '8':
        case '10':
        case '12':
            for(var nIndex = 1; nIndex <= 31; nIndex++){
                var oDay = new Option(nIndex, nIndex)
		        oDays.options.add(oDay);
            }
            break;
        case '2':
            if(oYears.value % 4 == 0){
                nDays = 29;
            }else{
                nDays = 28;
            }
            for(var nIndex = 1; nIndex <= nDays; nIndex++){
                var oDay = new Option(nIndex, nIndex);
		        oDays.options.add(oDay);
            }
            break;
        case '4':
        case '6':
        case '9':
        case '11':
            for(var nIndex = 1; nIndex <= 30; nIndex++){
                var oDay = new Option(nIndex, nIndex);
		        oDays.options.add(oDay);
            }
            break;
    }
}

var fSwitch = function(sElement){
	if($(sElement).getStyle('display') == 'none'){
		$(sElement).setStyle('display', 'block');
	}else{
		$(sElement).setStyle('display', 'none');
	}
}

var fTableRowHighlight = function(oSource, bOver){
	var oRow = oSource.parentNode;
	for(var nIndex = 0; nIndex < oRow.childNodes.length; nIndex++){
		if(oRow.childNodes[nIndex].tagName == 'TD'){
			oRow.childNodes[nIndex].style.backgroundColor = bOver ? '#F4F4F4' : '#E4E4E4';
			oRow.childNodes[nIndex].style.color = bOver ? '#BC1F25' : '#000';
		}
	}
}

var fParseRSS = function (sRSS, sTarget){
	var xmlobject = (new DOMParser()).parseFromString(sRSS, "text/xml");
	
	var root = xmlobject.getElementsByTagName('rss')[0];

	$(sTarget).setHTML('<textarea cols="30" rows="10">' + sRSS + '</textarea>');
}

var fBlinkComment = function(nItemID){
	var oContainer = $('divComment' + nItemID);
	var oElement = $('divCommentContainer' + nItemID)
	var nHeight = oElement.getSize().size.y;
	var oBlink = new Fx.Style(oContainer, 'height', {duration: 500, transition: Fx.Transitions.Cubic.easeOut});
	if(oContainer.getSize().size.y > 1){
		oBlink.start(0).chain(function(){
			//fInitSlider(g_nMainSliderPos);
		});
	}else{
		oBlink.start(nHeight).chain(function(){
			//fInitSlider(g_nMainSliderPos);
		});
	}
}

var fSwitchAdminMenu = function(oSource){
	var oMenuContent = $('divAbsAdminMenu');
	var oMenu = $('divAdminMenu');
	var oFx1 = new Fx.Styles(oMenu, {wait: true, duration: 700, transition: Fx.Transitions.Elastic.easeOut});
	var oFx2 = new Fx.Style(oMenuContent, 'opacity', {wait: false, duration: 500, transition: Fx.Transitions.Cubic.easeOut});
	if(oMenu){
		if(oMenu.getAttribute('active') == 0){
			oMenu.setStyles({'display': 'block', 'opacity': 0.75});
			var nWidth = oMenuContent.getSize().size.x;
			var nHeight = oMenuContent.getSize().size.y;
			//alert([nWidth, nHeight]);
			oMenuContent.setStyle('opacity', 0);
			oFx1.start({'width': nWidth, 'height': nHeight}).chain(function(){
				oFx2.start(1);
			});
			oMenu.setAttribute('active', 1);
		}else{
			oFx1 = new Fx.Styles(oMenu, {wait: false, duration: 300, transition: Fx.Transitions.Cubic.easeOut});
			oFx2.start(0).chain(function(){
				oFx1.start({'width': '0px', 'height': '0px'}).chain(function(){
					oMenu.setStyles({'display': 'none'});
				});
			});
			oMenu.setAttribute('active', 0);
		}
	}
	/*oMenu = null;
	oMenuContent = null;
	oFx1 = null;
	oFx2 = null;*/
}

var g_nMainPromoItr = 0;
var g_aPromoSlides = [];
var g_aPromoItems = [];
var g_oInfoRibbon;

var fMainPromo = function(sPromoEl){
	var oPromo = $(sPromoEl);
	var aItems = $$('#' + sPromoEl + ' div.promoItem')
	var nPromoItems = 0;
	var nIndex = 0;
	var nOrder = 0;
	var oItemStruct;

	if(aItems.length > 0){
		aItems.each(function(oItem){
			oItemStruct = {
				title: oItem.getElement('h3').innerHTML,
				description: oItem.getElement('div').innerHTML,
				img: oItem.getElement('img.FullSize').getProperty('src'),
				order: nIndex
			}
			g_aPromoItems[nIndex] = oItemStruct;
			nIndex++;
		});
		
		nPromoItems = g_aPromoItems.length;
		for(var nIndex = 0; nIndex < nPromoItems; nIndex++){
			var oCurImg = new Fx.Style(
				new Element('div').addClass('promoSlide').setStyles({
					'position': 'absolute',
					'left': '0px',
					'right': '0px',
					'margin': '0px',
					'padding': '0px',
					'backgroundImage': 'url(' + g_aPromoItems[nIndex].img + ')',
					'backgroundPosition': 'center center',
					'backgroundRepeat': 'no-repeat',
					'opacity': '0'
				}).injectInside(oPromo),
				'opacity',
				{duration: 1000}
			);
			g_aPromoSlides[nIndex] = oCurImg;
		}
		
		g_oInfoRibbon = new Fx.Styles(new Element('div').addClass('promoRibbon').setStyle('bottom', 0).injectInside(oPromo)).set({'opacity': 0});
		var oInfoRibbonTitle = new Element('h2').addClass('promoRibbonTitle').injectInside(g_oInfoRibbon.element);
		var oInfoRibbonDescription = new Element('div').addClass('promoRibbonDescription').injectInside(g_oInfoRibbon.element);
		g_oInfoRibbon.displayHeight = g_oInfoRibbon.element.offsetHeight;
		g_oInfoRibbon.element.setStyle('opacity', 0);

		g_oInfoRibbon.element.getElement('h2').setHTML(g_aPromoItems[0].title);
		g_oInfoRibbon.element.getElement('div').setHTML(g_aPromoItems[0].description);
		g_oInfoRibbon.custom({'opacity': [0, 0.85], 'height': [0, g_oInfoRibbon.displayHeight]});

		g_aPromoSlides[0].start(1);
		window.setTimeout('fPromoFlip();', 5000);
	}
}

var fPromoFlip = function(){
	var nItems = g_aPromoSlides.length;
	g_nMainPromoItr++;
	//alert(g_nMainPromoItr);
	g_nMainPromoItr = g_nMainPromoItr >= nItems ? 0 : g_nMainPromoItr;
	g_oInfoRibbon.custom({'opacity': [0.85, 0], 'height': [g_oInfoRibbon.displayHeight, 0]}).chain(function(){
		g_oInfoRibbon.element.getElement('h2').setHTML(g_aPromoItems[g_nMainPromoItr].title);
		g_oInfoRibbon.element.getElement('div').setHTML(g_aPromoItems[g_nMainPromoItr].description);
		g_oInfoRibbon.custom({'opacity': [0, 0.85], 'height': [0, g_oInfoRibbon.displayHeight]})
		g_aPromoSlides[g_nMainPromoItr].start(1);
		g_aPromoSlides[g_nMainPromoItr == 0 ? nItems - 1 : g_nMainPromoItr - 1].start(0);
	});
	
	window.setTimeout('fPromoFlip();', 5000);
}


String.extend({
/*	Property: stripTags
		Remove all html tags from a string.	*/
	stripTags: function() {
    return this.replace(/<\/?[^>]+>/gi, '');
  },
/*	Property: stripScripts
		Removes all script tags from an HTML string.
	*/
	stripScripts: function() {
		return this.replace(/<script[^>]*?>.*?<\/script>/img, '');
	},
/*	Property: evalScripts
		Executes scripts included in an HTML string.
	*/
	evalScripts: function() {
		if(scripts = this.match(/<script[^>]*?>.*?<\/script>/g)){
			scripts.each(function(script){
				eval(script.replace(/^<script[^>]*?>/, '').replace(/<\/script>$/, ''));
			});
		}
	},
/*	Property: replaceAll
		Replaces all instances of a string with the specified value.
		
		Arguments:
		searchValue - the string you want to replace
		replaceValue - the string you want to insert in the searchValue's place
		regExOptions - defaults to "ig" but you can pass in your preference
		
		Example:
		>"I like cheese".replaceAll("cheese", "cookies");
		> > I like cookies
	*/
	replaceAll: function(searchValue, replaceValue, regExOptions) {
		var re = new RegExp(searchValue, $pick(regExOptions,'gi'));
		return this.replace(re, replaceValue);
	},
/*	Property: urlEncode
		urlEncodes a string (if it is not already).
		
		Example:
		> "Mondays aren't that fun".urlEncode()
		> > Mondays%20aren%27t%20that%20fun
	*/
	urlEncode: function() {
		if (this.indexOf('%') > -1) return this;
		else return escape(this);
	},
/*	Property: parseQuery
		Turns a query string into an associative array of key/value pairs.
		
		Example:
(start code)
"this=that&what=something".parseQuery()
> { this: "that", what: "something" }

var values = "this=that&what=something".parseQuery();
> values.this > "that"
(end)
	*/
	parseQuery: function() {
		var pairs = this.match(/^\??(.*)$/)[1].split('&');
		var params = {};
		pairs.each(function(pair) {
      pair = pair.split('=');
      params[pair[0]] = pair[1];
    });
		return params;
	}
});

var fMouseX = function(evt) {
	if (!evt) evt = window.event; 
	if (evt.pageX) return evt.pageX; 
	else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;
}

var fMouseY = function(evt) {
	if (!evt) evt = window.event; 
	if (evt.pageY) return evt.pageY; 
	else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;
}

window.addEvent('domready', function(){
	fMainPromo('divLayoutPromo');
	if($('divNavWrap')){
		$$('#divNavWrap div.navItem').each(function(oItem){
			oItem.addEvents({
				'mouseover': function(){
					if(!window.ie)
						new Fx.Style(oItem, 'background-position', {wait: true, duration: 500, transition: Fx.Transitions.Cubic.easeOut}).start('0px -45px');
					else
						oItem.style.backgroundPosition = '0px -45px';
				},
				'mouseout': function(){
					if(!window.ie)
						new Fx.Style(oItem, 'backgroundPosition', {wait: true, duration: 500, transition: Fx.Transitions.Cubic.easeOut}).start('0px 0px');
					else
						oItem.style.backgroundPosition = '0px 0px';
				},
				'click': function(){
					location.href = '/' + oItem.id.replace('divNav', '') + '.asp';
				}
			});
		});
	}
});

Element.extend({
 
	clearValue: function(){
		switch(this.getTag()){
			case 'select':
				$each(this.options, function(option){
					if (option.selected) option.selected = false;
				});
			case 'input':
				if (this.checked || ['hidden','submit','button'].contains(this.type)) {
					if (['checkbox', 'radio'].contains(this.type)) this.checked = false;
					break;
				}
			case 'textarea': this.value = '';
		}
		return false;
	},
 
	clearFormElements: function(){
		this.getFormElements().each(function(el){ el.clearValue() });
	}
 
});

window.addEvent('load', function(){

});

window.addEvent('resize', function(){

});



