$(document).ready(function() {
	// fonst sizer control, extra elements can be controled by applyTo:
	$('#fontSizer').jfontsizer({ 
		applyTo: 'p, p a, #tabs a.intro .readMe', 
		changesmall: '1', 
		changelarge: '2',
		expire: 30 
	});
	
	// nav overlay width based on nav location
	$('.sub').each(function(index){
		var ulCount = $('ul', this).length;
		if (ulCount < 5){
			$(this).css('width', 600)	
		}
	});	
	
	
	

	// ensure tabs and analysis boxes are the same height
	var tabHeight = $('#tabs').height();
	var tabNavHeight = $('ul.tabs').height();
	var newsHeight = $('#NewsAnalysis').height();
	var panesHeight = tabHeight - tabNavHeight;	
	if (tabHeight > newsHeight){
		$('#NewsAnalysis').css('height', tabHeight);
	}	
	else{
		var dh = newsHeight - tabHeight;
		$('div.readMore').css('marginTop', dh);
	}	
	
	

	
	// Draw Multiple Colmns fo Bottom Nav	
	$('ul.column').columnize({width:210});	
	
	// table row coloring
	$('#table_portfolio tr').each(function() {
		$("tr:odd").addClass("dark");
		$("tr:even").addClass("light");
	 });	

	// add placeholder text in input fields for browsers that don't support HTML5 Placeholder attribute
	if(!Modernizr.input.placeholder){
	
		$('[placeholder]').focus(function() {
		  var input = $(this);
		  if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		  }
		}).blur(function() {
		  var input = $(this);
		  if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		  }
		}).blur();
		$('[placeholder]').parents('form').submit(function() {
		  $(this).find('[placeholder]').each(function() {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
			  input.val('');
			}
		  })
		});
	
	}	
	
	// tabs
	$('#tabs ul.tabs').tabs("div.panes > div");
	$('#overViewTabs ul.tabs').tabs("div.panes > div");		
	$('#newsfeedTabs ul.tabs').tabs("div.panes > div");	
	$('#marketChartTabs ul.tabs').tabs("div.panes > div");	
	//tab data from XML - this is for dev only	
	
	// Small Landing Landing CTA'
	// set zero right margin for every third instance
	$('.landingCTAsm:nth-child(3n)').css('margin-right', '0px');
	// my portfolio overview page
	$( "#sortable" ).sortable({
		revert: true,
		containment: 'parent',
		handle: '.drag',
		opacity: 0.7
	});
	// sorting of inner tabs. tabs need to have a uniform width
	$('#newsfeedTabs ul.tabs').sortable({
		handle: '.innerDrag',
		opacity: 0.7
	});
	$('#marketChartTabs ul.tabs').sortable({
		handle: '.innerDrag',
		opacity: 0.7
	});
	  	
	// used in Myvalueline overview page and applied to news_feed, market_charts and my_portfolio divs to toggle content using a sliding in and out effect  
	$(".groupHeading .button").each(function(index){		
		$(this).click(function() {				
			var ParentId = $(this).parent().parent().attr("id");
			var ResizeParentLi =  $("#"+ParentId).parent().attr("id");
			var LiHeight = $("#overview ul#sortable li#"+ResizeParentLi).css('height');
			$("#"+ParentId+ " .toggler").slideToggle("fast");
			
			if (LiHeight == '334px') {
				$("#overview ul#sortable li#"+ResizeParentLi).css('height', '32px')
			}
			else {
				$("#overview ul#sortable li#"+ResizeParentLi).css('height', '334px')
			}
		});			
	});	
});



