// Allows console to alert in IE
if( !console ) { var console = { log: function(msg) { alert(msg); } } }

$(window).bind('load', function() {
    var preload = new Array();
    $(".hover").each(function() {
        s = $(this).attr("src").replace(/\.(.+)$/i, "_on.$1");
        preload.push(s)
    });
    var img = document.createElement('img');
    $(img).bind('load', function() {
        if(preload[0]) {
            this.src = preload.shift();
        }
    }).trigger('load');
});

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

	var navCallOut, html, html1, html2, html3, html4, html5, footerCallout;
	function changeRgtNav(navCallOut) {
		if(navCallOut == '0') {
			html = "<a href=\"/comparisonTool.php?nav=0&tool=ct\" name=\"&lid=genx_comparisonTool\">";
			html += "	<img src=\"/img/img.comparisonTool.gif\" alt=\"Comparison Tool\" height=\"156\" width=\"194\" />";
			html += "</a>";
			html += "<div class=\"calculaterMain\">";
			html += "	<img src=\"/img/makingyourmoney.gif\" alt=\"making money\" title=\"Making your money work for you:\" />";
			html += "	<p class=\"hid\">With compounding, the money you earn also earns money. To see it work, enter an amount and how long you\"d like to let it grow.</p>";
			html += "	<div class=\"compoundContent\">";
			html += "		<p>Enter any dollar amount:</p>";
			html += "		<span>$</span>";
			html += "		<input type=\"text\" id=\"compound_amount\" />";
			html += "		<p>Enter how many years:</p>&nbsp;&nbsp;";
			html += "		<input type=\"text\" id=\"compound_year\" />";
			html += "		<a name=\"&lid=genx_compound_calc\" href=\"javascript: compoundCalc()\">";
			html += "			<img width=\"83\" height=\"20\" class=\"pointer hover\" alt=\"Calculate\" src=\"img/icons/btn.calculate.gif\"/>";
			html += "		</a>";
			html += "		<span id=\"error_field\"></span>";
			html += "		<p class=\"byTime\">By that time, you could have:</p>";
			html += "		<span>$</span>";
			html += "		<input type=\"text\" id=\"compound_total\" />";
			html += "		<span class=\"star\">*</span>";
			html += "	</div>";
			html += "</div>";
			document.getElementById('rgtContainerBox').innerHTML = html;
			//$('div.rgtContent').append(html);
		}
		if(navCallOut == '1') { 
			
			html = "<div id=\"flashcontentTestimonials\" class=\"testimonials\"></div>";
			html += "<a href=\"/comparisonTool.php?nav=0&tool=ct\" name=\"&lid=genx_comparisonTool\"><img src=\"/img/img.comparisonTool.gif\" alt=\"Comparison Tool\" style=\"margin-top:10px\" /></a>";
			document.getElementById('rgtContainerBox').innerHTML = html;
			onloadset = true;
			window.onload = function() {
				letsLoadTheRightWay();
			
				var so = new SWFObject('/video_banner.swf', 'video_banner', '194', '225', '8', '#336699');
				so.addParam('quality', 'high');
				so.addParam('wmode', 'transparent');
				so.addParam('salign', 't');
				so.write('flashcontentTestimonials');
					
				so = new SWFObject("genx_index.swf", "genx_index", "749", "444", "8", "#336699");
				so.addParam("allowScriptAccess", "always");
				so.addParam("quality", "high");
				so.addParam("wmode", "transparent");
				so.addParam("salign", "t");
				so.addVariable("bSkip", skipVideo());
				so.addVariable("section", window.location.search.substring(1).split("flid=")[1]);
				so.addVariable("py", getRate("getInfo"));
				so.write("flashcontent"); 
			}
		}
		if(navCallOut == '2') { 
			
			html = "<div id=\"flashcontentTestimonials\" class=\"testimonials\"></div>";
			document.getElementById('rgtContainerBox').innerHTML = html;
			onloadset = true;
			window.onload = function() {
				letsLoadTheRightWay();
			
				var so = new SWFObject('/video_banner.swf', 'video_banner', '194', '225', '8', '#336699');
				so.addParam('quality', 'high');
				so.addParam('wmode', 'transparent');
				so.addParam('salign', 't');
				so.write('flashcontentTestimonials');
			}
		}
	}


	function changeFooter(footerCallout){
		if(footerCallout == '0'){ 
				$("p#calculatorDisclosure").remove();
				html1 = "<p id='calculatorDisclosure'>*Based on hypothetical rate of return of 8%. This calculation does not include the effects of taxes, management fees or expenses.  This hypothetical example of compounding growth is for illustrative purposes only and is in no way to be considered indicative of any guaranteed performance an investor can expect to achieve. </p>";
				$(html1).insertBefore(".brokerage_disclaimer");
				$('p#wcyFooter').replaceWith(html1);
		} 
		if(footerCallout == '1'){
				$('p#calculatorDisclosure').remove();
		} 
		if(footerCallout == '2'){
				html3 = "";
				$('#globalFooter').append(html3);
				$('p#nshFooter').replaceWith(html3);
				$('p#calculatorDisclosure').replaceWith('');
		} 
		if(footerCallout == '3'){
				$('p#calculatorDisclosure').remove();
		} 
		if(footerCallout == '4'){
				html5 = "<p><strong>Mutual fund investment values will fluctuate, and shares, when redeemed, may be worth more or less than original cost.</strong></p>";
        			html5 += "<p><strong><em>Investors should consider carefully information contained in the prospectus, including investment objectives, risks, charges, and expenses.  You can request a prospectus by calling Schwab at 800-435-4000. Please read the prospectus carefully before investing.</em></strong></p>";
				$('div#default_disclaimer').remove();
				$(html5).insertBefore("p.txt");
		} 
	}


function letsLoadTheRightWay() {
	//check browser width from resolution less then 800
	var browserWidthCheck = $(window).width();
	if (browserWidthCheck <= 800) { $("#index #main").css("margin-left","29px");}
	
					
	
	//console.log(activeNav);
	$(this).find('body#index').each(function(i, ele){
		if(i == 0){
			
			
		}
												  });

	
	//general hovers 
    $(".hover").each(function() {
        if ($(this).attr("src").match(/_on\.(.+)$/i)) {
            $(this).removeClass("hover");
        }
    });
    $(".hover").hover(function() {
    	r = $(this).attr("src").split("/");
    	q = r[r.length -1];
        q = q.replace(/\.(.+)$/i, "_on.$1");
        
        s = "";
        for(i = 0; i< r.length - 1; i++) {
        	s = s + r[i] + "/";
        }
        s = s + q;
        $(this).attr("src", s);
    }, function() {
        s = $(this).attr("src").replace(/_on\.(.+)$/i, ".$1");
        $(this).attr("src", s);
    });
	
	//page height
	var containerHeight = $(".sectionDetail .containerColumn").height();
	var mainColHeight = $(".int .mainColunm").height();

	if(containerHeight <= 769) {
		$(".sectionDetail .content .rgtnav .rgtContent").css("padding-bottom","115px");
	}

	var mainColHeightFix = (mainColHeight+195);
	setTimeout( function() { 
				 if(mainColHeight <= 856) {  $(".int .mainColunm").css('height', mainColHeightFix+'px'); 
				 $(".int .rgtColunm").css('height', mainColHeightFix+'px'); } 
				 else {
				 $(".int .rgtColunm").css('height', mainColHeight+'px'); }		 
				 }, 3 );


}//main data

window.onload = function() {
	letsLoadTheRightWay();
}
