﻿$(document).ready(function(){
	hideFeature();
	iWantTo();
	$('.iWantTo a').click(function() {
		iWantToToo();
	});
 	tocCol();
 	naWrapper();
 	praccordion();
 	colHeights();
});

function FixRibbonAndWorkspaceDimensions(){
  ULSxSy:;
  g_frl = true;
  var elmRibbon = GetCachedElement("s4-ribbonrow");
  var elmWorkspace = GetCachedElement("s4-workspace");
  var elmTitleArea = GetCachedElement("s4-titlerow");
  var elmBodyTable = GetCachedElement("s4-bodyContainer");
  if(!elmRibbon || !elmWorkspace || !elmBodyTable){
    return;
  }
  if (!g_setWidthInited){
    var setWidth = true;
    if (elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
      setWidth = false;
    g_setWidth = setWidth;
    g_setWidthInited = true;
  }
  else{
    var setWidth = g_setWidth;
  }
  var baseRibbonHeight = RibbonIsMinimized() ? 44 : 135;
  var ribbonHeight = baseRibbonHeight + g_wpadderHeight;
  if(GetCurrentEltStyle(elmRibbon, "visibility") == "hidden"){
    ribbonHeight = 0;
  }

  // Override default resizing behavior
  // -- adds padding to the top of the "s4-workspace" <div> if the ribbon exists and has content
  // -- allows the ribbon to be positioned using CSS instead of JavaScript (more accessible)
  // -- checks to see if the page is inside a "no-ribbon" dialog
  if(elmRibbon.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1){
    elmWorkspace.style.paddingTop = ribbonHeight + 'px';
  }
  else{
  	$('#s4-workspace').addClass('noRibbon');	
    $('#s4-ribbonrow').hide();	
}
}

function hideFeature() {
	var fHeight = $('#home-feature').height();
	if (fHeight < 100) {
		$('#feature-wrapper').hide();
	}
	else {
		$('#home-feature').height('300px');
	}
}

function tocCol() {
	var tocWidth = $('.toc-layout-main ul').width();
	if (tocWidth = '50%') {
		$('.toc-layout-main ul').width('49%');
	}
}

function naWrapper() {
	$('#na-top').parents().filter('table.s4-wpTopTable').css('background','none');
	$('#na-top').parents().filter('div.ms-WPBody').css('padding','5px 0');
}


function iWantTo() {
	$('#main-nav ul.root > li.static > ul.static').append('<li class="static dynamic-children iWantTo"><a href="#" class="static dynamic-children menu-item">I Want To</a></li>');
}

function iWantToToo() {
	var iHeight = $('iWantToWrapperInner').height();
	if($('#iWantToWrapper').hasClass('open')) {
		$('#iWantToWrapper').removeClass('open');
		$('.iWantTo').removeClass('open');
		$('#iWantToWrapper').animate({'height': '0'}, 'slow');
	}
	else {
		$('#iWantToWrapper').addClass('open');
		$('.iWantTo').addClass('open');
		$('#iWantToWrapper').animate({'height': '200px'}, 'slow');
	}
}

function colHeights() {
	var lHeight = $('#left-nav').height();
	var mHeight = $('#content-area').height();
	var rHeight = $('#right-col').height();
	var bHeight = $('#breadcrumb-nav').height();
if ($('#left-nav').is(":hidden")) {
	var lHeight = 0;
}
if ($('#right-col').is(":hidden")) {
	var rHeight = 0;
}
if (lHeight < mHeight) {
	if (mHeight < rHeight) {
		$('#left-nav').height(rHeight);
		$('#content-area').height(rHeight);
		$('#content-area-inner').height(rHeight-30);
		$('#main-col').height(rHeight-bHeight-45);
	}
	else {
		$('#left-nav').height(mHeight);
		$('#right-col').height(mHeight);
	}
}
else {
	if (lHeight > rHeight) {
		$('#content-area').height(lHeight);
		$('#content-area-inner').height(lHeight-30);
		$('#main-col').height(lHeight-bHeight-45);
		$('#right-col').height(lHeight);
	}
	else {
		$('#left-nav').height(rHeight);
		$('#content-area').height(rHeight);
		$('#content-area-inner').height(rHeight-30);
		$('#main-col').height(rHeight-bHeight-45);
	}
}
}

$(function(){
		$('a.font-size').click(function(e){
			e.preventDefault();
			var ourText = $('body');
			var currFontSize = ourText.css('fontSize');
			var finalNum = parseFloat(currFontSize, 10);
			var stringEnding = currFontSize.slice(-2);
			if(this.id == 'large') {
				finalNum *= 1.2;
			}
			else if (this.id == 'small'){
				finalNum /=1.2;
			}
			ourText.css('fontSize', finalNum + stringEnding);
		});
	});
	
function praccordion() {	
	$('.pr-groupheader').parent().parent().addClass('accordion ui-accordion ui-widget ui-helper-reset ui-accordion-icons');
	$('.pr-groupheader').prepend('<span class="ui-icon"/>');
	/*$('.accordion').accordion();*/
	$('.accordion .pr-groupheader').click(function() {
		$(this).children('.ui-icon').toggleClass('open');
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
}

