jQuery(function() {


	//Sort on the vacancy tables
	jQuery("#job-table").tablesorter({
	// pass the headers argument and assing a object 
		headers: { 
			// assign the first column (we start counting zero) 
			4: { 
				// disable it by setting the property sorter to false 
				sorter: false 
			}
		}
	});

	jQuery('#employer-links').listnav();

	//Sets up backing on the forms when an item is selected
	jQuery('form > p > span > input, form > p > span > textarea, form > p > span > select').focus(function(){
	    jQuery(this).parents('p').addClass("over");
	}).blur(function(){
	    jQuery(this).parents('p').removeClass("over");
	});
	
	
	// Sub navigation show/hide	
	jQuery('#navigation>li').hoverIntent(function() {
		// Fade in the subnav list
		jQuery(this).find("ul").fadeIn("normal");
		
		// Fix subnav width
		var navWidth = jQuery(this).parent().width() -2;
		jQuery(this).find("ul").width(navWidth);
		
	}, function() {
		var navClass = jQuery(this).attr("class");
		
		// Unless this is subnav for the current page then fade it out
		if(navClass.indexOf("current_page_item") == -1 && navClass.indexOf("current_page_parent") == -1 && navClass.indexOf("current-cat") == -1 && navClass.indexOf("current-cat-parent") == -1) {
			jQuery(this).find("ul").fadeOut("normal");
		}
	});
	
	// Image preload
	if(document.images)
	{
		var image_array = new Array();
		
		// Array of images
		image_array[0] = "http://www.opportunities.co.uk/wp-content/themes/opportunities/images/nav_link_hover.gif";
		image_array[1] = "http://www.opportunities.co.uk/wp-content/themes/opportunities/images/up-arrow.png";
		image_array[2] = "http://www.opportunities.co.uk/wp-content/themes/opportunities/images/down-arrow.png";
		
		var preload_image = new Array ();
	 
		for(var i=0; i<image_array.length; i++)
		{
			preload_image[i]= new Image();
	    	preload_image[i].src = image_array[i];
		}
	}
	
	// Advert image hover
	var imgHeight
	var imgWidth
	jQuery("#top_ad img, #left_ad img, #right_ad img, #bottom_ad img").hover(function() {
		//If we haven't got a height or width set it
		if(!jQuery(this).data("height") || !jQuery(this).data("width")) {
			jQuery(this).data("height", jQuery(this).height());
			jQuery(this).data("width", jQuery(this).width());
		}
		
		// Add a higher z-index value so this image stays on top 
		jQuery(this).parent().css({'z-index' : '10'});
		// Add class of "hover", then stop animation queue buildup
		jQuery(this).addClass("hover").stop()
			.animate({
			/*
				// Vertically align the image
				marginTop: -(jQuery(this).data("height")+20)/2,
				marginLeft: -(jQuery(this).data("width")+20)/2,
				top: '50%',
				right: '50%',
			*/
				// Set new width
				width: jQuery(this).data("width")*1.15,
				// Set new height
				height: jQuery(this).data("height")*1.15
			}, 200);
	} , function() { // On hover out...
		// Set z-index back to 0
		jQuery(this).parent().css({'z-index' : '0'});
		// Remove the "hover" class , then stop animation queue buildup
		jQuery(this).removeClass("hover").stop()
			.animate({
			/*
				// Set alignment back to default
				marginTop: '0',
				marginLeft: '0',
				top: '0%',
				right: '0%',
			*/
				// Set width back to default
				width: jQuery(this).data("width"),
				// Set height back to default
				height: jQuery(this).data("height")
			}, 400);
	});
	
});


/**
 * Splits lists into two columns.
 */
jQuery(document).ready(function() {
     jQuery('.splitcol').each(function() {
          if(jQuery(this).is("ol")) { var ordered = true; }
          
          var colsize = Math.round(jQuery(this).children("li").size() / 2);
          
          jQuery(this).children("li").each(function(i) {
               if (i>colsize) {
                    jQuery(this).addClass('right_col');
               }
          });
          
          if(ordered) {
               jQuery(this).find('.right_col').insertAfter(this).wrapAll("<ol class='splitcol' start='" + (colsize+1) + "'></ol>").removeClass("right_col");
          } else {
               jQuery(this).find('.right_col').insertAfter(this).wrapAll("<ul class='splitcol'></ul>").removeClass("right_col");
          }
     });
});




/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

jQuery.fn.equalHeights = function(px) {

	jQuery(this).each(function(){
		var currentTallest = 0;
		jQuery(this).children().each(function(i){
			if (jQuery(this).height() > currentTallest) { currentTallest = jQuery(this).height(); }
		});
		// for ie6, set height since min-height isn't supported
		if (jQuery.browser.msie && jQuery.browser.version == 6.0) { jQuery(this).children().css({'height': currentTallest}); }
		jQuery(this).children('not:.clear').css({'min-height': currentTallest});
		jQuery(this).children().children('.contentBoxContent').css({'min-height': currentTallest-20});		
		
	});
	return this;
};

jQuery(document).ready( function() {	
	//Set equal heights	
	jQuery('.equal').equalHeights();
});


jQuery(window).resize(function() {
	console.info(jQuery('.equal').children('.contentBox').children().css('min-height', '0'));
	jQuery('.equal').equalHeights();	
});

