﻿/*
Edexcel Core JS developed by Creative SharePoint
Created: 1/07/2011
Developer: David Hendry
*/

function ProcessImn(){}

// Initiate the Left Navigation Expandable Menus
$(document).ready(function() {

   // TweakPageTitle();
     
    createNavigationSelectedState();
    addNavLearnersClass();
     
    //Attach the click to the dropdown arrows
  	  $(".dropdown a").click($toggleLeftNavSection);
	
	//Attach the click to the Expand/Collapse Header
	 $(".cBody").hide();
	 $(".cHeader").click(function()
  		{
  		   $(this).next(".cBody").slideToggle(0);
  		});
	
    $(".edx-LeftNav li.AspNet-Menu-Selected").each(function() {
    var current = $(this);
    current.parent('ul').each(function(){
    $(this).show();
    var thebuttonforthisgroup = $(this).parent("li").find("> .dropdown > a");
    $toggleLeftNavSectionButton.call(thebuttonforthisgroup, null);

      });
      
      $(".AspNet-Menu-WithChildren.AspNet-Menu-ChildSelected > ul").show();
      $(".AspNet-Menu-WithChildren.AspNet-Menu-Selected > ul").show();
    
    });    

     FindLeftNavParentLI();
	});


function FindLeftNavParentLI()
{
	var jqo= $(".collapse");
    jqo.parent().parent().addClass("edx-SecondChildLI");
}

function $toggleLeftNavSection(){
	var jqo= $(this);
	$toggleLeftNavSectionButton.call(this);
	
	//Find the UL of the dropdown element and use the SlideToggle Method
    jqo.parent().parent().find("> ul").slideToggle(250);
}

function $toggleLeftNavSectionButton(){
	var jqo= $(this);
    if (jqo.hasClass("expand")){
    	jqo.removeClass("expand").addClass("collapse");
    }
    else if (jqo.hasClass("collapse")){
    	jqo.removeClass("collapse").addClass("expand");
    }
}

function bookmarkthis() {

    var title = document.getElementsByTagName("title")[0].text;
    var url = location.href;


    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {

        window.external.AddFavorite(url, title);

    } else if (navigator.appName == "Netscape") {

        window.sidebar.addPanel(title, url, "");

    } else {

        alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");

    }

}

function mailpage() {
    mail_str = "mailto:?subject= Recommended Edexcel Link";
    mail_str += "&body= " + document.title;
    mail_str += "... at: " + location.href;
    location.href = mail_str;
}


function createNavigationSelectedState()
{
	var sNavigationID = '';
	var hostname = window.location.hostname;
	var pearsonhost = 'wbl.clients.creative-sharepoint.com'; // pearsonwbl.edexcel.com
	
	sNavigationID = ( hostname == pearsonhost ) ? '#edx-SiteBarPearson' : '#edx-SiteBarEdexcel';

	var sWindowPathName = window.location.pathname;
	sWindowPathName = sWindowPathName.toLowerCase();
	
	var oSecondNavLinks = $(sNavigationID + ' ul li a');
	var sPathName = '';

	oSecondNavLinks.each(function(index) {
    	
    	sPathName = this.pathname;

    	if (sPathName.substr(0,1) != '/') {
    		sPathName = '/' + sPathName;
    	}
    	
	   	if ( sWindowPathName.indexOf(sPathName.toLowerCase()) != -1 ) {
			$(this).addClass('selected');
    	}
    	
	});
	
	if ( $(sNavigationID + ' ul li a.selected').length > 1 )
	{
		$(sNavigationID + ' ul li a.selected:not(:last)').removeClass('selected');
	}
}


function addNavLearnersClass() /*Added for the students section to add unique classes to each node*/
{
	var i = 0;
	
	$('.learnersNav UL LI').each(function() {
		var e = "edx-Learners-" + i;
		$(this).addClass(e);	
		i++;	
	});
}

