// Javascript Document

// New Dropdown Menu Jquery
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function dropdown_open()
{  dropdown_canceltimer();
   dropdown_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function dropdown_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function dropdown_timer()
{  closetimer = window.setTimeout(dropdown_close, timeout);}

function dropdown_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#dropdown > li').bind('mouseover', dropdown_open)
   $('#dropdown > li').bind('mouseout',  dropdown_timer)});

document.onclick = dropdown_close;


/*	innerfade jquery settings
	discription:

	$('ID or class of the element containing the fading objects').innerfade({
		animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'),
		speed: Fadeing speed in milliseconds or keywords (slow, normal or fast)(Default: 1000, aka 1 second), 
		timeout: Time between the fades in milliseconds (Default: '2000'),
		type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'),
		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
		runningclass: CSS-Class which the container get’s applied (Default: 'innerfade')
		});
*/ 


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        	'animationtype':    'fade',
            'speed':            1000,
            'type':             'sequence',
            'timeout':          4000,
            'containerheight':  '500px',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do {current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );             
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}

// global overrides defaults for .innerfade below this line
		$(document).ready(
		function(){	$('.lst#slideshow').innerfade({
		// code placed here will override above defaults
						containerheight: '328px'
					});

		}
	);
		
		
		
// pitzer hp innerfade
		$(document).ready(
		function(){	$('.pz#slideshow').innerfade({
		// code placed here will override above defaults
						containerheight: '300px'
					});
		}
	);
		
//	innerfade jquery settings end		


// jQuery Current page selected code for left navigation 1/5/10 Joe
// url path will automatically select current page using the .selected class

$(document).ready(function(){
   var path = location.pathname.substring(1);
   if ( path )
     $('#sidebar_nav a[@href$="' + path + '"]').addClass('selected');
 });
// add another class named selected to for items contained within .main_nav2 when it is the current page
$(document).ready(function(){
   var path = location.pathname.substring(1);
   if ( path )
     $('#sidebar_nav .main_nav2 a[@href$="' + path + '"]').addClass('selected2');
 });

$(document).ready(function() {
        $("a.selected").parents('.main_nav').addClass("selected_subnav");
		$("a.selected2").parents('.subnav2').addClass("selected_subnav2");
		$("a.selected2").parents('.main_nav').addClass("selected_subnav2");
		$("a.selected.selected2").parents('.main_nav2').addClass("activate_subnav2");
	});

// end class for selected page of left nav

// Google Search Javascript

(function() {
var u = document.location.href.replace(/http:\/\//, '');
var sb = document.getElementById('searchbox_demo');
if (document.characterSet != undefined) {
if (sb.ie != undefined) {
sb.ie.value = document.characterSet;
} else {
var ie_field = sb.cref.cloneNode(true);
ie_field.name = "ie"
ie_field.value = document.characterSet;
sb.insertBefore(ie_field, sb.cref);
}
}
sb.cref.value = 'http://www.google.com/cse/tools/makecse?url=' + encodeURIComponent(u);
})();
(function() {
var f = document.getElementById('searchbox_demo');
if (!f) {
f = document.getElementById('searchbox_demo');
}
if (f && f.q) {
var q = f.q;
var n = navigator;
var l = location;
if (n.platform == 'Win32') {
q.style.cssText = '';
}
var b = function() {
if (q.value == '') {
q.style.background = '#fff url(/homepage_elements/search_text.gif) left no-repeat';
}
};
var f = function() {
q.style.background = '#ffffff';
};
q.onfocus = f;
q.onblur = b;
if (!/[&?]q=[^&]/.test(l.search)) {
b();
}
}
})();


// Pop Up window script

function PopUp(code) {
	CodeTemplate = window.open(code, "Video_Box", "width=500,height=400,left=150,top=150,scrollbars=yes,status=no,resize=yes")
	CodeTemplate.focus()
}


// jQuery for social networking tooltip class in footer
$(document).ready(function(){
 
	$(".tooltip a").append("<span></span>");
	
	$(".tooltip a").hover(function() {
		$(this).find("span").animate({opacity: "show", top: "-30"}, "slow");
		var hoverText = $(this).attr("title");
	    $(this).find("span").text(hoverText);
	}, function() {
		$(this).find("span").animate({opacity: "hide", top: "-25"}, "fast");
	});
});


/* Browser Selector Code */
/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);


// javascript for including a html file on non .asp pages. !only use this on web based forms that can't be created as an .asp file!

function clientSideInclude(id, url) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id + 
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

/* show/hide function - This will activate class tags that 
						display and close paragraphs when 
						the header is clicked, a similar
						version was created for the IMS website
						- Joseph Dickson 08/05/2010 
						*/
// Faculty A-Z

$(document).ready(function() {

// show all discriptions
   $('#discriptions').click(function(){
	 $('.course_body').show();
  });


// hide all discriptions
   $('#hide_discriptions').click(function(){
     $('.course_body').hide();
  });
 });

// Toggle adjacent course discription to show or hide
$(document).ready(function()
{
  //hide the all of the element with class course_body
  $(".course_body").hide();
  //toggle the componenet with class course_head
  $(".course_head").click(function()
  {
    $(this).next(".course_body").slideToggle(600);
  });
});


// Toggle adjacent .showhide class
$(document).ready(function()
{

  $(".showhide").show();

  $(".toggle_showhide").click(function()
  {
    $(this).next(".showhide").slideToggle(600);
  });
});