$(document).ready(function(){
	clearInputs();
	fadeGall();
	ieHover('#main-nav li');
	initTabs('.tabset');
	HomeMedia();
	Seeding();
});
/*---- clear inputs function ---*/
function clearInputs(){
	$('input:text, input:password, textarea').each(function(){
		if(!this.val) this.val = this.value;
		this.onfocus = function(){
			if(this.value == this.val) this.value = '';
		}
		this.onblur = function(){
			if(this.value == '') this.value = this.val;
		}
	});
}
/*--- fade gallery function ---*/
function fadeGall(){
	var wait_time = 6000;
	$('#header .gallery').each(function(){
		var _list = $(this).children();
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		var _t;
		_list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
		function changeEl(_ind){
			_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:500});
			_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:500});
			_a = _ind;
			if(_t) clearTimeout(_t);
			_t = setTimeout(function(){
				if(_a == _list.length - 1) changeEl(0);
				else changeEl(_a + 1);
			}, wait_time);
		}
		_t = setTimeout(function(){
			if(_a == _list.length - 1) changeEl(0);
			else changeEl(_a + 1);
		}, wait_time);
	});
}
/*--- IE6 hover function ---*/
function ieHover(h_list) {
	if ($.browser.msie && $.browser.version < 7) {
		$(h_list).hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
	}
}
/*--- tabs function ---*/
function initTabs(h_list) {
	$(h_list).each(function(_ind, _el) {
		var btn_h = $(_el);
		var _btn = $(_el).find('a.tab');
		var _a = 0;
		_btn.each(function(_ind, _el) {
			this._box = $('#'+_el.href.substr(_el.href.indexOf("#") + 1));
			if($(_el).hasClass('active')) {
				this._box.show();
				_a = _ind;
			}
			else {
				this._box.hide();
			}
			_el.onclick = function() {
				if(!$(this).hasClass('active')){
					_btn.get(_a)._box.hide();
					_btn.eq(_a).removeClass('active');
					this._box.show();
					$(this).addClass('active');
					_a = _ind;
				}
				return false;
			}
		});
	});
}
/*--- IE6 png fix ---*/
var transparentImage = "images/none.gif";
function fixTrans(){
	if (typeof document.body.style.maxHeight == 'undefined'){
	var imgs = document.getElementsByTagName("img");
	for (i = 0; i < imgs.length; i++){	
		if (imgs[i].src.indexOf(transparentImage) != -1) return;
		if (imgs[i].src.indexOf(".png") != -1){
				var src = imgs[i].src;
				imgs[i].src = transparentImage;
				imgs[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
			}
		}	
	}
}
if (document.all && !window.opera) attachEvent("onload", fixTrans);
/*--- font resize function ---*/
function _fontResize(){
	var _element = document.body;
	_default = 64;
	_curent = _default;
	_max = 80;
	_min = 48;
	_element.style.fontSize = _default + '%';
	var _step = 8;
	var _aaa = document.getElementById('aaa');
	var _btn = _aaa.getElementsByTagName('a');
	for (var j = 0; j < _btn.length; j++)
	{
		_btn[j].onclick = function()
		{
			if(this.className == 'zoom-in')
			{
				_curent += _step;
				if(_curent > _max)
				_curent = _max;
				_element.style.fontSize = _curent + '%';
			}
			else if(this.className == 'zoom-out')
			{
				_curent -= _step;
				if(_curent < _min)
				_curent = _min;
				_element.style.fontSize = _curent + '%';
			}
			else 
			{
				_element.style.fontSize = _default + '%';
				_curent = _default;
			}
		}
	}
}
/*--- Homepage Tab Content ---*/
function HomeMedia(){
    $('.HomeFeature:first').show();
    $('.tab-holder ul a').click(function(event){
        event.preventDefault();
        $('.HomeFeature').hide();
        $($(this).attr('href')).show();
    });    
}
if (window.addEventListener) window.addEventListener("load", _fontResize, false);
else if (window.attachEvent) window.attachEvent("onload", _fontResize);

function PrintPage()
    {
        var DocumentContainer = document.getElementById('PrintPage');
        var WindowObject = window.open('about:blank', "Printing", 
                              "width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
        WindowObject.document.writeln(DocumentContainer.innerHTML);
        WindowObject.document.close();
        WindowObject.focus();
        WindowObject.print();
        WindowObject.close();
    }

/* --- Seed Contact with Zips & Email Signup with Name/Addy --- */
function Seeding()
{
    var formID = jQuery.url.param('ID');
    if(formID == '413')
    {
        var email = jQuery.url.param('email');
        email = email.replace(/%40/,"@");
        $('input[id*=EmailControl_MyText]').val(email);        
        //$('#ctl00_ctl00_ctl03_MyText').val(jQuery.url.param('lastname').replace(/\+/," "));
        //$('#ctl00_ctl00_ctl02_MyText').val(jQuery.url.param('firstname').replace(/\+/," "));
    }
}
