
  function btnPrint_onClick(src){
  printWin = window.open(src, "_blank","height=800,left=100,top=100,width=800,toolbar=no,titlebar=0,status=0,menubar=yes,location= no,scrollbars=1");
  printWin.print();
  }

jQuery(function() {

	// This expands a select input to show all text (IE)
	if(jQuery.browser.msie) {
	    jQuery(".width-adjust-ie select").mousedown(function(){
	            jQuery(this).css("width","auto");
	    });
	    jQuery(".width-adjust-ie select").change(function(){
	            jQuery(this).removeAttr("style");
	    });
	    jQuery(".width-adjust-ie select").blur(function(){
	            jQuery(this).removeAttr("style");
	    });
	}


	// Fix to remove dark borders from buttons of active forms (IE)
	if (jQuery.browser.msie) {
		jQuery('input.button').wrap('<span class="button-wrap" />');
	}

	// Jquery datepicker
	jQuery('#datepicker').datepicker({onSelect: setDate,
	dateFormat: 'yy/mm/dd'
	}
	);
	
	
	if (jQuery("#content_1_ListFilter_hdnDate").val() != '')
	{
        jQuery('#datepicker').datepicker("setDate", new Date(jQuery("#content_1_ListFilter_hdnDate").val()) );
    }

	function setDate(date) { 
jQuery("#content_1_ListFilter_hdnDate").val(date);

jQuery("#content_1_ListFilter_btnCalendarChange").click();
}

	// Fancy box light-box calls
	jQuery("a.zoom").fancybox();

	jQuery("a.zoom1").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#FFF'
	});

	jQuery("a.zoom2").fancybox({
		'zoomSpeedIn'		:	500,
		'zoomSpeedOut'		:	500,
		'overlayShow'		:	false
	});

	jQuery.fn.vAlign = function() {

	    return this.each(function(i) {

	        var h = jQuery(this).height();
	        var oh = jQuery(this).outerHeight();
	        var mt = (h + (oh - h)) / 2;
	        jQuery(this).css("margin-top", "-" + mt + "px");
	        jQuery(this).css("top", "50%");
	        jQuery(this).css("position", "absolute");

	    });

	};





	jQuery.fn.hAlign = function() {

	    return this.each(function(i) {

	        var w = jQuery(this).width();
	        var ow = jQuery(this).outerWidth();
	        var ml = (w + (ow - w)) / 2;
	        jQuery(this).css("margin-left", "-" + ml + "px");
	        jQuery(this).css("left", "50%");
	        jQuery(this).css("position", "absolute");

	    });

	};




	// Tabs
    var tabContainers = jQuery('div.tab-window > div');
    
    jQuery('div.tabs ul.tab-navigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();
        
        jQuery('div.tabs ul.tab-navigation a').removeClass('selected');
        jQuery(this).addClass('selected');
        
        return false;
    });//.filter(':first').click();

	// Discovery
    var discoveryPanels = jQuery('#discovery-window > .panel');
    
    jQuery('#discovery-nav a').click(function () {
    
    var index = jQuery("#discovery-nav a").index(this);

        discoveryPanels.hide();
        jQuery("#discovery-window > div:eq(" + index + ")").show();
        
        jQuery('#discovery-nav a').removeClass('selected');
        jQuery(this).addClass('selected');
        
        return false;
    });//.filter(':first').click();
    
    

	// Initiate homepage accordion

	jQuery('#accordion div').hide();
	jQuery('#accordion div.default').show();
	jQuery('#accordion div.default').prev().find('a').addClass('open');
	jQuery('#accordion a').click(
		function() {
			var checkElement = jQuery(this).parents('h3').next();
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				checkElement.slideUp('normal');
			    jQuery(this).removeClass('open');
			    return false;
			}
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				jQuery('#accordion div:visible').slideUp('normal');
				
				jQuery('#accordion div:visible').prev().find('a').removeClass('open');
				jQuery(this).addClass('open');
				       
				checkElement.slideDown('normal');
				return false;
			}
		}
	);


	// Homepage slide-show script

	jQuery('#slide-show p a .window').css('display','none');
	jQuery('#slide-show p a:first').addClass('on').find('.window').fadeIn('slow');
	jQuery('#slide-show').removeClass('clean');

	var slide_count;
	var slide_interval;
	var old_slide = 0;
	var current_slide = 0;
	 
	slide_count = jQuery("#slide-show a").size();
	
	slide_interval = setInterval(slide_rotate,7000);
	
	function slide_rotate() {
		current_slide = (old_slide + 1) % slide_count; 
		showWindow(current_slide);
		old_slide = current_slide;
	}

	function showWindow(current_slide){
		jQuery('#slide-show p a').not(this).removeClass("on").find('.window').fadeOut('slow');
		jQuery("#slide-show a:eq(" + current_slide + ")").addClass("on").find('.window').fadeIn('slow');
	};

	jQuery("#slide-show p a").hoverIntent({
		sensitivity: 3, 
		interval: 50, 
		over: pauseShow, 
		timeout: 50
	});
	
	function pauseShow() {
		clearInterval(slide_interval);
		var hoveredItem = jQuery("#slide-show a").index(this);
		showWindow(hoveredItem);
	}




	// Overlabel script - show label over input

	jQuery.fn.overlabel = function() {
	    this.each(function() {
	        var jQuerylabel = jQuery(this),
	            jQueryinput = jQuery('#' + jQuerylabel.attr('for'));
	 
	        jQuerylabel
	            .addClass('overlabel-apply')
	            .bind('click', function(event) {
	                jQueryinput.focus();
	            });
	 
	        jQueryinput
	            .bind('focus blur', function(event) {
	                jQuerylabel.css('display', (event.type == 'blur' && !jQueryinput.val() ? '' : 'none'));
	            }).trigger('blur');
	    });
	};

    jQuery("label.overlabel").overlabel();

	
	
	// Drop down section navigation
	
	/*   HOVER INTENT 	*/
	function addMega(){
		jQuery(this).children('div').show(); //fadeIn(100); //addClass("hovering");
	}
	
	function removeMega(){
		jQuery(this).children('div').hide(); //fadeOut(100); //removeClass("hovering");
	}
	
	var megaConfig = {
	interval: 50,
	sensitivity: 4,
	over: addMega,
	timeout: 50,
	out: removeMega
	};
	
	jQuery('#section-navigation li').hoverIntent(megaConfig);

		
	// add class if nested list exists, css draws arrow
	jQuery('#section-navigation ul li').find('div').each(function(){
		if (jQuery(this).children('ul').length > 0) {
			jQuery(this).prev('a').addClass('dropdown');
		};
	});
	
	/*jQuery('#section-navigation li').hover(
	  function() { 
	    //jQuery(this).find('div').slideDown();
	    jQuery(this).find('div').css({'display' : 'block'});
	  },
	  function() { 
	    jQuery(this).find('div').css({'display' : 'none'});
	  }
	);	*/

	/* On focus styling for forms */
	
	jQuery("form.standard input:text").focus(function () {
         jQuery(this).css({'background-color' : '#FFF6DF'});
    });	

	jQuery("form.standard input:text").blur(function () {
         jQuery(this).css({'background-color' : '#ffffff'});
    });

	jQuery("form.standard textarea").focus(function () {
         jQuery(this).css({'background-color' : '#FFF6DF'});
    });		
	
	jQuery("form.standard textarea").blur(function () {
         jQuery(this).css({'background-color' : '#ffffff'});
    });	
    
    /* Datepicker widget for forms */
    
    jQuery(function() {
		jQuery(".datepicker").datepicker();
	}); 


	// Expanding left column navigation

	jQuery.fn.quickTree = function() {
	    return this.each(function(){
		
			//set variables
	        var jQuerytree = jQuery(this);
	        var jQueryroots = jQuerytree.find('li');
	        
	        jQuerytree.addClass('tree');
	        jQuerytree.find('ul').hide();
			
			//iterate through all list items
	        jQueryroots.each(function(){
			
				//if list-item contains a child list
	            if (jQuery(this).children('ul').length > 0) {
				
					//add expand/contract control
	                jQuery(this).addClass('root').prepend('<span class="expand" />');
					
	            }
	            
	        }); //end .each
	        
	        jQuery('span.expand').toggle(function(){
	                jQuery(this).toggleClass('contract').nextAll('ul').slideDown(100);
	            },
				//if it's clicked again, find all child lists and contract
	            function(){
	                jQuery(this).toggleClass('contract').nextAll('ul').slideUp(100);
	            }
	        );
	        
	        jQuery('.active').children('span.expand').click();
	                
	    });
	};
	
	jQuery('ul#page-navigation').quickTree();
	jQuery('ul#sitemap').quickTree();	






// Text resize tool


 // Reset Font Size
  var currentFontSize = 16;
    jQuery(".resetFont").click(function(){
    jQuery('html').css('font-size', 16);
  });
  // Increase Font Size
  jQuery("#text-plus").click(function(){
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum+1;
    jQuery('html').css('font-size', newFontSize);
    currentFontSize = newFontSize;
    return false;
  });
  // Decrease Font Size
  jQuery("#text-minus").click(function(){
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum-1;
    jQuery('html').css('font-size', newFontSize);
    currentFontSize = newFontSize;
    return false;
  });



  /* Collection photo slideshow initiaslise */
  
  jQuery("#collection-image-wrapper img").vAlign();
  jQuery("#collection-image-wrapper img").hAlign();

  /* Some dodgy js for the prototype, this will need fixing to work with vernon */

  jQuery('#pic-2').css('display','none');

  jQuery('#thumb-1').click(function () {
	
	jQuery('#pic-2').fadeOut();
	jQuery('#pic-1').fadeIn();

  });
  
  jQuery('#thumb-2').click(function () {
	
	jQuery('#pic-1').fadeOut();
	jQuery('#pic-2').fadeIn();

  });


	// ifSrc ads a #museum-name to the end of iframe src (Collections Online)
	
	function ifSrc()
		{
			var full = window.location.host;
			var parts = full.split('.');
			var sub = parts[0];
			return jQuery('#vernon-content').attr('src') + '#' + sub;
		}
	
	jQuery('#vernon-content').attr('src',ifSrc());

// Add external link icon to links with target=_blank
	jQuery("a[target*='_blank']").addClass('external-link').after('<img src="/images/template/icons/external.png" alt="External link" class="external-link-icon" />');


});












