// JavaScript Document

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt)
  {
    var len = this.length;

    var from =  0;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


/* 
 This creates the dynamic menu, and will stay the same across all pages. 

Edit and add to this as you like, just remember that all .html files should go in the root directory, and that identity pages should end with "-identity.html", web with "-web.html" etc. You can preceed those with whatever you want... For example, "Jantzi-flyers-print.html" and "Jantzi-stationary-print.html" are fine.

Allowed top-level pages are:
index.html
bio.html
portfolio.html
contact.html
identity.html
print.html
web.html

*/ 

// edit the menus here, one each for IDENTITY, PRINT, and WEB
  
	var treeStructure = new Array(
	
		[["IDENTITY"],
								[{label: "Social Innovation Canada", href: "SIC-logo-identity.html"}],

								[{label: "New Paradigm",href:"np-logo-identity.html"}],							
								
								[
								   {label: "Listerine", href: "listerine-logo-identity.html"}
								],   

								[  {label: "Jantzi Research", href: "jantzi-logo-identity.html"}
								],   

								[
								   {label: "Core Insight", href: "coreinsight-logo-identity.html"}
								],
								
								[  {label: "ProAct Ideas", href: "proact-logo-identity.html"}
								], 

								[
								   {label: "American Community Gardening Assoc.", href: "acga-logo-identity.html"}
								],

								[ 
								   {label: "Katrin Leblond", href: "leblond-logo-identity.html"}
								], 

								[
								   {label: "Fairyesque", href: "fairyesque-logo-identity.html"}
								],

								[
								   {label: "Glen Peloso Interiors", href: "peloso-logo-identity.html"}
								],
								
								[
								   {label: "The Union Yoga", href: "unionyoga-logo-identity.html"}
								], 

								[
									{label: "Griipa", href: "griipa-logo-identity.html"}
								] 								
		],
		
		[["PRINT"],
								[
									{label: "Bay Street Bull", href: "bsb-cover1-print.html"}
								], 

								[
								 	{label: "C2P2", href: "c2p2-cover-print.html"}
								], 

								[
								 	{label: "TTC", href: "ttc-ad-print.html"}
								], 

								[
								   {label: "Social Innovation Canada", href: "SIC-card-print.html"}
								],

								[
								 	{label: "TDSB", href: "tdsb-cover-print.html"}
								], 

								[
								 	{label: "Nestl&eacute; Purina", href: "purina-newsletter-print.html"}
								],

								[
								 	{label: "New Paradigm", href: "np-stationery-print.html"}
								],
								
								[
								   {label: "Jantzi Research", href: "jantzi-stationary-print.html"}
								],   

								[
								 	{label: "Right To Play", href: "righttoplay-poster-print.html"}
								], 

								[
								 	{label: "ProAct Ideas", href: "proact-businesscard-print.html"}
								],

								[
								 	{label: "Glen Peloso", href: "peloso-businesscard-print.html"}
								],	
		
								[ 
								 	{label: "Katrin Leblond", href: "leblond-poster-print.html"}
								],

								[
								 	{label: "Fairyesque", href: "fairyesque-pf-print.html"}
								],

								[
								 	{label: "Regent Park Film Festival", href: "rpff-poster-print.html"}
								],

								[
								 	{label: "Soka Gokkai International", href: "sokagokkai-cover-print.html"}
								],
								
								[
									{label: "Griipa", href: "griipa-stationery-print.html"}
								] 

		],
		
		[["WEB"],
		  						[
									{label: "My-Toronto.ca", href: "myto-video-web.html"}
								],

								[
								 	{label: "Social Innovation Canada", href: "SIC-web.html"}
								],

								[
								 	{label: "The Union", href: "unionyoga-web.html"}
								],

								[
								 	{label: "Jantzi Research", href: "jantzi-web.html"}
								],	

								[
								 	{label: "Kramer Henderson", href: "kramerhenderson-web.html"}
								],

								[
								 	{label: "Griipa", href: "griipa-web.html"}
								]

		]);

// Stop editing.


								 
var tree;
function buildBranch (node, treeStructureNode) {
	for (var x=0; x<treeStructureNode.length-1; x++) {
		if (treeStructureNode[x+1].length>0) {
			newNode = new YAHOO.widget.TextNode(treeStructureNode[x+1][0], node, false);

		} else {
			newNode = new YAHOO.widget.TextNode(treeStructureNode[x+1], node, false);

		}
		buildBranch(newNode, treeStructureNode[x+1]);
	}	
}
	
function treeInit(thisTree) {

	var nodeArray = new Array();
   	tree = new YAHOO.widget.TreeView("leftnav");
   	var root = tree.getRoot();
	var i=0;
	var lastNode = root;
	for (var i=0; i<thisTree.length; i++) {
		var tmpNode = new YAHOO.widget.TextNode(thisTree[i][0], root, false);
		buildBranch(tmpNode, thisTree[i]);
    }	
   
          tree.subscribe("expand", function(node) {
			  document.getElementById('ygtvlabelel' + node.index).className="expandedNode";
              // return false; // return false to cancel the expand
           });

       tree.subscribe("collapse", function(node) {
			  document.getElementById('ygtvlabelel' + node.index).className="ygtvlabel";	   
              //alert(node.index + " was collapsed");
           });

       // Trees with TextNodes will fire an event for when the label is clicked:
       tree.subscribe("labelClick", function(node) {
              //alert(node.index + " label was clicked");
           });
   
   tree.draw();
   document.getElementById('ygtvlabelel1').className="selected";
   tree.getNodeByProperty("href", tailorPage).parent.toggle();
   if (tailorPage != tailorSection) {
   		var secondLevel = tree.getNodeByProperty("href", tailorPage).getLabelEl();

   		secondLevel.className="subselect";
   }	


}

function menusInit() {

	switch(tailorSection) {
		case "index.html":
			document.getElementById("topmenu-sub").className="hidden";
			document.getElementById("top2Approach").className="selected";
			break;
		case "bio.html":
			document.getElementById("topmenu-sub").className="hidden";
			document.getElementById("top2Bio").className="selected";
			break;
		case "contact.html":
			document.getElementById("topmenu-sub").className="hidden";
			document.getElementById("top2Contact").className="selected";
			break;
		case "portfolio.html":
			document.getElementById("top2Portfolio").className="selected";
	
			break;
		case "identity.html":
			document.getElementById("top2Portfolio").className="selected";
			document.getElementById("topIdentity").className="selected";
			treeInit(treeStructure[0]);
			break;
		case "print.html":
			document.getElementById("top2Portfolio").className="selected";
			document.getElementById("topPrint").className="selected";
			treeInit(treeStructure[1]);
			break;
		case "web.html":
			document.getElementById("top2Portfolio").className="selected";
			document.getElementById("topWeb").className="selected";
			treeInit(treeStructure[2]);
			break;
			
	}								
}


var imageTree = new Array ();
imageTree["SIC"]=["images/Portfolio/Identity/SocialInnovation_identity.gif", "images/Portfolio/Print/SocialInnovation_print_card.gif", "images/Portfolio/Print/SocialInnovation_print_book.jpg", "images/Portfolio/Web/SocialInnovation_web.gif"];
imageTree["np"]=["images/Portfolio/Identity/NewParadigm_identity.gif", "images/Portfolio/Print/NewParadigm_print_stationer.gif", "images/Portfolio/Print/NewParadigm_print_report.gif", "images/Portfolio/Print/NewParadigm_print_binders.gif"];
imageTree["jantzi"]=["images/Portfolio/Identity/Jantzi_identity.gif", "images/Portfolio/Print/Jantzi_print_stationery.jpg", "images/Portfolio/Web/Jantzi_web.jpg"];
imageTree["coreinsight"]=["images/Portfolio/Identity/CoreInsight_identity.gif"];
imageTree["proact"]=["images/Portfolio/Identity/ProAct_identity.gif", "images/Portfolio/Print/ProAct_print_bcard.gif", "images/Portfolio/Print/ProAct_print_postcard.gif"];
imageTree["acga"]=["images/Portfolio/Identity/Gardening_identity.gif"];
imageTree["leblond"]=["images/Portfolio/Identity/KatrinLeblond_identity.gif", "images/Portfolio/Print/KatrinLeblond_print_poster.jpg"];
imageTree["fairyesque"]=["images/Portfolio/Identity/Fairyesque_identity.gif", "images/Portfolio/Print/Fairyesque_print_folder.gif", "images/Portfolio/Print/Fairyesque_print_postcard.jpg"];
imageTree["peloso"]=["images/Portfolio/Identity/GlenPeloso_identity.gif", "images/Portfolio/Print/GlenPeloso_print_bcard.jpg"];
imageTree["unionyoga"]=["images/Portfolio/Identity/Union_identity.gif", "images/Portfolio/Web/Union_web.gif"];
imageTree["griipa"]=["images/Portfolio/Identity/Griipa_identity.gif", "images/Portfolio/Print/Griipa_print_stationery.jpg", "images/Portfolio/Web/Griipa_web.jpg"];
imageTree["bsb"]=["images/Portfolio/Print/Bull_print_cover1.gif", "images/Portfolio/Print/Bull_print_cover2.gif", "images/Portfolio/Print/Bull_print_cover3.gif", "images/Portfolio/Print/Bull_print_Layout1.jpg", "images/Portfolio/Print/Bull_print_Layout2.jpg"];
imageTree["c2p2"]=["images/Portfolio/Print/C2P2_print_booklet-cover.gif", "images/Portfolio/Print/C2P2_print_booklet-Layout-1.gif", "images/Portfolio/Print/C2P2_print_bookletLayout-2.gif"];
imageTree["ttc"]=["images/Portfolio/Print/TTC_print_advertisement.jpg"];
imageTree["tdsb"]=["images/Portfolio/Print/TDSB_print_cover.jpg", "images/Portfolio/Print/TDSB_print_frontback.jpg"];
imageTree["purina"]=["images/Portfolio/Print/Purina_print_newsletter.gif"];
imageTree["righttoplay"]=["images/Portfolio/Print/RegentPark_print_poster.jpg"];
imageTree["rpff"]=["images/Portfolio/Print/SocialInnovation_print_card.gif"];
imageTree["sokagokkai"]=["images/Portfolio/Print/Soka_print_cover.jpg", "images/Portfolio/Print/Soka_print_layout.jpg"];



function cyclePortfolioImage () {
	imageArrayIndex = tailorPage.substring(0 , tailorPage.indexOf('-'));
	var pathPos = document['portfolioImage'].src.indexOf('images/');
	var imgPath = document['portfolioImage'].src.slice(pathPos);
	var newIndex = imageTree[imageArrayIndex].indexOf(imgPath) + 1;
	if (newIndex == imageTree[imageArrayIndex].length) { newIndex = 0; }	// loop back to beginning if at end of array.
	
	document.portfolioImage.src = imageTree[imageArrayIndex][newIndex];

}

function viewPortfolioImage (newIndex) {
	imageArrayIndex = tailorPage.substring(0 , tailorPage.indexOf('-'));
	var x;
	for (x = 0; x < imageTree[imageArrayIndex].length; x++) { document.getElementById("sample" + x).className = ""; }	
	document.getElementById("sample" + newIndex).className = "current";
	document.portfolioImage.src = imageTree[imageArrayIndex][newIndex];

}