$(document).ready(function(){

	if(parent.document.location == document.location){
		// Save Current Body Frame
		setCookie("toLoad", document.location);
		setCookie("frameLoaded", true);
		
		// Get Root Of Project Path
		var urlArray = document.location.href.split("/");
		var currentPath = null;

		for(var i = 0; i < urlArray.length; i++){
			if(currentPath != null){
				if(urlArray[i].indexOf(".htm") != -1){
					currentPath += "index.htm"
				} else {
					currentPath += "../"
				}
			}else{
				switch(urlArray[i].toLowerCase()){
					case "speechassistant":
					case "speechengine":
					case "speechengineasterisk":
					case "speechplatform":
					case "speechtuner":
					case "tuner":
						currentPath = ""
					break;			
				}
			}
		}

		// Redirect To Root Path Of Project FrameSet File		
		document.location.href = currentPath
	}else{

		var updateTreeInterval = null,

			updateTree = function(){
				if(parent.mainNav.treeMenu){

					parent.mainNav.treeMenu.openMenuItem(document.location);

					clearInterval(updateTreeInterval);	
				}
			};

		updateTreeInterval = setInterval(updateTree, 500);

		
		var localFile = (document.location.href.split("/")[0].indexOf("http") == -1);
			localFile = false;
			
		if(!localFile){		
			var txtLink = "<a id=\"aLinkFavorites\">Add to favorites</a>"
				txtLink += "<a id=\"aLinkPage\">Link to page</a>"
				txtLink += "<div id=\"linkDisplay\" class=\"linkPage\">";
				txtLink += "<div class=\"linkDisplayTitle\">Copy and paste the link below:</div>"
				txtLink += "<input type=\"text\" id=\"txtLinkPage\" value=\"" + document.location + "\" />"
				txtLink += "</div>";

				document.getElementById("pageHeaderLinks").innerHTML = txtLink;

			$("#aLinkFavorites").click(function(){		
				if (window.sidebar) { // Mozilla Firefox Bookmark
					window.sidebar.addPanel(document.title, document.location,"");	
				} 
				else if( window.external ) { // IE Favorite
					window.external.AddFavorite(document.location, document.title);
				}
				else if(window.opera && window.print) { // Opera Hotlist
					return true;
				}
			});

			$("#aLinkPage").click(function(){

				if($('#linkDisplay').css('display') == 'block'){
					$('#aLinkPage').html("Link to page");	
					$('#pageHeaderLinks').removeClass('open');
					$("#linkDisplay").css('display', 'none');
				}else{
					$('#aLinkPage').html("close");	
					$('#pageHeaderLinks').addClass('open');
					$("#linkDisplay").css('display', 'block');

					$("#txtLinkPage").focus();
					$("#txtLinkPage").select();
				}
			});

			var pageTracker = _gat._getTracker("UA-369433-1");
				pageTracker._initData(); 
				pageTracker._trackPageview();
		}else{
			$("#pageHeaderLinks").remove();
		}
	}
});

