// OH CONSTANTS
var OH_WP_CONTENT     = '/wp-content',
	OH_THEME          = OH_WP_CONTENT+'/themes/OHTheme',
	OH_THEME_IMAGES	  = OH_THEME+"/assets/images",
	OH_THEME_INCLUDES = OH_THEME+"/includes",
	OH_THEME_MODULES  = OH_THEME+"/modules";

// BROWSER CHECK	
var isIE  = ($.browser.msie) ? true : false,
	isIE6 = (isIE && parseInt(($.browser.version).charAt(0)) <= 6) ? true : false,
	isIE7 = (isIE && parseInt(($.browser.version).charAt(0)) == 7) ? true : false,
	isIE8 = (isIE && parseInt(($.browser.version).charAt(0)) == 8) ? true : false;

// NAMESPACES
var P6 = {};

/*----------
 * Plugins
------------*/
(function($) {
	
	/*------------
	 * UTILITIES
	--------------*/
	/* Intended to provide the functionality of the $.extend function
	   for the object array returned from the serializeArray()
	   function. e.g., var json = frm.serializeArray(); $.extendForm(json, jsonMe.data); */
	$.extendForm = function(arr,o) {
		if(!arr || !$.isArray(arr)) { return false; }
		if(!o) { return arr; }

		$.each(o,function(i,val){
			var p = {};
			eval("$.extend(p,{name: '"+i+"', value: '"+val+"'})");
			arr.push(p);
		});
	};
	
	/*-----------------------------------
	 * ALERTS, MESSAGES, AND INDICATORS
	-------------------------------------*/
	$.fn.ajaxPreloader = function(o) {
		if (!this[0] || !this[0]){return false;}
			o = o || {};
		var target     = $(this),
			xPos       = o.xPos 	  || 0,
			yPos 	   = ($.browser.msie && o.yPosIE) ? o.yPosIE || -1 : o.yPos || -1,
			visibility = o.visibility || "hidden",
			hide       = o.hide 	  || false,
			preLoader  = o.preLoader  || "loader", // options: loaderMedium
			zIndex 	   = o.zIndex 	  || false;

		$("body").append('<p class="'+preLoader+'">...</p>');

		var cssObj = {
	        position: "absolute",
	        left: 	  (target.offset().left) + xPos,
			top:  	  (target.offset().top)  + yPos
	    };

		if (zIndex) {
			$.extend(cssObj, {"zIndex":zIndex});
		}

		$("."+preLoader).css(cssObj);

		if (hide === true) {
			target.hide();
		} else {
			target.css("visibility",visibility);
		}

		$("."+preLoader).ajaxStop(function() {
			$(this).remove();
			if (hide === true) {
				target.show();
			} else {
				target.css("visibility","visible");
			}
		});

		return this;
	};
	
	
	
	/*-----------------
	 * MODAL MADNESS
	------------------*/
	$.fn.centerOnScreen = function(){
		if(!this||!this[0]){return false};
		
		var me = $(this);
		
		function centerOnScreen(modal) {
			if (modal.css("position") == "fixed") {
				modal.css("top", ($(window).height() - (modal.outerHeight() + 25)) / 2  + "px");
			} else {
				modal.css("top", ($(window).height() - modal.outerHeight()) / 2+$(window).scrollTop()  + "px");
			}
		    modal.css("left",($(window).width()  - modal.outerWidth() ) / 2+$(window).scrollLeft() + "px");
			return modal;
		}
		
		$(window).resize(function() { centerOnScreen(me); });
		
		centerOnScreen(me);
		
		return this;
	};
	
	$.fn.lightbox = function(o){
		o = o || {};
		var modal 	= $(this),
		    coverMe = $("#coverMe"), // Be sure to style #coverMe in your css with opacity settings to your liking
		    y       = P6.OH.getWindowHeight(),
			speed	= o.speed || "fast"; // string
		
		if (!coverMe.length) {
			$("body").prepend('<div id="coverMe"></div>');
			coverMe = $("#coverMe");
		}
		
		if (isIE) {
			coverMe.height(y).width("100%").show();
		} else {
			coverMe.height(y).width("100%").fadeIn(speed);
		}
		
		
		coverMe.unbind("click");
		coverMe.click(function() {
			if (isIE) {
				$(this).hide();
				coverMe.removeClass("coverMeLightBox");
			} else {
				$(this).fadeOut(speed, function() {
					coverMe.removeClass("coverMeLightBox");
				});
			}
			modal.fadeOut(speed, function() {
				modal.remove();
			});
		});
				
		return this;
	};
	
	$.fn.createModal = function (o) {
		if(!this || !this[0]){return false;}
		o = o || {};
		
		$(this).unbind("click.createModal");
		$(this).bind("click.createModal", function() {
			o.openCallbackArgs          = o.openCallbackArgs  || {};
			o.closeCallbackArgs         = o.closeCallbackArgs || {};
			o.openCallbackArgs.trigger  = $(this);
			o.closeCallbackArgs.trigger = $(this);
			P6.OH.createModal(o);
			return false;
		});
		
		return this;
	};
	
	$.fn.createPopup = function(o) {
		if(!this || !this[0]){return false;}
		o = o || {};
		
		$(this).each(function(i, val) {
			var trigger      = $(this),
				targetId     = trigger.attr('href').split("#")[1],
				popup        = $('#'+targetId),
				popupPointer = popup.find("img.popupPointer"),
				css          = {},
				closeMeHtml  = '<a title="Close Me" class="closeMe" href="javascript:;"><img class="iconX" src="'+OH_THEME_IMAGES+'/icons/x-1.gif"/></a>',
				closeMe;
			
			trigger.unbind("click.createPopup");
		   	trigger.bind  ("click.closeMe", function() {
				return false;
			});
			
			trigger.hover(
				function () {
					if (!popup.hasClass("appendedToBody")) {
						popup.appendTo("body");				    // append the modal frame to the body
						popup = $("body div.modal:last-child"); // newly created modal will always be the last child of the body
						popup.addClass("appendedToBody");
						popup.find(">div.modalWrap").prepend(closeMeHtml);
						closeMe = popup.find("a.closeMe"),
						
						closeMe.unbind("click.createPopup");
					   	closeMe.bind  ("click.closeMe", function() {
							popup.hide();
							window.clearTimeout(popupTO);
						});
					}
					
					css = P6.OH.Popup.getCoords(trigger);
					popup.css(css);
					popup.show();
					P6.OH.Popup.positionLeftOrRight(popup, popupPointer, css.left);
				}, 
				function () {
					popupTO = setTimeout(function() {
						popup.hide();
						popupPointer.removeClass("popupPointer2");
						popupPointer.attr("src", OH_THEME_IMAGES+"/icons/pointer-left-1.png");
					}, 100);
				}
			);
			
			popup.hover(
				function () {
					window.clearTimeout(popupTO);
				}, 
				function () {
					popupTO = setTimeout(function() {
						popup.hide();
						popupPointer.removeClass("popupPointer2");
						popupPointer.attr("src", OH_THEME_IMAGES+"/icons/pointer-left-1.png");
					}, 100);
				}
			);
			
		});
		
		return this;
	};
	
})(jQuery);

/*-----------------
 * NEW OH OBJECT
------------------*/
P6.OH = {	
	"getWindowHeight":function() {
		var y = window.innerHeight||document.body.clientHeight||document.documentElement.clientHeight;
		if (y < $(window).height()) {
			y = $(window).height();
		}
		return (document.height>y) ? document.height : y;
	},
	"createModal":function(o) {
		o = o || {};
		
		// modal options, m = abbreviation for modal
		var file   		      = o.file  	    	|| false,  // string
			mClass 		      = o.modalClass    	|| "",     // string
			mId    		      = o.modalId       	|| "",     // string
			openCallback      = o.openCallback  	|| false,  // function
			openCallbackArgs  = o.openCallbackArgs  || {},     // object
			closeCallback 	  = o.closeCallback 	|| false,  // function
			closeCallbackArgs = o.closeCallbackArgs || {},     // object
			lightbox 	  	  = o.lightbox          || false,  // boolean
			speed		  	  = o.speed		        || "fast"; // string
			
		var modal   = '<div class="modal '+mClass+'" id="'+mId+'"><div class="modalWrap"></div></div>',
			closeMe = '<a title="Close Me" class="closeMe" href="javascript:;"><img class="iconX" src="'+OH_THEME_IMAGES+'/icons/x-1.gif"/></a>',
			coverMe;
		
		$(modal).appendTo("body");				// append the modal frame to the body
		modal = $("body div.modal:last-child"); // newly created modal will always be the last child of the body
		
		// load file/content into the modal frame
		modal.find(">div.modalWrap").load(file, function() {
			$(this).prepend(closeMe);
			modal.lightbox({"speed":speed});
			coverMe = $("#coverMe");
			
			if (lightbox) {
				coverMe.addClass("coverMeLightBox");
			}
			
			modal.centerOnScreen();
			modal.fadeIn(speed);

			modal.find(".closeMe").click(function() {
				if (closeCallback) {
					closeCallbackArgs.closer = $(this);
					closeCallbackArgs.modal  = modal;
					closeCallback(closeCallbackArgs);
				}
				modal.fadeOut(speed, function() {
					modal.remove();
				});
				if (isIE) {
					coverMe.hide();
					coverMe.removeClass("coverMeLightBox");
				} else {
					coverMe.fadeOut(speed, function() {
						coverMe.removeClass("coverMeLightBox");
					});
				}
			});
			
			if (openCallback) {
				openCallbackArgs.modal = modal;
				openCallback(openCallbackArgs);
			}
		});
		
	    return this;
	},
	
	"Popup": {
		"getCoords":function(trigger) {
			var triggerPos = trigger.offset(),
				triggerX   = triggerPos.left,
				triggerY   = triggerPos.top,
				triggerW   = trigger.width(),
				triggerH   = trigger.height(),
				popupX     = triggerX+triggerW+10,
				popupY     = triggerY-73,
				css        = {left:popupX, top:popupY};
			return css;
		},
		"positionLeftOrRight":function(popup, popupPointer, popupLeft) {
			var winW      = $(window).width(),
			    popupW    = popup.outerWidth(),
				popupTot  = popupW + popupLeft;
			
			if (popupTot >= winW) {
				popup.css({"left":(popupLeft - (popupW+45))});
				popupPointer.addClass("popupPointer2");
				popupPointer.attr("src", OH_THEME_IMAGES+"/icons/pointer-right-1.png");
			}
		}
	},
	
	"Array": {
		"getIndexByValue": function(needle, haystack) {
			var index = -1
			for (i=0;i<haystack.length;i++) {
				if(haystack[i] == needle) {
					index = i;
					break;
				}
			}
			return index;
		},
		"sort":function(a, b) {
			return (a - b) // causes an array to be sorted numerically and ascending
		}
	},
	
	"Numbers": {
		"isEven":function(number) {
			return (number%2 == 0) ? true : false;
		},
		"random":function() {
			return Math.floor(Math.random()*11);
		}
	},
	
	"getProtocol":function() {
		return (document.location.protocol.indexOf('https') != -1) ? 'https' : 'http';
	},
	
	"loadCrayEgg":function() {
		var protocol = this.getProtocol();
		document.write('<script type="text/javascript" src="'+protocol+'://dnn506yrbagrg.cloudfront.net/pages/scripts/0011/0293.js"></script>');
	},
	
	"loadAdServicesConversion":function() {
		var protocol = this.getProtocol();
		
		// global vars
		google_conversion_id       = 1040843540;
		google_conversion_language = "en";
		google_conversion_format   = "3";
		google_conversion_color    = "666666";
		google_conversion_label    = "iJiuCIqrswEQlIao8AM";
		google_conversion_value    = 0;
		
		document.write('<script type="text/javascript" src="'+protocol+'://www.googleadservices.com/pagead/conversion.js"></script>');
	},
	
	"loadBrightcove":function() {
		var protocol = this.getProtocol();
		
		var urls = ['://admin.brightcove.com/js/BrightcoveExperiences.js',
		            '://admin.brightcove.com/js/APIModules_all.js'];
		
		for (var i in urls) {
			if (urls.hasOwnProperty(i)) {
				var x   = document.createElement('script');
				x.type  = 'text/javascript';
				x.async = true;
			    x.src   = protocol+urls[i];
			    var s   = document.getElementsByTagName('script')[0];
				s.parentNode.insertBefore(x, s);
			}
		}
	}
}

/*--------------
 * OH GLOBALS
----------------*/
P6.OH.Auth = {
	// properties
	authToken:         null,
	accountId:         null,
	keepAliveInterval: null,
	isAlive:           null,
	
	// methods
	init: function() {
		var me = P6.OH.Auth;
		me.keepAlive();
		
		$(document).unbind("click.authKeepAlive");
		$(document).bind("click.authKeepAlive", function(e) {
			me.isAliveCheck();
		});
	},

	keepAlive: function() {
		this.keepAliveInterval = window.setInterval(this.processKeepAlive, 60000); // 60000, 60 seconds
		this.isAliveCheck();
	},
	
	processKeepAlive: function() {
		var me = P6.OH.Auth;
		var act = "<EZMessage action='auth.keepAlive'><data>";
				act += "<authToken>"+me.authToken+"</authToken>";
				act += "<account>"+me.accountId+"</account>";
			act += "</data></EZMessage>";
		
		getXML(act, function() { });
	},
	
	isAliveCheck: function() {
		window.clearTimeout(this.isAlive);
		this.isAlive = window.setTimeout(this.processLogout, 1800000); // 1800000, 30 minutes
	},

	processLogout: function() {
		var me = P6.OH.Auth;
		var act = "<EZMessage action='auth.logout'><data>";
				act += "<authToken>"+me.authToken+"</authToken>";
			act += "</data></EZMessage>";

		getXML(act, function() {
			me.authToken = null;
			me.accountId = null;
			window.clearTimeout(me.keepAliveInterval);
			window.location.reload(true);
		});
	}
}


/*-------------
 * OH ROUTER
---------------*/
P6.OH.Router = {
	"constructor":function() {
		this.common();
		var	area = $("body").attr("id");
		if (typeof this[area] == "function") {
			this[area]();
		}
	},
	"destructor": function() {
		
	},
	"init": function() {
		this.constructor();
		this.destructor();
	},
	"common": function() {
		this.coreuiConcatMin();
		$('.turnIntoLink').turnIntoLink();
		P6.OH.loadBrightcove();
	},
	
	// AREAS, the body id
	"Home": function() {
		$('#Home').launchVideoFromQuerystring( "emailVid" ); /* might be old sauce -- launch brightcove video from querystring */
		$(".ohTvLink").bindShowLightbox( 11892205001 , "ohtv" ); /* in use */
	},
	"Category": function() {
		
	},
	"Single": function() {
		//this.Sections.init("commentsWrap");
	},
	
	"Disclaimers": function() {
		var hash = window.location.hash.split("#")[1];
		$('a[name="'+hash+'"]').parents('dd:eq(0)').addClass('sel');
		$("div.disclaimers-pages").floatingMenu($('#disclaimers'), $('#Footer'), 105);
	},
	
	"Tour": function() {
		var tourFrame = document.getElementById("tourVideo");
		tourFrame.contentWindow.location.href = "/video/tour/tour.jsp";
	},
	
	"LandingPg3": function() {
		$('a.aaPromoDetails').createModal({"file":OH_THEME_INCLUDES+"/info/aa/promo-details.php", "modalClass":"aaMilesModal"});
		$('a.aaTerms').createModal({"file":OH_THEME_INCLUDES+"/info/aa/terms-and-conditions.php", "modalClass":"aaMilesModal"});
		
		$("form[name='aadvantageForm']").bind("submit.submitForm", function() {
			var form = $(this),
				formWrap = form.parents('.formWrap:eq(0)'),
				errors   = formWrap.find('.errors'),
				username = form.find("input[name='login.userName']").val(),
				password = form.find("input[name='login.password']").val(),
				o        = { username:username, password:password };
				
			doLogin(o);
			return false;
		});
		
		function doLogin(o) {
			var act = "<EZMessage action='auth.login'><data>";
					act += "<userName>"+replaceSpecials(o.username)+"</userName>";
					act += "<password>"+replaceSpecials(o.password)+"</password>";
				act += "</data>";
			act += "</EZMessage>";
			
			getXML(act, processLogin);
		}
		
		function doAddFlyerMilesNumber(o) {
			
			var flyerMilesNumber = null,
			    accounts         = [],
				accountsXml      = "";
			
			for (var i=0; i<o.length; i++) {
				if (o[i].name == "flyerMilesNumber") {
					flyerMilesNumber = o[i].value;
				}
			}
			
			for (var i=0; i<o.length; i++) {
				if (o[i].name == "accounts") {
					accounts.push(o[i].value);
				}
			}
			
			for (var i=0; i<accounts.length; i++) {
				accountsXml += "<account>"+accounts[i]+"</account>";
			}
			
			var act = "<EZMessage action='marketing.add.flyer.miles.num'><data>";
					act += "<authToken>"+P6.OH.Auth.authToken+"</authToken>";
					act += "<flyerMilesNumber>"+flyerMilesNumber+"</flyerMilesNumber>";
					act += "<accounts>";
						act += accountsXml;
					act += "</accounts>";
				act += "</data>";
			act += "</EZMessage>";
			
			getXML(act, processAddFlyerMilesNumber);
		}
		
		function getAccounts() {
			var act = "<EZMessage action='filtered.account.list'><data>";
					act += "<authToken>"+P6.OH.Auth.authToken+"</authToken>";
				act += "</data>";
			act += "</EZMessage>";
			
			getXML(act, listAccounts);
		}
		
		function listAccounts(xml) {
			var accounts   = btn(xml, "accounts"),
				accountIds = btn(xml, "accountId"),
				form       = $("form[name='aadvantageForm']"),
				formWrap   = form.parents('.formWrap:eq(0)'),
				errors     = formWrap.find('.errors'),
				msg        = formWrap.find('.msg'),
				select     = form.find("select[name='accounts']"),
				options    = '',
				acctId     = null,
				acctName   = null;
			
			if (accounts.length) {
				for (var i=0; i<accountIds.length; i++) {
					acctId   = sNode(btn(accounts[0], "accountId")[i]);
					acctName = sNode(btn(accounts[0], "accountName")[i]);
					if (i == 0) {
						P6.OH.Auth.accountId = acctId;
					}
					options += '<option value="'+acctId+'">'+acctName+'</option>';
				}
			}
			/*
			for (var i=0; i<accounts.length; i++) {
				acctId   = sNode(btn(accounts[i], "accountId")[0]);
				acctName = sNode(btn(accounts[i], "accountName")[0]);
				if (i == 0) {
					P6.OH.Auth.accountId = acctId;
				} 
				options += '<option value="'+acctId+'">'+acctName+'</option>';
			}
			*/
			
			msg.text("Select the account(s) on which you would like to earn miles and then enter your AAdvantage® number.");
			select.html(options);
			
			form.unbind("submit.submitForm");
			form.bind("submit.submitForm", function() {
				var o = form.serializeArray();

				doAddFlyerMilesNumber(o);
				return false;
			});
		}
		
		function processAddFlyerMilesNumber(xml){
		    var errors           = btn(xml, "errors"),
				username         = btn(xml, "userName"),
				flyerMilesNumber = btn(xml, "flyerMilesNumber"),
				form             = $("form[name='aadvantageForm']"),
				formWrap         = form.parents('.formWrap:eq(0)'),
				errorWrap        = formWrap.find('.errors'),
				step3            = OH_THEME_INCLUDES+"/forms/aa/promo-congrats.php",
				errorMsg         = null,
				errorText        = "",
				actionError;
		    
			if (errors.length > 0) {
				for (var i=0; i<errors.length; i++) {
					actionError = btn(errors[i], "action");
					accessError = btn(errors[i], "access");
					if (accessError.length) {
						errorMsg = sNode(accessError[0]);
					} else {
						errorMsg = (actionError.length) ? sNode(actionError[0]) : sNode(btn(errors[i], "error")[0]);
					}
					errorText += "<em>"+errorMsg+"</em>";
				}
				errorWrap.html(errorText);
				errorWrap.fadeIn();
			} else {
				errorWrap.hide().empty();
				formWrap.load(step3, function() {
					$("#ohAAUsername").text(sNode(username[0]));
					$("#ohAANumber").text(sNode(flyerMilesNumber[0]));
				});
			}
		}
		
		function processLogin(xml){
		    var errors   = btn(xml, "errors"),
				holder   = btn(xml, "access"),
				auth     = btn(xml, "authToken"),
				tHolder   = null,
				tAuth     = null,
				form      = $("form[name='aadvantageForm']"),
				formWrap  = form.parents('.formWrap:eq(0)'),
				errorWrap = formWrap.find('.errors'),
				step2     = OH_THEME_INCLUDES+"/forms/aa/promo-step-2.php";
				
			//form.find('input[type="image"]').ajaxPreloader();
		    
			if (errors.length > 0) {
				
				errorWrap.html("<em>invalid username and password</em>");
				errorWrap.fadeIn();
				
			} else if (holder.length > 0) {
				tHolder = sNode(holder[0]);
				tAuth   = sNode(auth[0]);
				
				if (tHolder == "granted") {
					P6.OH.Auth.authToken = tAuth;
					errorWrap.hide().empty();
					
					form.load(step2, function() {
						$("a.popupTrigger").createPopup();
						
						// STEP 2
						getAccounts();
						
					});
					
					P6.OH.Auth.init();
					
		        } else {
			
					errorWrap.html("<em>login failed</em>");
					errorWrap.fadeIn();
					
				}
			}
		}
	},
	
	// SECTIONS - html element id
	"Sections": {
		"init": function(id) {
			var	section = $("#"+id);
			if (!section.length) { return false; }
			
			if (typeof this[id] == "function") {
				this[id]();
			}
		},
		"commentsWrap": function() {
				
		}
	},
	
	"coreuiConcatMin": function() {
		/* progressively enhance links for all pages that will not work without JavaScript (except
        /contact_us/, which also includes important info re: address, phone, etc.) */

        //TODO - decouple style classes from behavior classes for login, help and referAFriend
		$( '.openAnAccount' ).openAnAccount();
		$( '#secureLogin, .secureLogin' ).secureLogin();
		$( '.liveHelp' ).liveHelp();
		$( '.referAFriend' ).referAFriend();
		
		/* un-hide progressively enhanced elements */
		$( '.enhanced' ).css( "visibility", "visible" );
        $( '#mainNav li a' ).toggleHover();

		/* highlight the current page in top nav or bottom sub-nav */
		oh.marketingSite.utils.styleNav();

		/* IE fixes - first-child, last-child */	
		$( 'ul.piped, dl.piped' ).firstAndLastChild();
		
		/* PARTNER PAGE: display alerts before taking people off-site */
		
		// TODO - progressively enhance these so the disclaimer shows even if JS is disabled
		$( '.confirmAndGoToPage' ).confirmAndGoToPage();
		$( '.confirmAndGoToONN' ).confirmAndGoToONN();
        $('.confirmAndGoToONNPremium').confirmAndGoToONN('http://www.onn.tv/premium/');

        /* RATES PAGE: bind clicks */
		$( "#rates #optionRates.fees,"
		  +"#rates #stockRates.fees,"
		  +"#rates #spreadRates.fees").toggleHoverAndBindClick( '/rates/fees/').toggleSiblingHover('#goToRates a');

	    /* RATES FAQ PAGE: bind clicks */
		$( "#pricingLandingPage #optionRates.fees,"
		  +"#pricingLandingPage #stockRates.fees,"
		  +"#pricingLandingPage #spreadRates.fees").toggleHoverAndBindClick( '/rates/').toggleSiblingHover('#goToRates a');
	
		/* WHY PAGE: bind clicks */
		$( '#why #tVirtual' ).toggleHoverAndBindClick( '/virtual/' );
		$( '#why #tPromo' ).toggleHoverAndBindClick( '/promotions/' );
		
		$( "#why #optionRates.fees,"
		  +"#why #stockRates.fees,"
		  +"#why #spreadRates.fees").toggleHoverAndBindClick( '/rates/').toggleSiblingHover('#goToRates a');
	
		$('img.investmentCoaching').toggleHoverAndBindClick( '/education/investment-coaching/');

		/* TOUR PAGE: bind clicks */
		$( '#tour #tVirtual' ).toggleHoverAndBindClick( '/virtual/' );
		$( '#tour #tFree' ).toggleHoverAndBindClick( '/landing/affiliate100' );

        /* PROMOTIONS PAGE : bind clicks */
		$( '#promotions #tVirtual' ).toggleHoverAndBindClick( '/virtual/' );
		$( '#promotions  #tSecure' ).toggleHoverAndBindClick( '/why/' );
		
		/* Trading Pages */
		$( '#option-trading #tVirtual, #stock-trading #tVirtual' ).toggleHoverAndBindClick( '/virtual/' );
		$( '#option-trading #tPromo, #stock-trading #tPromo' ).toggleHoverAndBindClick( '/promotions/' );
		$( "#option-trading #optionRates.fees, #option-trading #stockRates.fees,"
		  +"#option-trading #spreadRates.fees, #stock-trading #optionRates.fees,"
		  +"#stock-trading #stockRates.fees, #stock-trading #spreadRates.fees").toggleHoverAndBindClick( '/rates/').toggleSiblingHover('#goToRates a');	

        /* FAQ PAGE: show/hide */
		$( '#faq' ).toggleFAQ();
		
		/* Risk section: navigation dropdown */
		$( '#riskDropdown' ).riskNavigator();
		oh.marketingSite.utils.playTourVideo();
		
		/* LIGHTBOX */
		$( ".stability" ).toggleSiblingHover("#stabilityCta .watchNow, #stabilityCta .watchNow span").bindShowLightbox(12084686001 , "stability");
		$( ".media_close_window" ).bindHideLightbox();
	}
}

/*-----------------
 * WHATEVER DUDE!
-------------------*/
$(function(){ P6.OH.Router.init(); });

