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");
          }
     });
});
