/*Progressive header image reveal function */


function progressiveImage(wrapId, fadeDelay, duration) {
	
	wrapId = $(wrapId);
	if(!wrapId) return;
	
	var imgs = $(wrapId).getElements('img');
	if(!imgs[0]) return;
	
	//detect ie8 or less, as there are problems using opacity with pngs.
	var ie = Browser.Engine.trident;
	
    if(!fadeDelay) {fadeDelay = 800}
	if(!duration) {duration = 2000}
	
	imgs.each(function(item, index, imgs) {
			if(ie) {
				//Create wrapper and a div to replace the image tag
				var wrap = new Element('div');
				var imgReplace = new Element('div');
				wrap.wraps(item);
				wrap.grab(imgReplace);
				//transfer the image tag classes to the new wrapper
				wrap.setProperty('class', item.getProperty('class')+' png24opacityIE');
				wrap.setStyle('position', 'absolute');
				//set the image replacement to match the image tag
				imgReplace.setStyles({
					width: item.getSize().x,
					height: item.getSize().y,
					display: 'block'
				});
				//remove the classes from the img tag
				item.setProperty('class', '');
				//item is now set to the new wrapper which will handle the opacity change
				item = wrap;
			}
			item.setStyle('opacity', 0);
			
			item.set('tween', {
				'duration': duration,
				'onComplete': (function(){
					var next = this.getNext(this.get('tag')); //for IE this is a div, for all others an img tag
					imgs.loadComplete = $clear(imgs.loadComplete);
					if(next) {
						imgs.loadComplete = (function(){this.fade('in');}).delay(fadeDelay, next);
					}
	
					
				}).bind(item)}
			);
	});
	

	imgs.loadComplete = (function(){
		var allComplete = this.every(function(item){return item.complete});

		if(allComplete) {
			this.loadComplete = $clear(this.loadComplete); 
			
			if(ie) {
				//now that images are loaded, get the src and apply it to the image replacement div via ie AlphaImageLoader
				this.each(function(item) {
					var src = item.getProperty('src');
					var imgReplace = item.getParent('.png24opacityIE').getElement('div');
	 				item.setStyle('display', 'none');;
					imgReplace.setStyle('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+item.getProperty('src')+', sizingMethod="crop")');
				});
				imgs =  $(wrapId).getElements('.png24opacityIE');
			}
			
			this.loadComplete = (function(){imgs[0].fade('in');}).delay(0);
		}
	}).periodical(1000, imgs);

}

window.addEvent('domready', function() {
	progressiveImage('RotatingImageWrap');
});	

// Multi-slide - used to hide information on long pages. User clicks on heading to reveal the information.
function Enable_Multislide() { 	window.addEvent('domready',function() {
		multislide = new multislide('ms_container', 
				{	onExpand: function(el){
						el.addClass('arrow');
					},	
					onCollapse: function(el){
						el.removeClass('arrow');
					}
				});
		var hash = window.location.hash.substr(1); //strip off the leading #
		if (hash) {
			multislide.expand_ifcontains(hash);
			var hashEl = $(hash);
			if (hashEl) {
				var myFx = new Fx.Scroll(window).toElement(hashEl);
			}
		}
		$(document.body).getElements('a[href^=#]').each(function(item){
			href = item.getProperty('href').substr(1);
			item.addEvent('click', function(){
				this.expand_ifcontains(arguments[0]);
				var hashEl = $(arguments[0]);
				if (hashEl) {
					var myFx = new Fx.Scroll(window).toElement(hashEl);
					return false;
				}
				
			}.pass(href, multislide));
		});
	});
}

/*Image Preloader Function*/

function MM_preloadImages() 
{ //v3.0
  var d=document; 
  
  if(d.images)
  { 
    if(!d.MM_p) 
    {
      d.MM_p=new Array();
    }
    
    var i, j=d.MM_p.length, a=MM_preloadImages.arguments; 
    
    for(i=0; i<a.length; i++)
    {
      if (a[i].indexOf("#")!=0)
      { 
        d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
      }
    }
  }
}

/*Any page ensure these images are preloaded*/
MM_preloadImages(
	'/Images/navigation/PCAHeaderLogoHover.gif',
	'/Images/navigation/WhyPcaHover.jpg',
	'/Images/navigation/ContactHover.jpg',
	'/Images/navigation/AcademicsHover.jpg',
	'/Images/navigation/GeneralInfoHover.jpg',
	'/Images/navigation/ExtracurricularHover.jpg',
	'/Images/navigation/HistoryHover.jpg',
	'/Images/navigation/PCAOnlineHover.jpg',
	'/Images/navigation/AlumniHover.jpg'
);

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17119201-2']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
