 jQuery.noConflict();
 jQuery(window).load(function()
		{
			var hmptime = 8000; // Timeout for Homepage random images
			var lns= 50;		// Extra padding for left column
			var rns= 100;		// Extra padding for right column
			
			unHide();
			adjustZindexFlash();
			adjustZindex();
			newsRoomImages();
			navWidth(140);
			setWidth();
			setMHeight();
			setHome();
			equateCols(565);
			equateSlidecap();
			expandDiv();
			equateAll();
			adjustVline();
			setAccordion();
			printPage();
			sharePrint();
			
			//Unhides all hidden elements; Footer, Follow us and Calender of Events block
			function unHide(){
				jQuery('#footer').show();
				jQuery('#home-footer').show();
				jQuery('#bottom-left-nav').show();
				jQuery('#follow-us').show();
			}
			
			// Sets the js for using accordions on the pages
			function setAccordion(){
				if(jQuery('#accordion').get(0) != null){	
					jQuery('#accordion').accordion({ autoHeight: false, active: false, collapsible: true, animated: false });
				}
				if(jQuery('#tabs').get(0) != null){
					jQuery( "#tabs" ).tabs();
				}
			}
			
			// Sets the print and share functionalities
			function sharePrint(){
			   var delay = 400;
			   
			   jQuery('.custom_button, .hover_menu').mouseenter(function() {
			       jQuery('.hover_menu').fadeIn('fast');
			       jQuery('.custom_button').addClass('active');
			       jQuery(this).data('in', true);
			       jQuery('.hover_menu').data('hidden', false);
			   }).mouseleave(function() {
			       jQuery(this).data('in', false);
			       setTimeout(hideMenu, delay);
			   });
			}
			
			// Used in sharePrint function to hide the menu
			function hideMenu(){
			    if (!jQuery('.custom_button').data('in') && !jQuery('.hover_menu').data('in') && !jQuery('.hover_menu').data('hidden')) {
			        jQuery('.hover_menu').fadeOut('fast');
			        jQuery('.custom_button').removeClass('active');
			        jQuery('.hover_menu').data('hidden', true);
			    }
			}
			
			// Fix a IE 7 z-index bug which affects the menu
			function adjustZindex(){
				var zIndex = 1000;
				jQuery('#main div').each(function(){
					jQuery(this).css('zIndex', zIndex);
					zIndex -= 10;
				});
				jQuery('#inner-header-image').css('zIndex', 1000);
				jQuery('#top-alert').css('zIndex', 1500);
			}
			
			//Automatically adjusts vertical rule btw main text and faculty region
			function adjustVline(){
				if(jQuery('#instru-left').get(0) != null){
					if(jQuery('#instru-right').get(0) != null){
						var ir = 3;
						jQuery('#instru-right').children().each(function(){
							ir += jQuery(this).outerHeight(true);						
						});
						
						var il = jQuery('#instru-left').height();
						if( ir < il ){
							jQuery('#instru-right').height(il);
						}
						else{
							jQuery('#instru-right').height(ir);
						}
					}
				}
			}
			
			// Expands the left column to full width if the right column does not exist on the page
			// Also espands mid column to occupy the width of the right column, if the right column is missing from the page
			function setWidth(){
				if(jQuery('#instru-left').get(0) != null){
					if(jQuery('#instru-right').get(0) == null){
						jQuery('#instru-left').width('100%');
					}
				}
				
				var con = '';
				if(jQuery('#right-content div').get(0) != null){
				jQuery('#right-content div').each(function(){
						con +=jQuery.trim(jQuery(this).html());
				});
				}
				if(jQuery('#mid-content-l').get(0) != null){
					if(con == ''){
						jQuery('#right-content').hide();
						jQuery('#mid-content-l').width(819);
						jQuery('#home-footer').width(819);
					}
				}
			}
			
			// Fix for menu appearing under the flash object in the media section
			function adjustZindexFlash(){
				if ( jQuery.support.htmlSerialize ) {
					jQuery('.wrap-media object').append('<param name="wmode" value="transparent" />');
				}
				else{ 
					jQuery(".wrap-media object").each(function (i) {

					var algo = jQuery(this).context.attributes;
					var str_tag = '<OBJECT ';
					
					for (var i=0; i < algo.length; i++)
					str_tag += algo[i].name + '="' + algo[i].value + '" ';
					
					str_tag += '>';
					
					var flag = false;
					
					jQuery(this).children().each(function (elem) {
					if (jQuery(this).attr("NAME") == "wmode") {
					flag=true;
					str_tag += '<PARAM NAME="' + jQuery(this).attr("NAME") + '" VALUE="transparent">';
					}
					else
					str_tag += '<PARAM NAME="' + jQuery(this).attr("NAME") + '" VALUE="' + jQuery(this).attr("VALUE") + '">';
					});
					
					if(!flag)
					str_tag += '<PARAM NAME="wmode" VALUE="transparent">';
					
					str_tag += '</OBJECT>';
					
					jQuery(str_tag).insertAfter(this);
					jQuery(this).remove();
					} ); 
				}
			}
			
			// Sets  the height of the three columns on page load 
			function setMHeight(){
				var nh=0;
				if(jQuery('#mid-content').get(0) != null){	
					var nh = jQuery('#mid-content').height() + jQuery('#home-footer').height();
					jQuery('#mid-content').height(nh);
				}
				if(jQuery('#mid-content-l').get(0) != null){	
					var nh = jQuery('#mid-content-l').height() + jQuery('#home-footer').height();
					jQuery('#mid-content-l').height(nh);
				}
				if(jQuery('#left-content-inner').get(0) != null){	
					jQuery('#left-content-inner').height(reCalcLeftHeight());
				}
				if(jQuery('#right-content').get(0) != null){	
					jQuery('#right-content').height(reCalcRightHeight());
				}
			}
			
			// Sets the width for the top navigation menu
			function navWidth(x){
				var flag = false;

				jQuery('#top-nav li.headlink').hover(function(){
					var m = jQuery(this).outerWidth();
					
					var ch = 0;
					jQuery(this).children('ul').children().each(function(){
						ch = jQuery(this).outerWidth() > ch ? jQuery(this).outerWidth() : ch;
					});
					var newW = m > x ? m : x;
					jQuery(this).children('ul').width(newW);
										
					jQuery(this).children('ul').show();

				},function(){
						jQuery(this).children('ul').hide();
				});

			}
			
			// Calculates the height of the left column, this function is used to get the new height of the column when content is inserted into the page. 
			function reCalcLeftHeight(){
				var ln = 0, bl = 0, lh = 0;
				
				if(jQuery('#left-content-inner').get(0) != null){
					if(jQuery('#left-nav').get(0) != null){
						ln = jQuery('#left-nav').outerHeight();
					}
					if(jQuery('#bottom-left-nav').get(0) != null){
						bl = jQuery('#bottom-left-nav').outerHeight();
					}	
					lh = ln + bl + lns;
				}				
				return lh;
			}
			
			// Calculates the height of the right column, this function is used to get the new height of the column when content is inserted into the page. 
			function reCalcRightHeight(){
				var pm = 0, rb = 0, fu = 0, rh = 0;
								
				if(jQuery('#right-content').get(0) != null){					
					
					if(jQuery('#print-media').get(0) != null){
						pm = jQuery('#print-media').outerHeight();
					}
					if(jQuery('#right-box').get(0) != null){
						rb = jQuery('#right-box').outerHeight();
					}
					if(jQuery('#follow-us').get(0) != null){
						fu = jQuery('#follow-us').outerHeight();
					}
					
					rh = pm + rb + fu+ rns;
					//alert("rh: "+rh);
				}
				return rh;
			}
			
			// Make the Columns equal in height 
			function equateCols(x){
					
				var max = jQuery('#content').height() > x ? jQuery('#content').height() : x;

				if(max >0 ){
					if(jQuery('#left-content').get(0) != null){
						jQuery('#left-content').height(max);}
					if(jQuery('#mid-content').get(0) != null){	
						jQuery('#mid-content').height(max);}
					if(jQuery('#left-content-inner').get(0) != null){
						jQuery('#left-content-inner').height(max);}
					if(jQuery('#mid-content-l').get(0) != null){	
						jQuery('#mid-content-l').height(max);}
					if(jQuery('#right-content').get(0) != null){
						jQuery('#right-content').height(max);}					
				}
			}
			
			// Make the media tabs on the homapage equal in height 
			function equateSlidecap(){
				var max = jQuery('#slide-container .stopic:eq(0)').height();
				if(jQuery('#slide-container .stopic:eq(1)').height() > max)
					max = jQuery('#slide-container .stopic:eq(1)').height();
				if(jQuery('#slide-container .stopic:eq(2)').height() > max)
					max = jQuery('#slide-container .stopic:eq(2)').height();
					
				jQuery('#slide-container .stopic').height(max);	
					
			}
			
			// Make the Columns equal in height 
			function equateColsM(x){
				
				//set height for left-nav
				var nh = jQuery('#left-nav').outerHeight() + jQuery('#bottom-left-nav').outerHeight() + lns;
				jQuery('#left-content-inner').height(nh);
					
				var max = x;

				if(max >0 ){
					if(jQuery('#left-content').get(0) != null){
						jQuery('#left-content').height(max);}
					if(jQuery('#mid-content').get(0) != null){	
						jQuery('#mid-content').height(max);}
					if(jQuery('#left-content-inner').get(0) != null){
						jQuery('#left-content-inner').height(max);}
					if(jQuery('#mid-content-l').get(0) != null){	
						jQuery('#mid-content-l').height(max);}
					if(jQuery('#right-content').get(0) != null){
						jQuery('#right-content').height(max);}					
				}
			}
			
			// Centers the image in the gallery
			function centerImg(i){
				var parent_height = jQuery('#main-media .hm-media').height(); 
				var image_height = jQuery('.hm-media .img-box .wrap-media').eq(i).height();				
				var top_margin = ((parent_height - image_height)/2) > 0 ? ((parent_height - image_height)/2) : 0;
				jQuery('.hm-media .img-box .wrap-media').eq(i).css( 'margin-top' , top_margin);
			}
			
			// Centers the full text to the left of the media element
			function vCenterTxt(curr,next,opts){
				if(jQuery(next).find('.info-wrap-full').get(0) != null){
					var parent_height = jQuery(next).find('.info-wrap-full').height(); 
					var txt_height = jQuery(next).find('.info-wrap-full .info').height();			
					var top_margin = ((parent_height - txt_height)/2) > 0 ? ((parent_height - txt_height)/2) : 0;
					jQuery(next).find('.info-wrap-full .info').css( 'margin-top' , top_margin-15);
				}
			}
			
			// Activates the Media element for the homepage media content
			function setMedia(){
				jQuery('#mid-content #main-media').cycle({ 
				    timeout: 0, 
				    speed:   300,
				    height: 401,
				    after: vCenterTxt,
				    slideExpr: '.hm-media'
				});
				jQuery('#slide-container .stopic').each(function(i){
					jQuery(this).click(function() { 
					    jQuery('#mid-content #main-media').cycle(i+1);
					    centerImg(i+1);
					    var h = 401;
					    if(jQuery('#mid-content #main-media div.hm-media:eq('+(i+1)+') div.img-box').children('.gallery').get(0) != null){
					    	h = 416;
					    }
					    jQuery('#main-media').height(h);
				    	jQuery('#main-media .hm-media').eq(i+1).height(h);
				    	jQuery('#main-media .hm-media:eq('+(i+1)+') .galleria-container').height(h);
					    jQuery('#slide-container .stopic').removeClass("active");
					    jQuery('#slide-container .stopic').eq(i).addClass("active");					     
					    return false; 
					});	
				
					
				});
							
			}
			
			// Sets the gallery for Landing and Interior pages
			function setGallery2(){	
				if(jQuery('#int-media .int-media-slide').get(0) != null){
					jQuery('#int-media .int-media-slide').cycle({ 
					    timeout: 0, 
					    speed:   300,
					    containerResize: 0,
					    fit: 1,
					    prev: '#int-media #prev',
					    next: '#int-media #next',
					    after: onAfterGal2,
					    height: 270,
					    width: 472,
					    slideExpr: 'img'
					});
				}
				
				if(jQuery('#land-media .land-media-slide').get(0) != null){
					jQuery('#land-media .land-media-slide').cycle({ 
					    timeout: 0, 
					    speed:   300,
					    containerResize: 0,
					    fit: 1,
					    prev: '#land-media #prev',
					    next: '#land-media #next',
					    after: onAfterGal2,
					    height: 285,
					    width: 542,
					    slideExpr: 'img'
					});
				}
			}
			// Sets the gallery for the homepage
			function setGallery(){
				jQuery('.gallery .galleria-container .galleria-stage .galleria-images').cycle({
					timeout: 0, 
				    speed:   300,
				    containerResize: 0,
				    fit: 1,
				    prev: '.galleria-image-nav .galleria-image-nav-left',
				    next: '.galleria-image-nav .galleria-image-nav-right',
				    before: onBefore,
				    after: onAfter,
				    height: 331,
				    width: 507
				});
			}
			// Call back for setGallery function
			function onBefore(curr,next,opts){
				//
			  // Get image size
			  var imgHeight = jQuery(next).height();
			  var imgWidth = jQuery(next).width();
				
			  // Get container size
			  var slider = jQuery(next).parent();
			  var containerHeight = slider.height();
			  var containerWidth = slider.width();
				
			  var top = Math.floor((containerHeight / 2) - (imgHeight / 2));
			  var left = Math.floor((containerWidth / 2) - (imgWidth / 2));
			  
			  
			  top = top > 0 ? top : 0;
			  left = left > 0 ? left : 0;

			  jQuery(next).css({"marginTop" : top,"marginLeft" : left});
			}
			
			// Call back for setGallery function
			function onAfter(curr,next,opts) {
				var caption = jQuery(next).attr('alt');
				jQuery('.galleria-counter .galleria-current').html(opts.currSlide + 1);
				jQuery('.galleria-counter .galleria-total').html(opts.slideCount);
				jQuery('.galleria-info-text .galleria-info-description').html(caption);
			}
			
			// Call back for setGallery2 function
			function onAfterGal2(curr,next,opts) {
				var caption = jQuery(next).attr('alt');
				if(jQuery.trim(caption) != ''){
					jQuery(next).parents("#land-media").children(".caption").show().html(caption);
				}
				else{
					jQuery(next).parents("#land-media").children(".caption").hide();
				}
				
			}


			// Method responsible for the Homepage Media content and the Landing page gallery
			function setHome(){
				if(jQuery('#mid-content #main-media').length != 0){
					randImg();
					setMedia();			
					centerImg(0);
					setGallery();
					
				}

				setGallery2();

			}
			
			// Displays random images when the homepage loads
			function randImg(){
				jQuery('#main-media .hm-media:eq(0) .img-box .wrap-media').cycle({ 
					    timeout: hmptime, 
					    speed:   300,
				     	slideExpr: 'img'
				});
			}
			
			// Controls the collapsing and expanding of divs
			function expandDiv(){
				jQuery(".ex-cont .expand").click(function () {
					if(jQuery(this).siblings().filter(".ex-inner").get(0).style.display == "block"){
						jQuery(this).children().filter(".ico").html("+ ");
						jQuery(this).siblings().filter(".ex-inner").hide();
					}
					else{
						jQuery(this).children().filter(".ico").html("-  ");
						jQuery(this).parent().siblings().children(".expand").find(".ico").html("+ ");
						jQuery(this).parent().siblings().children(".ex-inner").hide();
						jQuery(this).siblings().filter(".ex-inner").show();
						
					}

					
				});
			}
			
			// Makes sure the height is equal accross all columns
			// This is the main function responsible for making sure the columns have equals hieghts
			// It uses a jquery plugin called resize, which fires an event everytime the page height changes
			// It's binded to #mid-content-inner and #landing-inner, which are the middle column on the Interior and the Landing pages respectively
			function equateAll(){				
				jQuery('#mid-content-inner').bind( 'resize', function(e) {					
					var lh = reCalcLeftHeight();
					var rh = reCalcRightHeight();
					var r = (lh > rh) ? lh : rh;
					var m = jQuery('#mid-content-inner').outerHeight() + jQuery('#home-footer').outerHeight();						
					var h = (r > m) ? r : m;
					equateColsM(h);
					adjustVline();
				});
				jQuery('#landing-inner').bind( 'resize', function(e) {
					var lh = reCalcLeftHeight();
					var rh = reCalcRightHeight();
					var r = (lh > rh) ? lh : rh;
					var m = jQuery('#landing-inner').outerHeight() + jQuery('#home-footer').outerHeight();						
					var h = (r > m) ? r : m;
					equateColsM(h);
				});
			}
			
			// Sets the shadow box functionality for the newsroom page
			function newsRoomImages(){
				jQuery("#j-gallery .img-ico a").each(function (i) {
					var rt = jQuery("#j-gallery .img-ico a").eq(i).siblings(".in-title").html()
					var t = (rt != null) ? rt : '';
					
					jQuery(this).fancybox({
						'titlePosition' : 'inside',
						'overlayColor' : '#000',
						'overlayOpacity' : 0.7,
						'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {	return t; } 
					});
				}); 	
			}
			
			// Sets up print page
			function printPage(){
				jQuery('#print-media .print-this').click(function() {
				  window.print();
				  return false;
				 });	
			}
			
			// Temporary redirect. Helpful for updating menu links while pages publish
			// jQuery("a[href='https://www.juilliardalumni.net/NetCommunity/SSLPage.aspx?&pid=379']").attr('href', 'https://www.juilliardalumni.net/SSLPage.aspx?&pid=379');
			jQuery("a[href='http://www.plan.gs/Home.do?orgId=5093']").attr('href', 'http://www.gftpln.org/Home.do?orgId=5093');
		}
		
		
);
