jQuery(document).ready(function() {

//	jQuery("#photo").fadeIn('fast');

	// beta only
	// jQuery("a:not([hrefjQuery='?sendthrough']||[href^='https://beta']||[href^='http://beta']||[href^='/']||[href^='#'])").attr("href","http://beta.wheatoncollege.edu/web/edge").addClass("iframe edge");
	
	//jQuery("div#tagline div.connection div.related div.content a:not([hrefjQuery='?sendthrough'])").attr("href","http://beta.wheatoncollege.edu/web/making-connections/");
	
	// prep images for fancybox
	var thumbnails = 'a:has(img)[hrefjQuery=".bmp"],a:has(img)[hrefjQuery=".gif"],a:has(img)[hrefjQuery=".jpg"],a:has(img)[hrefjQuery=".jpeg"],a:has(img)[hrefjQuery=".png"],a:has(img)[hrefjQuery=".BMP"],a:has(img)[hrefjQuery=".GIF"],a:has(img)[hrefjQuery=".JPG"],a:has(img)[hrefjQuery=".JPEG"],a:has(img)[hrefjQuery=".PNG"]';
	jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox");

	jQuery("a:has(img)").addClass("link_image");
	
	jQuery("a.fancybox").fancybox();
	
	jQuery(document).keypress(function(e) { 
	    if (jQuery(e.target).is('input, textarea')) {
	        // event invoked from input or textarea
	    } else { 
	    	switch(e.which){ 
            case 96:
            	// backtick clicked
            	jQuery("a.quicklinks").trigger('click'); 
            break; 
            
           // case 105:
            	// i clicked
           // 	window.location = jQuery("a.clickinsidewheaton").attr("href");
           // break; 
            
           // case 119:
            	// w clicked
           // 	window.location = jQuery("a.clickwebmail").attr("href");
           // break; 
            
            case 47:
            	// / clicked
            	window.location = jQuery("a.clickhome").attr("href");
            break; 

	    default: ;
            
	    }  }      
	});

	// Fancybox for Quicklinks
	jQuery("a.quicklinks").fancybox({
		'frameWidth' : 800,
		'frameHeight': 400,
		'enableEscapeButton' : true,
		'overlayShow' : true,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,
		'zoomSpeedIn' : 1,
		'overlayOpacity' : .6,
		'showCloseButton' : true
	});	
	
	// Fancybox for Report a problem (404)
	jQuery("a.problemreport").fancybox({
		'frameWidth' : 800,
		'frameHeight': 700,
		'enableEscapeButton' : true,
		'overlayShow' : true,
		'hideOnOverlayClick' : true,
		'hideOnContentClick' : false,
		'zoomSpeedIn' : 200,
		'overlayOpacity' : .6,
		'showCloseButton' : true
	});	


	// Quickaccess
	if(jQuery.fn.quickaccess) { // if quickaccess.js is included

// Quick Access for Search
	var query = jQuery('#search_query');
	if(!query.val()) {
		query.attr('autocomplete','off').val('').one('focus',function() {
			jQuery(this).val('');
//			jQuery('#search').append('<div id="qa_results"/>');

//			jQuery.get('/assets/scripts/quicklinks-internal.html',function(data) {
                      jQuery.get('/assets/scripts/quicklinks_real_links.html',function(data) {
//			jQuery.get('/assets/scripts/quicklinks.html',function(data) {

				jQuery('body').append(data);
		jQuery('#search_query').quickaccess({selector:'#example ul li a',maxResults:15,focus:false,forceSelect:false,sort:true,duplicates:false}); // initialize in the search query field
		jQuery('#qa_results').removeClass('qa_blur');
			});
		});
	}



	}
	// Homepage taglines and People Quilt
	if(jQuery('body').is('#homepage')) {
		jQuery('body').click(function(e) { // when clicking the body
			var target = jQuery(e.target);
			if(target.is('.blurb .close')||!target.closest('.blurb').length) { // if we're not clicking inside a quilt bubble
				jQuery('#quilt li').removeClass('open').find('.blurb').stop().height('auto').hide(); // close all the quilt boxes
			}
			if(target.is('.related .close')||!target.closest('.related').length) { // if we're not clicking inside a connections bubble
				jQuery('#tagline .connection').removeClass('open').find('.related').stop().height('auto').hide(); // close all the connections boxes
			}
			if(target.is('.close')) return false;
		});
		jQuery('#quilt .blurb,#tagline .related').prepend('<a href="#" class="close">Click to close</a>');
		jQuery('#quilt li>a,#tagline .connection>a').click(function(e) {
			var item = jQuery(this).parent().toggleClass('open'); // toggle the popup
			jQuery('#quilt li,#tagline .connection').not(item).removeClass('open').find('.blurb,.related').stop().hide(); // and hide all the other popups
			if(jQuery.browser.msie&&jQuery.browser.version==7&&item.is('.connection')) {
				jQuery.fx.off = true;
			}
			item.find('.close').hide();
			item.find('.blurb,.related').show().hide().css('opacity',0).animate({opacity:1,height:'show'},500,function() {
				if(jQuery.browser.msie) {
					jQuery(this).css('opacity','');
					jQuery(this).find('.close').show();	
				} else jQuery(this).find('.close').fadeIn(600);
				jQuery.fx.off = false;
			});
			return false; // cancel the click and prevent bubbling
		});
	}
	// Sidebar quilt
	jQuery('#sidebar #quilt .description').wrapInner('<div class="description_text"/>');
	// Switchers
	jQuery('.switcher>h4>a').click(function() { // when clicking a switcher
		var switcher = jQuery(this).parent().parent();
		switcher.toggleClass('active') // toggle the active class
			.find('.contents').slideToggle(200); // and show the contents
		if(switcher.is('.active')) { // if activating
			jQuery('<div id="whiteout"/>').prependTo('body') // add a whiteout overlay
				.one('click',function() { // which, when clicked
					switcher.find('>h4>a').click(); // is the same as clicking the switcher
				});
		} else { // if deactivating
			jQuery('#whiteout').remove(); // remove the whiteout overlay
		}
		return false; // cancel the original click
	});
});
