(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","hidden");
		});
	}
})(jQuery);

$(function() {

	$(".learning_pathway_video a").click(function() {
		$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'width'			: 640,
			'height'		: 360,
			'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?autoplay=1&clip_id=$1'),
			'type'			: 'swf'
		});

		return false;
	});


	$('.accordian > li > h3 > a').click(function() {
		var $this = $(this);
		$this.parent('h3').parent('li').children('div').slideToggle('fast');
		$this.toggleClass(function() {
		  if ($(this).is('.active')) {
		    return false;
		  } else {
		    return 'active';
		  }
		});
	});
	
	$('.fade').innerfade({
		speed: 'slow',
		timeout: 4000,
		type: 'sequence',
		containerheight: '171px'
	});
	
	$("#google_map").gMap({ 
		latitude:               54.12564502925476,
		longitude:              -3.2175135612487793,
		controls: false,
		scrollwheel: false,
		markers: [
			{ 
				latitude: 54.120489,
				longitude: -3.212664,
				popup: true,
				html: '<p>South Site</p>'
			},
			{
				latitude: 54.129882,
				longitude: -3.221912,
				popup: true,
				html: '<p>North Site</p>'
			}
		],
		zoom: 13,
		maptype: G_HYBRID_MAP,
		icon:
		{
	        image:              "/images/icons/map.png",
	        shadow:             false,
	        iconsize:           [32, 32],
	        shadowsize:         false,
	        iconanchor:         [4, 19],
	        infowindowanchor:   [8, 2]
	    }
	});

	$('.half li').equalHeights();
	
    $(".jumpmenu").change(function() {
      	var val =  $("option:selected", this).val();
        if (val != '') {
            location.href=val;
        }
    });
	
	$('#slider').anythingSlider({
	  // Appearance
	  width               : 1038,      // Override the default CSS width
	  height              : 480,      // Override the default CSS height
	  resizeContents      : true,      // If true, solitary images/objects in the panel will expand to fit the viewport

	  // Navigation
	  startPanel          : 1,         // This sets the initial panel
	  hashTags            : true,      // Should links change the hashtag in the URL?
	  buildArrows         : true,      // If true, builds the forwards and backwards buttons
	  buildNavigation     : true,      // If true, buildsa list of anchor links to link to each panel
	  navigationFormatter : null,      // Details at the top of the file on this use (advanced use)
	  forwardText         : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
	  backText            : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)

	  // Slideshow options
	  autoPlay            : true,      // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
	  startStopped        : false,     // If autoPlay is on, this can force it to start stopped
	  pauseOnHover        : false,      // If true & the slideshow is active, the slideshow will pause on hover
	  resumeOnVideoEnd    : true,      // If true & the slideshow is active & a youtube video is playing, it will pause the autoplay until the video has completed
	  stopAtEnd           : false,     // If true & the slideshow is active, the slideshow will stop on the last page
	  playRtl             : false,     // If true, the slideshow will move right-to-left
	  startText           : "Start",   // Start button text
	  stopText            : "Stop",    // Stop button text
	  delay               : 6000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
	  animationTime       : 1000,       // How long the slideshow transition takes (in milliseconds)
	  easing              : 'easeInOutQuart'	   // Anything other than "linear" or "swing" requires the easing plugin
	});
	
	$('.block_link a').click(function(event) {
		event.stopPropagation();		
	}).each(function() {
		var $this = $(this);
		$this.closest('.block_link').click(function() {
			document.location = $this.attr('href');	
			return false;
		});
	});
	
	$('#nav_categories a').click(function(event) {
		event.stopPropagation();		
	}).each(function() {
		var $this = $(this);
		$this.closest('li').click(function() {
			document.location = $this.attr('href');	
			return false;
		});
	});
	
	$('#main_navigation ul').superfish({
		autoArrows: false
	});
	
	$('.fancybox').fancybox();
	
});
