﻿/**
* ...
* @author Josh Bennett
* @copyright (c)2008 Whittmanhart
*/
//Dom Ready
window.addEvent('domready', function(){
/*if(navigator.appVersion.indexOf("MSIE 6")>-1)
{
	(function(){this.padding="0px";this.backgroundImage="none"}).call(document.getElementById('links').firstChild.style);
}*/

//________________Text Resize__________________

	if($('tools_textSizeSelector')){
		//If javascript is enabled set text href to javascript:void(0);
		$("normal").href = "javascript:void(0)";
		$("large").href = "javascript:void(0)";
		$("xlarge").href = "javascript:void(0)";

		var textSizes = new Object();//Hold a key value pair [String tagName, Number fontSize]
		var contDiv = 'mainContent';//sets which element's children will be affected by the text resize
		
		//List of all container elements who's children will be effected by text resizing
		var contResizeElements = ["informationArea", "formArea", "horizontalCallouts", "InfoWraper"]
		
		for(var i = 0; i<contResizeElements.length; i++){
			if ($(contResizeElements[i])) {//If element 'informationArea' area exists set contDiv
				$$('#' + contResizeElements[i] + ' *').each(function(el){
				    if( el.getProperty ) {
				        el.origFontSize = parseInt(el.getStyle('font-size'), 10);
			        }
				});
			}
		}		
		//Functions
		//for resizing text
		var resizeText = function(increaseBy){
			$$('*').each(function(el){
				if(el.origFontSize)
					el.setStyle('font-size', el.origFontSize + increaseBy )
			});
			return increaseBy;
		}
		
		$$('#tools_textSizeSelector a').each(function(el){
			if(el.getProperty('rel')){
				var tmpStr = el.getProperty('rel');
				var fontSize = parseInt(tmpStr.substr(tmpStr.indexOf("_")+1)) - 12;
				if(isNaN(fontSize))
					fontSize=12;
				el.setStyle('font-size', 12 + fontSize + "px");
			}
			el.addEvent('click', function(e){
				$('tools_textSizeSelector').getElement('.selected').removeClass('selected');
				var sizeAddition = parseInt(this.getStyle('font-size'), 10) - 12;
				this.addClass('selected');
				
				var sizeCookie = Cookie.write('fontSize', sizeAddition , {'path':'/'});
				
				resizeText(sizeAddition);
			});
		});

		if(Cookie.read('fontSize')){
			$$('#tools_textSizeSelector a').each(function(el){
				el.removeClass('selected')
			})
			switch(resizeText(parseInt(Cookie.read('fontSize'), 10))){
				case 0:
					$('normal').addClass('selected');
				break;
				case 2:
					$('large').addClass('selected');
				break;
				case 4:
					$('xlarge').addClass('selected');
				break;
				default:
					$('normal').addClass('selected');
				break;
			}
		}
		
	}//end if

//_________________Print Button_________________		
	if($('callouts_printBtn')){
		$('callouts_printBtn').getElement('a').setProperty('href', 'javascript:void();').addEvent('click', function(e){
			window.print();
		})
	}
	
//___________target="Blank" XHTML strict work around_______________
	$$('a').each(function(el){
		if(el.getProperty('rel') == 'external' ){
			el.setProperty('target', '_blank')
		}
	})

});


