// JavaScript Document

// Search Function piggy-backing in the Menu JavaScript Page.
function doUDSearch(theEvent, boolWasButton) {
	
	if (window.event) { theEvent = event; } // IE Fix
	
    var KeyID = theEvent.keyCode;
    if (KeyID == 13 || boolWasButton == true) {
        document.getElementById('q').value = document.getElementById('searchBox').value;
        document.forms[0].action = "http://gsa1.udel.edu/search";
        document.forms[0].method = "get";
        if (document.getElementById('__VIEWSTATE')) { document.getElementById('__VIEWSTATE').value = ""; }
        document.forms[0].submit();
        return false;
    }
    else {
        return false;
    }
}

// Begin Menu Stuff
$(document).ready(function() {

// Function that changes the style of the colored Banner Bar and H2 tags to 
// correspond with the section of the site we are in.
var strURL = window.location.toString();

if (strURL.search(/\/about\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-about.jpg");
	$("h2").css("color", "#A16B00");
}
else if (strURL.search(/\/people\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-people.jpg");
	$("h2").css("color", "#6D8940");
}
else if (strURL.search(/\/academics\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-academics.jpg");
	$("h2").css("color", "#588946");
}
else if (strURL.search(/\/prospective\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-prospective.jpg");
	$("h2").css("color", "#497FA9");
}
else if (strURL.search(/\/research\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-research.jpg");
	$("h2").css("color", "#8D8280");
}
else if (strURL.search(/\/marine\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-marine.jpg");
	$("h2").css("color", "#278C98");
}
else if (strURL.search(/\/getinvolved\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-getinvolved.jpg");
	$("h2").css("color", "#C36C40");
}
else if (strURL.search(/\/news\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-news.jpg");
	$("h2").css("color", "#BD8E00");
}
else if (strURL.search(/\/utility\//i) != -1) {
	$('img#colorBar').attr("src","/Media/Images/graphics/colorBar-utility.jpg");
	$("h2").css("color", "#3D78D0");
}

//small function to make external links launch a new page/change string to match host domain.
$("#right a[@href^=http]").attr("target","_blank");
$("#right a[@href^=http]").attr("rel","nofollow");
//icon generating code
$("#right a[@href^=mailto]").before('<span class="emailIcon">&nbsp;</span>');
$("#right a[@href$=pdf]").before('<span class="pdfIcon">&nbsp;</span>').attr('target','_blank');
$("#right a[@href$=jpg]").before('<span class="downloadIcon">&nbsp;</span>').attr('target','_blank');
$("#right a[@href$=doc]").before('<span class="downloadIcon">&nbsp;</span>').attr('target','_blank');
$("#right a[@href$=mpg]").before('<span class="movieIcon">&nbsp;</span>').attr('target','_blank');
$("#right a[@href$=mov]").before('<span class="movieIcon">&nbsp;</span>').attr('target','_blank');
$('#breadcrumb li:last a').attr('href','#').addClass('noLink');

$("#printBtn").click(function() {window.print();});

//reset giftshop form.
$("#resetBtn").click(function() {
																															$("#giftShop input").val("")
																													
																															; return false
																															
																															});


$(".searchBox").focus( function() { $(this).val("");});

$(".learnMore").hover(function(){
					$(this).attr('src','/Media/Images/graphics/button-LearnMore-Over.gif');																								
																															},function(){
																															
					$(this).attr('src','/Media/Images/graphics/button-LearnMore.gif');																										
																											});


//add close class to all li's in #nav
$("#nav li ul").parent().addClass("c t");
$("#nav > li").addClass("c t");

/* the following function is used to find the link to the page the browser is currently on, and give it a class of activeLink  */  
/* it only works on subfolders, we need to treat the homepage (either www.ceoe.udel.edu/ or www.ceoe.udel.edu/default.aspx) differently */
if ((location.pathname.substring(1).toString() != "default.aspx") && (location.pathname.substring(1).toString() != "")) {
   $('#nav a[@href$="' + location.pathname.substring(1) + '"]').addClass("activeLink").parents().removeClass("c");
}
else {
   $('a[title="Home Page"]').addClass("activeLink").parents().removeClass("c");
}


//This is for the code to choose a section to highlight in the main nav, if the page is not in the navigation.
if ($("#navColumn").children().is("a")) {
	$("#nav a[@href=" + $("#navColumn a").attr("href") + "]").addClass("activeLink").parents().removeClass("c");
}


$(".topToggle").each(function(){
  if ($(this).siblings().is("ul:hidden")) {
    $(this).removeClass("openTopIcon");	
  }
	else {
    $(this).addClass("openTopIcon");
    $(this).parent("li").siblings("li:openIcon").click();
	}																											
});

$(".topToggle").click(function() {
  $(this).toggleClass("openTopIcon");													
	$(this).parent("li").toggleClass("c");
	$(this).parent("li").siblings("li:not(.c)").addClass("c").children("a").removeClass("openTopIcon");
	return false;
});

$("#nav>li> a:nth-child(1)").hover(function() {
  $(this).addClass("lightTopIcon").siblings("a").addClass("hoverClass");
  },function(){
  $(this).removeClass("lightTopIcon").siblings("a").removeClass("hoverClass");																																																					
});

$("#nav>li> a:nth-child(2)").hover(function() {																																															
  $(this).addClass("hoverClass").siblings("a").addClass("lightTopIcon");
  },function(){
  $(this).removeClass("hoverClass").siblings("a").removeClass("lightTopIcon");																																																					
});

$(".navicon a").each(function() {
  if ($(this).parent().parent().siblings().is("ul:hidden"))	{
    $(this).removeClass("openIcon");
  }
  else {
    $(this).addClass("openIcon");	
  }																											
});

$(".navicon a").mouseout(function(){$(this).blur();});

$(".navicon a").click(function() {
  if ($(this).parent().parent().siblings().is("ul:hidden")) {
    $(this).addClass("openIcon");	
	}
	else {
	  $(this).removeClass("openIcon");	
	}
	$(this).parent().parent().siblings("ul").toggle();
	return false;
});					 
							 

//background image reloading fix ie6
try {
    document.execCommand("BackgroundImageCache", false, true);
}
catch(err) {}


});



Date.prototype.getWeek = function() {
	var onejan = new Date(this.getFullYear(),0,1);
	return Math.ceil((((this - onejan) / 86400000) + onejan.getDay())/7);
}

var x = 1;
var todayDate = new Date();
var thisWeek = todayDate.getWeek();
var thisYear = todayDate.getYear();

thisYear = thisYear + 100;
if (thisYear > 1000)
{
thisYear = thisYear - 1900;
}

if (thisWeek >= 1 && thisWeek <= 5) 
{convertWeek = 1;}
else if (thisWeek >= 1 && thisWeek <= 22)
{convertWeek = 3;}
else if (thisWeek >= 23 && thisWeek <= 34)
{convertWeek = 5;}
else if (thisWeek >= 35 && thisWeek <= 52)
{convertWeek = 8;}
else
{};

if (convertWeek == 8) {
    nextWeek = 1;
    nextYear = thisYear + 1;
    futureWeek = 3;
    futureYear = thisYear + 1;
    txtCurrentSemester = 'Fall';
    txtNextSemester = 'Winter';
    txtFutureSemester = 'Spring';
}
else if (convertWeek == 1) {
    nextWeek = 3;
    nextYear = thisYear;
    futureWeek = 5;
    futureYear = thisYear;
    txtCurrentSemester = 'Winter';
    txtNextSemester = 'Spring';
    txtFutureSemester = 'Summer';
}
else if (convertWeek == 3) {
    nextWeek = 5;
    nextYear = thisYear;
    futureWeek = 8;
    futureYear = thisYear;
    txtCurrentSemester = 'Spring';
    txtNextSemester = 'Summer';
    txtFutureSemester = 'Fall';
}
else if (convertWeek == 5) {
    nextWeek = 8;
    nextYear = thisYear;
    futureWeek = 1;
    futureYear = thisYear + 1;
    txtCurrentSemester = 'Summer';
    txtNextSemester = 'Fall';
    txtFutureSemester = 'Winter';
};

txtCurrentYear = thisYear + 1800;
txtNextYear = nextYear + 1800;
txtFutureYear = futureYear + 1800;

$(document).ready(function(){
    $('.currentSemLink').attr('href','http://chico.nss.udel.edu/CoursesSearch/search-results?college=MS&term=' + thisYear + convertWeek );
    $('.nextSemLink').attr('href','http://chico.nss.udel.edu/CoursesSearch/search-results?college=MS&term=' + nextYear + nextWeek);
    $('.futureSemLink').attr('href','http://chico.nss.udel.edu/CoursesSearch/search-results?college=MS&term=' + futureYear + futureWeek);
    $('.currentSemLink').text(txtCurrentSemester + ' ' + txtCurrentYear + ' Courses');
    $('.nextSemLink').text(txtNextSemester + ' ' + txtNextYear + ' Courses');
    $('.futureSemLink').text(txtFutureSemester + ' ' + txtFutureYear + ' Courses');
});