var Site = {
	init: function() {
	    Site.FastIsi.init();
        Site.TextSize.init({
            cookieName: 'textSize',
            textTarget: 'contentMain',
            trackId: 'textTrack',
            knobId: 'textKnob',
            container: 'siteUtil'
        });
        //new SmoothScroll({ duration: 500 });
	},
	
    TextSize: {
        cName: null,
        opts: {
            duration: 60
        },
        myScale: null,
        els: null,
        curr: 0,
		sizes: [0.75, 0.85, 1.0, 1.15, 1.25, 1.35, 1.45],
		
        init: function(obj) {
            if (!$(obj.trackId)) return;

            this.textTarget = $(obj.textTarget) || $(document.body);
            this.cName = obj.cookieName;

            //if doesnt exist, set to 0
            if (!$chk(Cookie.read(this.cName))) Cookie.write(this.cName, 0, this.opts);

            this.myScale = parseInt(Cookie.read(this.cName)) || 0;
            this.slider = new Slider($(obj.trackId), $(obj.knobId), {
				snap: true,
                steps: 7,
                onTick: function(pos) {                    
					this.knob.setStyle('left', this.step * 7);
                }
            });

            this.slider.knob.addEvents({
                'mousedown': function() {
                    this.addClass('on');
                },
                'mouseup': function() {
                    this.removeClass('on');
                }
            });			
            this.processScale(this.myScale);
            this.slider.set(this.myScale.toInt());

            this.slider.addEvents({
                'complete': function(step) {
                    this.knob.removeClass('on');
                },
                'change': function(step) {                    
					this.processScale(step);
					this.setCookie(step);
					s.events = 'event6';
					s.tl(this, 'o', 'Change Text Size');
                }.bind(this)
            });

        },
        setCookie: function(index) {
            this.myScale = index
            Cookie.write(this.cName, index, this.opts)
        },
        getSize: function(index) {					
			return this.sizes[index];
        },
        processScale: function(index) {
            this.textTarget.setStyle('font-size', this.getSize(index) + "em");
        }
    },
    
	FastIsi: {
		init: function() {
			this.navs = $$("#fastNav .item");
			this.contents = $$("#fastContent .contentItem");
			
			if (this.navs.length != this.contents.length) return;
			
			this.navs.each(function(el, i) {
				el.getElement("a").set("href", "javascript:void(0);");
				el.addEvent("click", function() {
					this.show(i);
				}.bind(this));
				
				if (i == 0) el.addClass("active");
			}, this);
			
			this.contents.each(function(el, i) {
				if (i != 0) el.setStyle("display", "none");
			});
			
			this.pre = 0;
			this.curr = 0;
		},
		
		show: function(index) {
			if (index == this.curr) return;					
			
			this.navs[this.curr].removeClass("active");
			this.contents[this.curr].setStyle("display", "none");
			
			this.navs[this.pre].removeClass("preActive");
			
			var pre = (index == 0) ? 0 : index - 1;
			
			this.navs[index].addClass("active");
			this.contents[index].setStyle("display", "");
			this.navs[pre].addClass("preActive");
			
			
			this.pre = pre;
			this.curr = index;
		}
	},
	ObcRegistration: {
        init: function() {
            Site.RegFields = new FieldsManager("obcRegForm", {
                labelSelector: ".longField label",
                inputSelector: ".longField input[type=text]"
            });
        }
    }
};


window.addEvent("domready", function() {
	Site.init();
});

// Query string gatherer
function $get(key,url){
  if(arguments.length < 2) url =location.href;
  if(arguments.length > 0 && key != ""){
	  if(key == "#"){
		  var regex = new RegExp("[#]([^$]*)");
	  } else if(key == "?"){
		  var regex = new RegExp("[?]([^#$]*)");
	  } else {
		  var regex = new RegExp("[?&]"+key+"=([^&#]*)");
	  }
	  var results = regex.exec(url);
	  return (results == null )? "" : results[1];
  } else {
	  url = url.split("?");
	  var results = {};
		  if(url.length > 1){
			  url = url[1].split("#");
			  if(url.length > 1) results["hash"] = url[1];
			  url[0].split("&").each(function(item,index){
				  item = item.split("=");
				  results[item[0]] = item[1];
			  });
		  }
	  return results;
  }
}	  

function MM_showHideLayers() { //v6.0
    var i, p, v, obj, args = MM_showHideLayers.arguments;
    for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null) {
        v = args[i + 2];
        if (obj.style) { obj = obj.style; v = (v == 'show') ? 'visible' : (v == 'hide') ? 'hidden' : v; }
        obj.visibility = v;
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_openBrWindow_(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

function openSendFriend() {
    window.open(applicationRoot + '/send-to-friend.aspx?title=' + document.title + '&url=' + encodeURI(window.location.href), null, 'scrollbars=no,resizable=no,width=400,height=400');
}


function goToRequested(url) {
    window.open(url, "_newWin", 'toolbar,menubar,scrollbars,resizable,location');
    window.close();
}

function openDisclaimer(url) {
    MM_openBrWindow_(applicationRoot + '/Exitsite.aspx?url=' + url, 'winDisclaimer', 'width=370,height=342');
}

function calcEnglish(form, feet, inches, pounds) {
    var msg = "";
    
    if ((!inches) || isNaN(inches)) {
        inches = 0;
    }

    if (((inches <= 0) || isNaN(inches)) && ((feet <= 0) || isNaN(feet))) {
        msg += 'Please enter your height\n';
    }       

    if ((pounds <= 0) || isNaN(pounds)) {
        msg += 'Please enter your weight';        
    }
    
    if (msg != "")
    {
        alert(msg);
        return false;
    }

    TotalInches = eval(feet * 12) + eval(inches)
    form.calcval.value = Math.round(pounds * 703 * 10 / TotalInches / TotalInches) / 10
    return false;
}


