﻿/* ------------------------REPLACEMENT SLIDESHOW 2010---------------------------- */
//http://www.kevinleary.net/jquery-fadein-fadeout-problems-in-internet-explorer/
(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = function(speed,to,callback) {
		return this.animate({opacity: to}, speed, function() {
			if (to == 1 && jQuery.browser.msie)
				this.style.removeAttribute('filter');
			if (jQuery.isFunction(callback))
				callback();
		});
	};
})(jQuery);

//ADAPTED FROM http://jonraasch.com/blog/a-simple-jquery-slideshow
function slideSwitch() {
	//SET CURRENT
	var $active = ($('.active').length) ? $('.active') : $('.slideshow .slide').first();
	$active.addClass('active');
	$active.customFadeIn(500);
	$('.last').customFadeOut(500);
	
	//CHECK FOR CLASS TO LOOP OR JUST ONCE
	if ($('.slideshow .active img').attr('src')  == $('.slideshow .slide img').last().attr('src')) {
		if ($('.slideshow').hasClass('once')) {
			clearInterval(slideshowtimer);
		} else {
			//SET NEXT
			$('.slideshow .slide').first().removeClass('last').addClass('active');
			$active.removeClass('active').addClass('last');
		}
	} else {
		//SET NEXT
		$active.next().removeClass('last').addClass('active');
		$active.removeClass('active').addClass('last');
	}

	//SET SLIDESHOW TO VISIBLE, REALLY ONLY THE FIRST TIME
	$('.slideshow .slide').css('visibility','visible');
}

// PROCEDURAL :: CHECK FOR SLIDESHOW
if ($('.slideshow').length) {
	$('.slideshow .slide').customFadeOut(0);
	$('.slideshow .slide:first-child').addClass('active');
	$('.slideshow .active').css('visibility','visible');
	$('.slideshow .active').customFadeIn(750);
	var slideshowtimer = setInterval("slideSwitch();",2500);
}
/* ------------------------REPLACEMENT SLIDESHOW 2010---------------------------- */



/* ------------------------SLIDESHOW---------------------------- */
//OPACITY MODIFIED FROM http://www.brainerror.net/scripts_js_blendtrans.php
//CLASSNAME MODIFIED FROM http://www.hotscripts.com/forums/javascript/47025-document-getelementsbyclassname.html
/* ----------------------------- */

function getElementsByClassName(classname,container) {
	var objTemp = document.getElementsByTagName("*");
	var arrStories = [];
	var blnSomething = false;
	for (var i in objTemp) {
		if (new RegExp("\\b"+classname+"\\b").test(objTemp[i].className)) {
			arrStories.push(objTemp[i]);
			blnSomething = true;
		}
	}
	
	if (!(blnSomething)) {
		arrStories[0] = -1;
	}
	
	return arrStories;
}

function setOpacity(id,opacity) {
	var object = document.getElementById(id).style;
	
	object.opacity = (opacity / 100);						//SAFARI,FIREFOX,CSS3
	object.MozOpacity = (opacity / 100);					//OLD MOZILLA
	object.KhtmlOpacity = (opacity / 100);					//OLD KONQUEROR AND OLD SAFARI-WEBKIT
	object.filter = "alpha(opacity=" + opacity + ")";		//IE
}

function setFade(id,opacStart,opacEnd,millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;
	var i;

	//determine the direction for the blending, if start and end are the same nothing happens
	if (opacStart > opacEnd) {
		for (i = opacStart; i >= opacEnd; i--) {
			setTimeout("setOpacity('"+id+"',"+i+")",(timer * speed));
			timer++;
		}
	} else if (opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++) {
			setTimeout("setOpacity('"+id+"',"+i+")",(timer * speed));
			timer++;
		}
	}
}

function playSlideshow() {
	switch (conTransition) {
		case 'fade':
			setFade(arrStories[current].id,100,0,750);
			setFade(arrStories[next].id,0,100,750);
			//highlightButton(next);
			break;
	}

	current = next;
	next++;
	if (next == arrStories.length) { next = 0; }
}

function gotoSlide(next) {
	switch (conTransition) {
		case 'fade':
			setFade(arrStories[current].id,100,0,750);
			setFade(arrStories[next].id,0,100,750);
			//highlightButton(next);
			break;
	}
	
	current = next;
	clearInterval(timer);
}

function highlightButton(num) {
	//GET BUTTONS
	var arrButtons = getElementsByClassName("button","b2bSlideshowWebPart");

	//CLEAR ALL BUTTONS
	for (i = 0;i < arrButtons.length;i++) {
		arrButtons[i].setAttribute("class", "button buttonRegular");
		arrButtons[i].setAttribute("className", "button buttonRegular");
	}

	arrButtons[num].setAttribute("class", "button buttonActive");
	arrButtons[num].setAttribute("className", "button buttonActive");
}

//--------------------------
//   PROCEDURE
//--------------------------


//MAKE ARRAY
var arrStories = getElementsByClassName('story');

if (arrStories[0] != -1) {
	//START BUTTONS
	var strButtons = "";
	
	//DETERMINE TYPE OF TRANSITION
	var conTransition = "fade";
	
	//SETUP EACH CLASS
	for (i = 0;i < arrStories.length;i++) {
		//--ASSIGN IDs SEQUENTIALLY TO OBJECTS
		arrStories[i].setAttribute("id","story"+i);
		
		//--HIDE ALL
		setOpacity(arrStories[i].id,0);
		
		//--MAKE BUTTONS
		//strButtons += '<a href="#" onclick="gotoSlide('+i+');return false;" class="button buttonRegular">'+(i + 1)+'</a>';
	}
	//SHOW FIRST
	var current = 0;
	var next = 1;
	setOpacity(arrStories[current].id,100);
	//SHOW BUTTONS
	//document.getElementById('buttons').innerHTML = strButtons;
	//highlightButton(0);
	//FADE ON TIMER
	var timer = setInterval("playSlideshow();",6000);
}

/* ------------------------JQUERY---------------------------- */
$(document).ready(function(){	
	//------------------------------<FONT> TAGS
	//http://stackoverflow.com/questions/278709/allowing-the-font-tag-to-override-css
	$('font[size]').each(function() {
        var fontSize = this.size;
        if (fontSize == 1) {
            $(this).css("font-size", 10);
        } else if (fontSize == 2) {
            $(this).css("font-size", 11);
        } else if (fontSize == 3) {
            $(this).css("font-size", 13);
        } else if (fontSize == 4) {
            $(this).css("font-size", 16);
        } else if (fontSize == 5) {
            $(this).css("font-size", 24);
        } else if (fontSize == 6) {
            $(this).css("font-size", 28);
        }
    });
    $('font[face]').each(function() {
        $(this).css('font-family', this.face);
    });
    $('font[color]').each(function() {
        $(this).css('color', this.color);
    });


	//------------------------------CALENDAR
	//MODIFY TD TAGS IN CALENDAR
	$("td.ms-cal-topday").attr("onclick","return false;");
	$("td.ms-cal-topday").attr("onmouseover","return false;");
	$("td.ms-cal-topday-today").attr("onclick","return false;");
	$("td.ms-cal-topday-today").attr("onmouseover","return false;");
	$("td.ms-cal-topdayfocus").attr("onclick","return false;");
	$("td.ms-cal-topdayfocus").attr("onmouseover","return false;");
	
//FIND EVENTS DATES
	var arrLinks = new Array();
	$('.ms-cal-workitem a').each(function() {
		var strLinkTitle = $(this).text();
		var strLinkTabIndex = $(this).attr("tabindex");
		arrLinks.push(new Array("'"+strLinkTitle+"'",strLinkTabIndex));
	});
	
	


	//REPLACE LINKS FOR EVENT DATES
	$('.ms-cal-topday a').each(function() {
		var strDateTabIndex = $(this).attr('tabindex');
		var strDateContent = $(this).text();
		var strDate = $(this).attr('href');
		strDate = strDate.substring(strDate.indexOf('MoveToViewDate(') + 16,strDate.indexOf('Day') - 3);
		strDate = strDate.replace(/\\u002f/g,'%2F');
		
		for (i = 0;i < arrLinks.length;i++) {
			if (strDateTabIndex == arrLinks[i][1]) {
				$(this).attr('alt',arrLinks[i][0]);
				//$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
				$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
			}
		}
	});
	
	
	///THIS IS WHAT BRAD AND BRANDON ADDED CAUSE WE ROCK//
	var arrLinks2 = new Array();
	$('.ms-cal-noworkitem a').each(function() {
		var strLinkTitle = $(this).text();
		var strLinkTabIndex = $(this).attr("tabindex");
		arrLinks2.push(new Array("'"+strLinkTitle+"'",strLinkTabIndex));
	});
		$('.ms-cal-topday a').each(function() {
		var strDateTabIndex = $(this).attr('tabindex');
		var strDateContent = $(this).text();
		var strDate = $(this).attr('href');
		strDate = strDate.substring(strDate.indexOf('MoveToViewDate(') + 16,strDate.indexOf('Day') - 3);
		strDate = strDate.replace(/\\u002f/g,'%2F');
		
		for (i = 0;i < arrLinks2.length;i++) {
			if (strDateTabIndex == arrLinks2[i][1]) {
				$(this).attr('alt',arrLinks2[i][0]);
				//$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
				$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
			}
		}
	});
	//REPLACE EMPTY DATES
	$("td.ms-cal-topday").each(function() {
		if ($(this).find('a').attr('href').indexOf("javascript:") != -1) {
			$(this).html('<center>'+$(this).find('a').text()+'</center>');
		}
	});

	//------------------------------
	//REPLACE LINKS FOR EVENT DATES - TODAY
	$('.ms-cal-topday-today a').each(function() {
		var strDateTabIndex = $(this).attr('tabindex');
		var strDateContent = $(this).text();
		var strDate = $(this).attr('href');
		strDate = strDate.substring(strDate.indexOf('MoveToViewDate(') + 16,strDate.indexOf('Day') - 3);
		strDate = strDate.replace(/\\u002f/g,'%2F');
		
		for (i = 0;i < arrLinks.length;i++) {
			if (strDateTabIndex == arrLinks[i][1]) {
				$(this).attr('alt',arrLinks[i][0]);
				//$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
				$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
			}
		}
	});
	
	//REPLACE EMPTY DATES - TODAY
	$("td.ms-cal-topday-today").each(function() {
		if ($(this).find('a').attr('href').indexOf("javascript:") != -1) {
			$(this).html('<center>'+$(this).find('a').text()+'</center>');
		}
	});

//------------------------------
	//REPLACE LINKS FOR EVENT DATES - FOCUS
	$('.ms-cal-topdayfocus a').each(function() {
		var strDateTabIndex = $(this).attr('tabindex');
		var strDateContent = $(this).text();
		var strDate = $(this).attr('href');
		strDate = strDate.substring(strDate.indexOf('MoveToViewDate(') + 16,strDate.indexOf('Day') - 3);
		strDate = strDate.replace(/\\u002f/g,'%2F');
		
		for (i = 0;i < arrLinks.length;i++) {
			if (strDateTabIndex == arrLinks[i][1]) {
				$(this).attr('alt',arrLinks[i][0]);
				//$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
				$(this).attr('href','/Lists/District%20Calendar/calendar.aspx?CalendarDate='+strDate+'&CalendarPeriod=Day');
			}
		}
	});
	
	//REPLACE EMPTY DATES - FOCUS
	$("td.ms-cal-topdayfocus").each(function() {
		if ($(this).find('a').attr('href').indexOf("javascript:") != -1) {
			$(this).html('<center>'+$(this).find('a').text()+'</center>');
		}
	});

});