﻿$(document).ready(function() {
	var path = location.pathname.substring(0);
	var filename = path.substring(path.lastIndexOf('/')+1,path.lastIndexOf('.aspx'));
	
	if (0 <= path.lastIndexOf('/Submit-Stories/'))  {
		filename = 'Submit-Stories';
	}
	if (0 <= path.lastIndexOf('/Search-Stories/')) {
		filename = 'Search-Stories'
	}
	if (0 <= path.lastIndexOf('/NewsEvents/')) {
		filename = 'NewsEvents'
	}
	if (0 <= path.lastIndexOf('/For-Teachers/')) {
		filename = 'For-Teachers'
	}
	if (0 <= path.lastIndexOf('/About/')) {
		filename = 'About'
	}
	//alert(path.lastIndexOf('/Search-Stories/'));
	var navSection = filename; 
	//alert (document.getElementById('tnavSearch-Stories'));
	setNavs(navSection);
	  
	/*********************************************************************************
	 Menu state scripts - specific to Vevertan Community Archive layouts
	 load this script AFTER js/global.js to use function imageSwap()
	 TODO: make functions robust using global bw to check support for setAttribute(),
		addEventHandler(), removeEventHandler() etc.
	*********************************************************************************/
	
	function setNavs(section){
		//setNavHere('nav'+section);
		setNavOn('tnav'+section);
		//setNavOn('bnav'+section);
	}
	
	function setNavHere(navImgId){
		//alert(navImgId)
		var theNavImg = document.getElementById(navImgId);
		if (theNavImg) {		
			imageSwap(navImgId,2);
			var theLink = theNavImg.parentNode;
			theLink.onmouseout = function(){ imageSwap(navImgId,2); };
		}
	}
	
	function setNavOn(navImgId){
		var theNavImg = document.getElementById(navImgId);
		//alert(document.getElementById("tnavSearch-Stories"));
		//alert(navImgId);
		if (theNavImg) {
			imageSwap(navImgId,1);
			var theLink = theNavImg.parentNode;
			theLink.onmouseover = null;
			theLink.onmouseout = null;
		}
	}
	
	/*ColorBox elements*/
	$(".colorbox").colorbox({iframe:true, innerWidth:650, innerHeight:700, overlayClose:false});
	//$.fn.colorbox({href:'/For-Teachers/teacher-survey.aspx'});
	//$.fn.colorbox({html:'<p>Teachers, please take a moment to complete our survey!</p>'});
	
	/*Dialog*/
	$("#dialog-modal").dialog({
			width: 350,
			height: 210,
			modal: true	
		});
	
	$("#dialogFormLink").click(function(){
		$("#dialog-modal").dialog('close');						
	})
	
})
		
