
var JS_ROOT = "/sites/all/themes/ailey/js/";
if ($('script[src*=global.js]').length && ($('script[src*=global.js]').length > 0)) {
	try {
	JS_ROOT = $('script[src*=global.js]').attr('src').replace(/global\.js.*/i, '') + 'js/';
	}
	catch(e){}
}

$.generateId = function() {
	return arguments.callee.prefix + arguments.callee.count++;
};
$.generateId.prefix = 'jq-';
$.generateId.count = 0;

$.fn.generateId = function() {
	return this.each(function() {
		this.id = $.generateId();
	});
};


var ALVIN = {
	/* utility methods for global site usage */
	utils: {
		/* png fix
		--------------------------------------------------------*/
		fixPng: {
			init: function(){
				// plugin definition
				$.fn.pngFix = function(options) {
					// iterate and reformat each matched element
					return this.each(function(){
					
						// detect IE6
						if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
							
								// set variables
								var obj = $(this);
								var bg = obj.css("backgroundImage");
								
								// check if its an image
								if(obj.attr("src")){
									var clear="./images/clear.gif"; //path to clear.gif
									obj.css({
										height: obj.height(),
										width: obj.width(),
										filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+obj.attr("src")+"', sizingMethod='crop')"
									});
									obj.attr({ src: clear });
								} else {
									// but if its a bg image through css then do this
									var img = bg.substring(bg.indexOf('"') + 1, bg.lastIndexOf('"'));
									obj.css({
										filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img + "', sizingMethod='crop')",
										backgroundImage: "none"
									});
								}
							
						} // END if 
					
					});
				};			
				ALVIN.utils.fixPng.activate();
			},
			
			activate: function(){
				$('.png, .logo, #news-sticker, .divider, .active, .back-to-ailey-btn, .sidebar-content, .primary-content-header, .primary-content-footer, #primary-footer, #primary-search-box, .playBtn, .domain-the-ailey-school.front div.accordion ul.menu .trigger, domain-the-ailey-school.front div.accordion ul.menu .active-trail .trigger').pngFix();
				
			}
		},
		
		/* css browser hack
		--------------------------------------------------------*/
		checkBrowser: {
			init: function(){
				// ie6
				if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6){
					$('body').addClass('ie6');
					//alert('222')
				} 
				// ie7
				else if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 7){
					$('body').addClass('ie7');
				} 
				// ie8
				else if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 8){
					$('body').addClass('ie8');
				}
				// firefox
				else if(jQuery.browser.mozilla){
					$('body').addClass('firefox');
				}
				// opera
				else if(jQuery.browser.opera){
					$('body').addClass('opera');
				}
				// safari
				else if(jQuery.browser.safari || jQuery.browser.webkit){
					$('body').addClass('safari');
				}
				else {
					$('body').addClass('other');
				}		
			} // end init
		}, // end checkBrowser
		
		/* Clear input text fields on click
		--------------------------------------------------------*/
		inputClear: {
			init: function(){
				$('input:text').live("click", function(){
					if (this.value == this.defaultValue){
						this.value = '';
					}
					
					$('input:text').blur(function(){
						if (this.value == '') {
							this.value = this.defaultValue;
						}
					});					
					
				});
				
				$('input:text').blur(function(){
					if (this.value == ''){
						this.value = this.defaultValue;
					}
				});		
					
			}
		}
		
	}, //end utility
	
	widgets: {
		accordion: {
			init: function(){
				$('div.accordion ul.menu li.expanded ul.menu').hide();
				$('div.accordion ul.menu li.active-trail.expanded ul.menu').show();
				$('div.accordion ul.menu .trigger').click(function(e) {
					var parentMenuItem = $(this).closest("ul.menu li");
					if (parentMenuItem.hasClass("active-trail")) {
						parentMenuItem.find("ul.menu").slideUp('fast');
						parentMenuItem.removeClass('active-trail');
					}
					else {
						var mainMenu = $(this).closest(".pane-content ul.menu");
						mainMenu.find("ul.menu").slideUp('fast');
						mainMenu.find("li.expanded").removeClass('active-trail');
						parentMenuItem.find("ul.menu").slideDown('fast');
						parentMenuItem.addClass('active-trail');
					}
					
					//var childMenu = parentMenuItem.find("ul.menu");
					//childMenu.slideToggle('fast').parent('ul').find('ul.menu:visible').slideUp('fast');
				});
				
				$("div > ul.menu > li.leaf a").each(function() {
					if ($(this).attr("title")) {
						$("<span class='menu-subtitle'>" + $(this).attr("title") + "</span>").insertAfter($(this));
					}
				});
				
			}
		},		

		calToggler: {
			init: function(){
				$('.cal-accordion .acc-content').hide();
				$('.cal-accordion span.toggler').click(function(e){
					//e.preventDefault();
					$(this).parents('.acc-toggle').toggleClass('acc-active');
					$(this).parents('.acc-item').find('div.acc-content').slideToggle('fast');
					//$(this).children('.acc-link').toggleClass('active').next('ul')
					//	.slideToggle('fast').parent().siblings('li')
					//	.find('ul:visible').slideUp('fast');
					//alert($(this).children('.acc-link').attr('class'))
				});			
			}
		},

		showMore: {
			init: function(){

				//TODO: read more functionality should only appear if the text is long enough

				//for repertory detail pages and class detail pages
				if ($('body').hasClass('node-type-repertory-piece') || $('body').hasClass('node-type-class')) {
					$('.about-rep .pane-content').each(function() {
						var togglables = $(this).children("*");

						if (togglables.length > 2) {
							
							togglables.hide();
							togglables.eq(0).show();
							togglables.eq(1).show();
							
							$(this).append("<a href='#' class='read-more-link'>Read More</a>");	
							
							
					        $(this).find(".read-more-link").toggle(function(){
					        	togglables.show();
					        	$(this).text("Read Less").stop();
					        	$(this).css({
					        		'background-position' : '0px -17px'
					        	});
					        }, function(){
					        	togglables.hide();
								togglables.eq(0).show();
								togglables.eq(1).show();
					            $(this).text("Read More").stop();
					            $(this).css({
					        		'background-position' : '0px 3px'
					        	});
					        });
						}
						
					});
				}
				
			
				// for bio page
				if($('body').hasClass('node-type-person')){
					$('.bio-text .pane-content').each(function() {
						var togglables = $(this).children("*");

						if (togglables.length > 2) {
							
							togglables.hide();
							togglables.eq(0).show();
							togglables.eq(1).show();
							
							$(this).append("<a href='#' class='read-more-link'>Read More</a>");	
							
							
					        $(this).find(".read-more-link").toggle(function(){
					        	togglables.show();
					        	$(this).text("Read Less").stop();
					        	$(this).css({
					        		'background-position' : '0px -17px'
					        	});
					        }, function(){
					        	togglables.hide();
								togglables.eq(0).show();
								togglables.eq(1).show();
					            $(this).text("Read More").stop();
					            $(this).css({
					        		'background-position' : '0px 3px'
					        	});
					        });
						}
						
					});
				} // end if body
				
				
				
				$(".wysiwyg-read-more-link").toggle(function() {
					$(this).text("Read Less").stop();
					$(this).css({'background-position' : '0px -17px'});
					$(this).parents(".wysiwyg-more-less").find(".wysiwyg-more-less-toggle").show();
				}, function() {
					$(this).text("Read More").stop();
					$(this).css({'background-position' : '0px 3px'});
					$(this).parents(".wysiwyg-more-less").find(".wysiwyg-more-less-toggle").hide();
				});
				
				ALVIN.widgets.showMore.truncateText();

			},
			
			truncateText: function(){
			
				(function($){
					$.fn.jTruncate = function(options) {
					   
						var defaults = {
							length: 300,
							minTrail: 20,
							moreText: "more",
							lessText: "less",
							ellipsisText: "...",
							moreAni: "",
							lessAni: ""
						};
						
						var options = $.extend(defaults, options);
					   
						return this.each(function() {
							obj = $(this);
							var body = obj.text();
							
							if(body.length > options.length + options.minTrail) {
								var splitLocation = body.indexOf(' ', options.length);
								if(splitLocation != -1) {
									// truncate tip
									var splitLocation = body.indexOf(' ', options.length);
									var str1 = body.substring(0, splitLocation);
									var str2 = body.substring(splitLocation, body.length - 1);
									obj.html(str1 + '<span class="truncate_ellipsis">' + options.ellipsisText + 
										'</span>' + '<span class="truncate_more">' + str2 + '</span>');
									obj.find('.truncate_more').css("display", "none");
									
									// insert more link
									obj.append('<a href="#" class="truncate_more_link more-less">' + options.moreText + '</a>');
				
									// set onclick event for more/less link
									var moreLink = $('.truncate_more_link', obj);
									var moreContent = $('.truncate_more', obj);
									var ellipsis = $('.truncate_ellipsis', obj);
									moreLink.click(function() {
										if(moreLink.text() == options.moreText) {
											moreContent.show(options.moreAni);
											moreLink.text(options.lessText);
											ellipsis.css("display", "none");
											
											//alert('2')
										} else {
											moreContent.hide(options.lessAni);
											moreLink.text(options.moreText);
											ellipsis.css("display", "inline");
											
										}
									
										if($(this).parents('div.media-item').find('.video-clip').length){
											$(this).parents('div.media-item').find('.media-feature a').toggle('fast');
											$(this).parents('div.media-item').find('.video-clip').toggle('normal');
										}
											
										//$('.more-content').slideToggle();
										//$(this).text($(this).text() == 'More' ? 'Less' : 'More');
										$(this).toggleClass('clicked');	
										
										return false;
								  	});
								}
							} // end if


							
						});
					};
				})(jQuery);
				
			}
			
		},
		
		tabs: {
			init: function(){
			
				var tabContainer = $('div.tab-container');
				var tabHeaders = tabContainer.find('.pane-title');
				var tabPanes = tabContainer.find('.pane-content');
				
				var tabNav = document.createElement("div");
				$(tabNav).addClass("tab-nav").addClass("clearfix");
				
				tabContainer.prepend(tabNav);

				for (var i=0; i<tabPanes.length; i++) {
					var tabPane = $(tabPanes.eq(i));
					var tabHeader = $(tabHeaders.eq(i));
					tabPane.generateId();
					tabHeader.wrapInner("<a href='#" + tabPane.attr("id") + "' />");
				}
				
				
				tabHeaders.appendTo(tabNav);
				
				tabPanes.hide();
				
				
				tabHeaders.find("a").click(function() {
					tabPanes.fadeOut('fast').hide().filter(this.hash).fadeIn('fast');
			        //  remove selected class
			        tabHeaders.find("a").removeClass('on');
			        $(this).addClass('on');
			        return false;
				});
				
				
				tabHeaders.find('a').eq(0).click();

			}
		
		},
		
		mediaCarousel: {
			init: function(){
				$.getScript(JS_ROOT + 'plugins/jquery.cycle.all.min.js', function(){
					ALVIN.widgets.mediaCarousel.thumbs();
					ALVIN.widgets.mediaCarousel.arrowNav();
				});
				
			},
			
			thumbs: function(){
				$('#media-player ul').cycle({ 
				    fx:     'scrollHorz', 
				    speed:  'normal', 
				    timeout: 0, 
				    pager:  '#media-thumbs ul', 
				    pagerAnchorBuilder: function(idx, slide) { 
				        // return selector string for existing anchor 
				        return '#media-thumbs ul li:eq(' + idx + ') a'; 
				    }  
				});		
				
				$('#media-thumbs ul li a').click(function(){
					$('#media-thumbs ul li a').siblings('span.highlight').hide();
					$(this).siblings('span').show();
					return false;
				});	
				
				$('#media-thumbs ul li a:first').trigger('click');
				
				//Removal all those painful <div class="panel-separator></div>
				$('.panel-separator').remove();
				
				$('.history-detail-carousel').cycle({ 
				    fx:     'scrollHorz', 
				    speed:  'normal', 
				    timeout: 0, 
				    pager:  '#media-thumbs ul',
				    pagerAnchorBuilder: function(idx, slide) { 
				        // return selector string for existing anchor 
				        return '#media-thumbs ul li:eq(' + idx + ') a'; 
			    	}  
				});
				
				
			},
			
			arrowNav: function(){
				(function($) {
				    $.fn.dbcarousel = function(options) {
				    	// setup default settings
				    	var defaults = {
				    		numElementsShowing: 3,
							contentArrayLength: $('#media-thumbs ul li').length,
							//slidingContainer : $('#media-thumbs ul'),
							elementWidth: $('#media-thumbs ul > li:first').outerWidth(true),
							totalWidth: $('#media-thumbs ul > li:first').outerWidth(true) * $('#media-thumbs ul li').length
				    	},
				    
				    	// This makes it so the users custom options overrides the default ones
				    	settings = $.extend({}, defaults, options);
				    
						return $(this).each(function() {
							obj = $(this);
							slidingContainer = obj;
							$(this).css("width", defaults.totalWidth);
							//alert(obj.class)
							
							var slideRight = function(){
								//if($('.history-detail-carousel').length > 0){
								//	$('.history-detail-carousel').cycle('next');
								//}
								//$('#media-player ul').cycle('next');

								if(!obj.is(':animated')){ 
									var currentLeft = parseInt(obj.css('left'));
									var widthShowing = defaults.numElementsShowing * defaults.elementWidth;
									var totalWidth = defaults.contentArrayLength * defaults.elementWidth;
									//alert(totalWidth - defaults.elementWidth);
									if((totalWidth - defaults.elementWidth) <= (Math.abs(currentLeft) + widthShowing) + 500){
										//addToEnd();
									} else {
										obj.animate({ "left": "-="+defaults.elementWidth * options.numElementsShowing+"px"}, 250);
									}
									
									//alert(Math.abs(currentLeft) + widthShowing);
								}
								
							};
							
							
							var slideLeft = function(){
								//if($('.history-detail-carousel').length > 0){
								//	$('.history-detail-carousel').cycle('prev');
								//}
								//$('#media-player ul').cycle('prev');
								
								if(!obj.is(':animated')){ 
									if(parseInt(obj.css('left')) == 0){
										//addToFront();
									} else {
										obj.animate({ "left": "+="+defaults.elementWidth * options.numElementsShowing+"px"}, 250);
									}	
								}
							};
							
							// arrow functions
							$('#nextBtn').live('click', function(e){ 
								e.preventDefault(); 
								slideRight();  
							});	
							
							$('#prevBtn').live('click', function(e){ 
								e.preventDefault(); 
								slideLeft(); 
							});		
							
							
							/*
							var addToFront = function(){
								var currentLeft = parseInt(obj.css('left'));
								obj.css('left', currentLeft - defaults.elementWidth);
								var lastElement = $('div.carousel-slider > div:last').clone();
								lastElement.insertBefore($('div.carousel-slider > div:first'));
								$('div.carousel-element:last').remove();
								
							};
							
							var addToEnd = function(){
								var currentLeft = parseInt(obj.css('left'));
								obj.css('left', currentLeft + defaults.elementWidth);
								var firstElement = $('div.carousel-slider > div:first').clone();
								firstElement.insertAfter($('div.carousel-slider > div:last'));		
								$('div.carousel-slider > div:first').remove();
							};
							*/
				
							
						}); // END: return this
						
						// returns the jQuery object to allow for chainability.  
				        return this;
				    };
				})(jQuery);

				$('.col-9 #media-thumbs ul').dbcarousel({
					numElementsShowing: 6
				});
				
				$('.col-12 #media-thumbs ul').dbcarousel({
					numElementsShowing: 9
				});
				
				//alert($('.col-12 #media-thumbs ul li:visible').length);

			}
		}
		
	}, // END: widgets

		/* PAGE SPECIFIC JS */
		pages: {
			/* GLOBAL */	
			global: {
				resetButtons: function() {
					$('.webform-client-form #edit-next, .webform-client-form #edit-submit').before($('input[type="reset"]'));
				},
				nav: function(){
					$.getScript(JS_ROOT + 'plugins/jquery.hoverIntent.minified.js', function(){
						//On Hover Over
						var megaHoverOver = function(){
						    $(this).find(".sub").show(); //Find sub and fade it in
						   	
						    (function($){
						        //Function to calculate total width of all ul's
						        jQuery.fn.calcSubWidth = function() {
						            rowWidth = 0;
						            //Calculate row
						            $(this).find("div.nav-col").each(function(){ //for each ul...
						                rowWidth += $(this).outerWidth() + 40; //Add each ul's width together
						            });
						        };
						    })(jQuery); 

						    if($(this).find(".row").length > 0 ){ //If row exists...
						        var biggestRow = 0;	

						        $(this).find(".row").each(function(){	//for each row...
						            $(this).calcSubWidth(); //Call function to calculate width of all ul's
						            //Find biggest row
						            if(rowWidth > biggestRow){
						                biggestRow = rowWidth;
						            }
						        });

						        $(this).find(".sub").css({'width' :biggestRow}); //Set width
						        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
								$(this).find('a.nav-item').addClass('on');

						    } else { //If row does not exist...
						        $(this).calcSubWidth();  //Call function to calculate width of all ul's
						        $(this).find(".sub").css({'width' : rowWidth}); //Set Width
						        $(this).find('a.nav-item').addClass('on');
						        
						    }
						};

						//On Hover Out
						var megaHoverOut = function(){
						  $(this).find(".sub").stop().hide();

						  $(this).find('a.nav-item').removeClass('on');
						};

						//Set custom configurations
						var config = {
						     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
						     interval: 40, // number = milliseconds for onMouseOver polling interval
						     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
						     timeout: 10, // number = milliseconds delay before onMouseOut
						     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
						};

						//$("#primary-nav ul li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
						$("#primary-nav div.content div.panel-panel div.panel-pane .pane-content div:first-child").hoverIntent(config); //div style - No List - change global.css
						//$("#primary-nav ul li").hoverIntent(config); //Trigger Hover intent with custom configurations					      

					});


				} // END NAV

			},
			/* HOMEPAGE */	
			homePage: {
				calendarData: {},
				loadedDates: {},

				selectDate: function(dateText, inst) {
					dateText = $.trim(dateText.replace('ui/datepicker/week/end', ''));
					if (ALVIN.pages.homePage.calendarData[dateText]) {
						var dt = new Date(dateText);
						var formattedDate = $.datepicker.formatDate("DD, MM d", dt);
						var ymdDate = $.datepicker.formatDate("yy-mm-dd", dt);
 
						
						var performances = ALVIN.pages.homePage.calendarData[dateText];
						var location = (performances.length > 0) ? performances[0].location.value : "";

						var popup = '<div class="popup-content"><div class="pointer"></div><div class="row date-time"><a href="/calendar/' + ymdDate + '">' + formattedDate + '</a>'
							+ (location ? ("<p>" + location + "</p>") : "") + '</div>';
						
						for (var i=0; i<performances.length && i<2; i++) {
							var performance = performances[i];
							
							
							var title = performance.title + " " + performance.time;

							if (location != performance.location.value) {
								location = performance.location.value;
								popup += '<div class="row date-time"><p>' + location + '</p></div>';
							}
							
							popup += '<div class="row event-' + i + '"><h4>' + title + '</h4>';

							popup += '<ul>';
							
							var pieces = performance.pieces; //array
							
							for(var j=0; j< pieces.length && j< 3; j++) {
								popup += '<li>' + pieces[j] + '</li>';
							}
							popup += '</ul></div>';
							
						}
						
						popup += "<div><p><a href='/calendar#filters[tid-112]='><span class='disc-arrow-right'>Ailey II Schedule</span></a></p><p><a href='/calendar#filters[tid-146]='><span class='disc-arrow-right'>Public Class Schedule</span></a></p></div>";
						
						popup += '</div>';
						
						
						
						
						$('.event-popup').html(popup).show();
						return true;
					}
					else {
						return false;
					}

				},
				setCalendar: {
					init: function(){
						$.getScript(JS_ROOT + 'plugins/jquery.hoverIntent.minified.js');
						// Datepicker
						$('#calendar').datepicker({
							inline: true,
							onChangeMonthYear: function(year, month, inst) { 
								var dateString = year + "-" + (month < 10 ? "0" : "") + month;
								if (!ALVIN.pages.homePage.calendarData[dateString]) {
									$.getJSON('/performance-listing/' + dateString
											, function(monthData) {
												$.extend(ALVIN.pages.homePage.calendarData, monthData);
												for (var prop in monthData) { 
													//$("td." + prop.replace(/\//g, "-") + " a").css({'backgroundColor' : '#FF6600','color' : '#ffffff'});
													$("td." + prop.replace(/\//g, "-") + " a").addClass('has-event');
												}
												ALVIN.pages.homePage.calendarData[dateString] = true;
											}
									);
								}
								else {
									//since onChangeMonthYear happens BEFORE the element is written, let's delay a little bit...
									window.setTimeout(function(){
										for (var prop in ALVIN.pages.homePage.calendarData) {
											$("td." + prop.replace(/\//g, "-") + " a").addClass('has-event');
										}	
									}
									, 150);
								}
							} 
							//, beforeShow: function(input) { alert('hi'); }

					    	, beforeShowDay: function(dt) {
						        var dateString = $.datepicker.formatDate("mm-dd-yy", dt); //date.getMonth()+'-'+date.getDate()+'-'+date.getFullYear();  
						        return [true, dateString, ''];
						    }

							, onSelect: function(dateText, inst) {
								//this prevents the calendar from redrawing itself
								return false;
							}
						});
						$('#calendar-loading').remove();
						$.getScript(JS_ROOT + 'plugins/jquery.atooltip.js', function(){
							ALVIN.pages.homePage.setCalendar.popup();
						});
					},
					
					//todo: move this to "onChangeMonthYear" event
					popup: function(){
						$('#calendar').hover(function(){
							$('#calendar tr td a').aToolTip();
							//$('#calendar tr td a').click(function() { $(this).hover(); });
								
						}, function(){
						//blah	
						});
							
					}
				},

				// CAROUSEL FOR BG ON HOMEPAGE - BASED ON DEMO CODE
				bgCarousel: function(){
					$("#supersize").appendTo($(document.body));
					(function($){  
					    //Adjust image size
					    $.fn.resizenow = function() {
					        //Define starting width and height values for the original image
					        var startwidth = 1280;  
					        var startheight = 1000;
					        //Define image ratio
					        var ratio = startheight/startwidth;
					        //Gather browser dimensions
					        var browserwidth = $(window).width();
					        var browserheight = $(window).height();
					        
					        //Resize image to proper ratio
					        if ((browserheight/browserwidth) > ratio) {
					            $(this).height(browserheight);
					            $(this).width(browserheight / ratio);
					            $(this).children().height(browserheight);
					            $(this).children().width(browserheight / ratio);
					        } else {
					            $(this).width(browserwidth);
					            $(this).height(browserwidth * ratio);
					            $(this).children().width(browserwidth);
					            $(this).children().height(browserwidth * ratio);
					        }
					        //Make sure the image stays center in the window
					       //	$(this).children().css('left', '0px');
					       // $(this).children().css('top', '0px');
					    };
					})(jQuery);
	
					$('.video-slide-wrap p').hide();
	
					// SUPER SIZE ME
			        $('#supersize').resizenow();
			        //Invoke the resizenow() function on browser resize
			        $(window).bind("resize", function() {
			            $('#supersize').resizenow();
			        });
	
	
					var $carousel = $('#supersize');
					
					// initialize cycle
					$carousel.cycle({
						fx : 'scrollHorz',
						easing : 'easeInOutCubic',
						timeout : 5500,
						//fit: 0,
	    				//containerResize: 0,
						delay: 6000,
						//timeout : 6000,
						speed : 2000,
						before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
							//resizeSlide();
							$(nextSlideElement).resizenow();
							//alert(nextSlideElement.className);
							//$carousel.data('isChanging', true);
						},
						after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
							//resizeSlide();
							//$('#supersize').resizenow();
							$(nextSlideElement).resizenow();
							//carousel.data('isChanging', false);
						}
						
					});
					
					// define controls
					var btn_prev = $('.featured a.arw-prev');
					var btn_next = $('.featured a.arw-next');
					
					btn_prev.click(function(e) {
						e.preventDefault();
						if (!$carousel.data('isChanging')) {
							$carousel.cycle.prev( $carousel.data('cycle.opts') );
						}
						$carousel.cycle('pause');
					});
			
					btn_next.click(function(e) {
						e.preventDefault();
						if (!$carousel.data('isChanging')) {
							$carousel.cycle.next( $carousel.data('cycle.opts') );
						}
						$carousel.cycle('pause');
					});
					

				},

				// THIS IS THE CONTENT THAT SLIDES/CHANGES WITH THE BG CAROUSEL
				featureCarousel: function(){
					var $carousel = $('#featured-info');

					// initialize cycle
					$carousel.cycle({
						fx : 'fade',
						easing : 'easeInOutCubic',
						timeout : 5500,
						//timeout : 6000,

						speed : 3000,
						before: function(currSlideElement, nextSlideElement, options, forwardFlag){
							$carousel.data('isChanging', true);
						},
						after: function(currSlideElement, nextSlideElement, options, forwardFlag){
							$carousel.data('isChanging', false);
						}
					});

					// define controls
					var btn_prev = $('.featured a.arw-prev');
					var btn_next = $('.featured a.arw-next');

					btn_prev.click(function(e){
						e.preventDefault();
						if (!$carousel.data('isChanging')){
							$carousel.cycle.prev( $carousel.data('cycle.opts') );
						}
						$carousel.cycle('pause');
					});

					btn_next.click(function(e){
						e.preventDefault();
						if (!$carousel.data('isChanging')){
							$carousel.cycle.next( $carousel.data('cycle.opts') );
						}
						$carousel.cycle('pause');
					});

				}

			},

			schoolHome: {
				init: function(){
					//alert('2');
					ALVIN.widgets.accordion.init();
					//ALVIN.widgets.stretchBg.init();
				}
			},

			bioPage: {
				init: function(){
					ALVIN.widgets.accordion.init();
					ALVIN.widgets.showMore.init();
					ALVIN.widgets.mediaCarousel.init();
				}
			},

			listingPage: {
				init: function(){
					ALVIN.widgets.accordion.init();

				}
			},

			repertoryDetailPage: {
				init: function(){
					ALVIN.widgets.tabs.init();
					//ALVIN.widgets.mediaCarousel.init();

				}
			},


			aileyTimeline: {
				init: function(){
					
					ALVIN.widgets.mediaCarousel.init();
					
				}
			},
			
			aileyCampaign: {
				init: function(){
					
					//ALVIN.widgets.mediaCarousel.init();
					
				}
			},
			
			
			articleAdmissions: {
				init: function(){
					ALVIN.widgets.accordion.init();
					//ALVIN.widgets.mediaCarousel.init();
					
				}
			},	
			
			aboutPage: {
				init: function(){
					ALVIN.widgets.accordion.init(); 
					//ALVIN.widgets.mediaCarousel.init();
					
				}
			},	
			
			searchResults: {
				init: function(){
					
					//ALVIN.widgets.mediaCarousel.init();
					
				}
			},
			
			spaceRental: {
				init: function(){
					ALVIN.widgets.mediaCarousel.init();
					//ALVIN.widgets.mediaCarousel.init();
					
				}
			}
			
		} // END: pages

	}; // END ALVIN global var

	$(function() {
		// check browser
		try { ALVIN.utils.checkBrowser.init(); } catch(e) {}

		// activate nav
		try { ALVIN.pages.global.nav(); } catch(e) {}
				
		try { ALVIN.pages.global.resetButtons(); } catch(e) {}
		try { ALVIN.widgets.tabs.init(); } catch(e) {}
		try { ALVIN.widgets.accordion.init(); } catch(e) {}
		try { ALVIN.widgets.showMore.init(); } catch(e) {}
		//try { ALVIN.widgets.lightBox.init(); } catch(e) {}

		try {
			// INITIATE PLUGIN FOR TRUNCATION
			var theTarget = $('.teaser .post-summary .node-content ');
			theTarget.jTruncate({
				length: 150,
				minTrail: 20,
				moreText: "More",
				lessText: "Less",
				ellipsisText: "...",
				moreAni: "",
				lessAni: ""
			});					
		}
		catch(e) {}
		try {
			$('span.playBtn, .video-link').live('click', function(e){
				e.preventDefault();
				if($(this).parents('.media-item').find('.more-less').length > 0){
					$(this).parents('.media-item').find('.more-less').trigger('click');
				} else {
					$(this).parents('div.media-item').find('.media-feature a').toggle('fast');
					$(this).parents('div.media-item').find('.video-clip').toggle('normal');
				}
			});
		}
		catch(e) {}

		
		try { ALVIN.widgets.mediaCarousel.init(); } catch(e) {}

		// actiavte input clear functions
		try { ALVIN.utils.inputClear.init(); } catch(e) {}

		// Activate PNG fix - keep this last
		try { ALVIN.utils.fixPng.init(); } catch(e) {}
	});
	
	// target=_blank 4 footer links 
	$(document).ready(function(){
		$("#primary-footerNav a").click(function(){ window.open(this.href); return false;}); 
	});
	
	
