// JavaScript page methods for pctsWeb
// PAGE = sevents.php

// declare a page namespace
var events = {};

// --- namespace variables -------
events.getEventsCurrentYear = function() {
	// get the events for the current year
	
	// first get a random number so as to prevent IE from using a cached accessor return
	var theRan = pctsFramework.randomNumber();
		
	// Create an accessor
	var theAccessor = "../accessors/getEvents.php?year=" + pctsFramework.currentYear;
	var theAccessor = theAccessor + "&anticache=" + theRan;
		
	// set the target
	var theTarget = document.getElementById('eventsBody');
	
	pctsFramework.getContent(theAccessor, theTarget, true);
	
	// update the control assembly
	document.getElementById('currentYear').className = 'newsLinkInactive';
	document.getElementById('nextYear').className = 'newsLink';
	
}

events.getEventsNextYear = function() {
	// get the events for the current year
	
	// first get a random number so as to prevent IE from using a cached accessor return
	var theRan = pctsFramework.randomNumber();
		
	// Create an accessor
	var theAccessor = "../accessors/getEvents.php?year=" + pctsFramework.nextYear;
	var theAccessor = theAccessor + "&anticache=" + theRan;
		
	// set the target
	var theTarget = document.getElementById('eventsBody');
	
	pctsFramework.getContent(theAccessor, theTarget, true);
	
	// update the control assembly
	document.getElementById('currentYear').className = 'newsLink';
	document.getElementById('nextYear').className = 'newsLinkInactive';
	
}

events.moreControlMouseIn = function(theClass, theId) {
	// handle mouse in to a table row
	
	if(theId == 'nextYear' && theClass == 'newsLink') {
		document.getElementById(theId).className = 'newsLinkMoused';
		
	}
	
	if(theId == 'currentYear' && theClass == 'newsLink') {
		document.getElementById(theId).className = 'newsLinkMoused';
		
	}
	
}	

events.moreControlMouseOut = function(theClass, theId) {
	// handle mouse out from a table row
	// alert(theClass);
	
	if(theId == 'nextYear' && theClass == 'newsLinkMoused') {
		document.getElementById(theId).className = 'newsLink';
		
	}
	
	if(theId == 'currentYear' && theClass == 'newsLinkMoused') {
		document.getElementById(theId).className = 'newsLink';
		
	}
	
}

events.checkForNextEvents = function() {
	// check to see if there are any events next year
	
	// first get a random number so as to prevent IE from using a cached accessor return
	var theRan = pctsFramework.randomNumber();
		
	// Create an accessor
	var theAccessor = "../accessors/checkEvents.php?year=" + pctsFramework.nextYear + "&mode=next";
	var theAccessor = theAccessor + "&anticache=" + theRan;
	
	// call the accessor
	page.getData(theAccessor);
	
}

events.handleReturnedEventNumber = function(theNumber, theMode) {
	// check to see if there are any records for a given year, and if not, turn off that year in the paging control
	if(theNumber == '0') {
		// no records were found
		var theElement = theMode + 'Year';
		document.getElementById(theElement).style.display = 'none';
		document.getElementById('pageControlSeparator').style.display = 'none';
		
	}
}

events.primaryMouseIn = function(theId) {
	// handle mouse in to an event block
	
	// first, determine the iterator
	var theThumbNum = theId.split('eventItem');
	var i = theThumbNum[1];
	
	// now handle the fade
	if (pctsFramework.browser != 'IE') {
		  // its not IE so we address the entire primary block
		  var theThumb = 'eventItem' + i;
		  // set the opacity of the thumb
		  page.setOpacity(100, theThumb);
		  //$('#' + theThumb).fadeTo("normal", 1.0);

	  } else {
		  // it's IE so we address the thumb image itself
		  var theThumb = 'eventThumbParent' + i;
		  page.setOpacity(100, theThumb);
		  
		  //theThumb = 'IEPressBlockBody' + i;
		  //page.setOpacity(100, theThumb);	  
	
	  }
}

events.primaryMouseOut = function(theId) {
	// handle mouse out from an event block
	
	// first, determine the iterator
	var theThumbNum = theId.split('eventItem');
	var i = theThumbNum[1];
	
	// now handle the fade
	if (pctsFramework.browser != 'IE') {
		  // its not IE so we address the entire primary block
		  var theThumb = 'eventItem' + i;
		  // set the opacity of the thumb
		  // $('#' + theThumb).fadeTo("normal", .79);
		  page.setOpacity(88, theThumb);

	  } else {
		  // it's IE so we address the thumb image itself
		  var theThumb = 'eventThumbParent' + i;
		  page.setOpacity(88, theThumb);
		  
		  //theThumb = 'IEPressBlockBody' + i;
		  //page.setOpacity(88, theThumb);
		  
	  }
}

events.fadeThumbs = function() {
	// fade out the thumbnail images for the thumbs so that they can get a nice mouseover effect when a user hovers the mouse over a primary block
	
	// we iterate through the thumb collection to do this
	
	// first get the number of thumbs
	var theThumbs = document.getElementById('numItems').value * 1;
	
	// now iterate
	for(i = 1; i <= theThumbs; i++) {
		
		if (pctsFramework.browser != 'IE') {
			// its not IE so we address the entire primary block
			var theThumb = 'eventItem' + i;
			// set the opacity of the thumb
			$('#' + theThumb).fadeTo("normal", 0.88);

		} else {
			// it's IE so we address the thumb image itself
			var theThumb = 'eventItemParent' + i;
			// set the opacity of the thumb
			// page.setOpacity(88, theThumb);
			$('#' + theThumb).fadeTo("normal", 0.88);
		}
		
	}
	
}

// --- page functions -------



// --- attached events -------

// we attach inside an if statement because IE handles event listeners differently from other browsers.

if (window.attachEvent) {
	// attached events for IE
	window.attachEvent("onload", events.getEventsCurrentYear);
	window.attachEvent("onload", events.checkForNextEvents);
	// window.attachEvent("onload", events.fadeThumbs);

} else {
	// attached events for other browsers
	window.addEventListener('load', events.getEventsCurrentYear, false);
	window.addEventListener('load', events.checkForNextEvents, false);
	// window.addEventListener('load', events.fadeThumbs, false);

}