function initPage(){
	if(typeof($) == 'function'){
		ieHover('#nav li');
		initTabs('.tabset');
		clearInputs();
		initGall();
		InitVideos();
		Seeding();
		RecolorLinks();
	}
	resizefonts();
}
if (window.addEventListener) window.addEventListener("load", initPage, false);
else if (window.attachEvent && !window.opera) window.attachEvent("onload", initPage);
/*--- init fage gallery function ---*/
function initGall(){
	var stay_time = 5000; //in ms
	$('.gallery .gallery-list').each(function(){
		var _list = $(this).children();
		var btn_h = $('<ul></ul>');
		var _t;
		var _flag = true;
		$(this).after(btn_h);
		btn_h.wrap('<div class="pager"></div>');
		_list.each(function(_i){
			if(_i < 9) btn_h.append('<li><a href="#">0'+(_i+1)+'</a></li>');
			else btn_h.append('<li><a href="#">'+(_i+1)+'</a></li>');
		});
		_btn = btn_h.find('a');
		var _a = _list.index(_list.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		btn_h.prepend('<li class="white"><a href="#">&laquo;</a></li>').append('<li class="white"><a href="#">&raquo;</a></li>');
		btn_h.children(':last').click(function(){
			if(_a == _list.length - 1) changeEl(0);
			else changeEl(_a + 1);
			return false;
		});
		btn_h.children(':first').click(function(){
			if(_a == 0) changeEl(_list.length - 1);
			else changeEl(_a - 1);
			return false;
		});
		if($.browser.msie && $.browser.version <= 7) _list.removeClass('active').hide().eq(_a).addClass('active').show();
		else _list.removeClass('active').css('opacity', 0).eq(_a).addClass('active').css('opacity', 1);
		_btn.eq(_a).parent().addClass('active');
		
		_btn.click(function(){
			if(_t) clearTimeout(_t);
			_flag = false;
			changeEl(_btn.index(this));
			return false;
		}).parents('ul:eq(0)').mouseenter(function(){
			_flag = false;
			if(_t) clearTimeout(_t);
		});
		$(this).mouseenter(function(){
			_flag = false;
			if(_t) clearTimeout(_t);
		}).mouseleave(function(){
			_flag = true;
			_t = setTimeout(function(){
				if(_a == _list.length - 1) changeEl(0);
				else changeEl(_a + 1);
			}, stay_time);
		});
		
		function changeEl(_ind){
			if(_t) clearTimeout(_t);
			if(_ind != _a){
				if($.browser.msie && $.browser.version <= 7){
					_list.eq(_a).removeClass('active').hide();
					_list.eq(_ind).addClass('active').show();
				}
				else{
					_list.eq(_a).removeClass('active').animate({opacity: 0}, {queue:false, duration:500});
					_list.eq(_ind).addClass('active').animate({opacity: 1}, {queue:false, duration:500});
				}
				_btn.eq(_a).parent().removeClass('active');
				_btn.eq(_ind).parent().addClass('active');
				_a = _ind;
				if(_flag) _t = setTimeout(function(){
					if(_a == _list.length - 1) changeEl(0);
					else changeEl(_a + 1);
				}, stay_time);
			}
		}
		
		if(_flag) _t = setTimeout(function(){
			if(_a == _list.length - 1) changeEl(0);
			else changeEl(_a + 1);
		}, stay_time);
	});
}
/*---- 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;
		}
	});
}
/*--- 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;
			}
		});
	});
}
/*--- font resize function ---*/
function resizefonts () {
 	var fMin = document.getElementById("font-min");
	 var fNormal = document.getElementById("font-normal");
	 var fMax = document.getElementById("font-max");
	 var fSize = 100;
 
	 var body = document.getElementsByTagName("body")[0];
	 body.style.fontSize = "120%";
 
	 fNormal.onclick = function (){
		  body.style.fontSize = "120%";
		  return false;
	 }
	 fMin.onclick = function (){
		  fSize = body.style.fontSize.replace("%","");
		  fSize = parseInt(fSize) - 7.5;
		  if (fSize <= 40) fSize = 40;  
		  body.style.fontSize = fSize+"%";
		  return false;
	 }
	 fMax.onclick = function (){
		  fSize = body.style.fontSize.replace("%","");
		  fSize = parseInt(fSize) + 7.5;
		  if (fSize >= 145) fSize = 145;
		  body.style.fontSize = fSize+"%";
		  return false;
	 }
}

/* --- Video stuff --- */
function InitVideos()
{
    $('#tab2 .HomeFeature:first').show();
    $('#tab2 .videolist li:gt(0)').show();
    $('#tab2 .videolist a').click(function(event){
        event.preventDefault();
        $('#tab2 .HomeFeature').hide();
        $($(this).attr('href')).show();
        $('#tab2 .videolist li').show();
        $(this).parent().hide();
    });
}

/* --- Seed Contact with Zips & Email Signup with Name/Addy --- */
function Seeding()
{
    if(jQuery.url.attr('source').match(/contactform/i)!=null)
    {
        $('input#zip5').val(jQuery.url.param('Zip'));
        $('input#zip4').val(jQuery.url.param('Zip4'));
    }
    if(jQuery.url.attr('source').match(/emailsignup/i)!=null)
    {
        $('input[id*=fname]').val(jQuery.url.param('firstname'));
        $('input[id*=lname]').val(jQuery.url.param('lastname'));
    }
    var formID = jQuery.url.param('ID');
    if(formID == '464')
    {
        var emailBox = $('input[id*=EmailControl]');
        var fnBox = $('#ctl00_ctl09_ctl03_MyText');
        var lnBox = $('#ctl00_ctl09_ctl04_MyText');
        var email = jQuery.url.param('email');
        if (email!=null)
        {
            emailBox.val(email.replace(/%40/,"@"));
            if(emailBox.val() != '')
            {
                //emailBox.parent().hide();
            }    
        }
        var ln = jQuery.url.param('lastname');
        if(ln!=null)
        {           
            lnBox.val(ln.replace(/\+/," "));
            if(lnBox.val()!='')
            {
                //lnBox.parent().hide();
            }
        }
        var fn = jQuery.url.param('firstname');
        if(fn!=null)
        {
            fnBox.val(fn.replace(/\+/," "));
            if(fnBox.val()!='')
            {
                //fnBox.parent().hide();
            }
        }
    }
    //var infCode = $('.formRadio:eq(1) tr').html();
    //$('formRadio:eq(1)').html(infCode);
    //$('.formRadio:eq(1) td').wrap('<tr>');
    
}

function RecolorLinks()
{
    $('a[style*=blue]').css('color','#2675B8');
}