
jQuery(document).ready(function($){
	
	/*
	 * jquery.flexislider.js v0.1 - jQuery script
	 * Copyright (c) 2009 Barry Roodt (http://calisza.wordpress.com)
	 *
	 * Licensed under the New BSD license.
	 *
	 * This script slides a list of images from right to left across the window.
	 * An example can be found at http://flexidev.co.za/projects/flexislider
	 * Please check http://code.google.com/p/flexidev/downloads/ for the latest version
	 *
	 */
	
	// Adapted by Mark James 2/6/2011 for Crane Services
	// Adapted the adapted version; Darren Bayliss <darren.bayliss@matrix.co.uk> 02/06/2011 15:18 for Mark James :-)
	var speed = 10;
	var pic, numImgs, arrLeft, i, totalWidth, n, myInterval; 
	
	pic = $("#linkScroller").find("li"); //selects what to scroll
	numImgs = $("#linkScroller li").size();
	arrLeft = new Array(numImgs);
	
	$.fn.flexiScroll = function() { 
		for (i=0;i<numImgs;i++){
				arrLeft[i] -= 1;
			
				if (arrLeft[i] == -($(pic[i]).width())){
					totalWidth = 0; 
					for (n=0;n<numImgs;n++){
						if (n!=i){  
							totalWidth += $(pic[n]).width();
						}
					}   
					arrLeft[i] =  totalWidth;
				}
				$(pic[i]).css("left",arrLeft[i]);
			}
	}

	for (i=0;i<numImgs;i++){
		
		totalWidth=0;
		for(n=0;n<i;n++){
			totalWidth += $(pic[n]).width();
		}
		
		arrLeft[i] = totalWidth;
		$(pic[i]).css("left",totalWidth);
	}
	
	myInterval = setInterval($().flexiScroll,speed);
	//$('#imageloader').hide();
	$(pic).show();






	// rollover function home page services navigation
	/**/
	$(function(){
		$('#servNav #linkBox .servNavLink a')
			.css( {opacity:1} ) //default
			
			//rollover animation
			.mouseover(function(){
				$(this).stop().animate(
				{opacity:0.5}, 
				{duration:400})
			})
			
			//rollout animation
			.mouseout(function(){
				$(this).stop().animate(
				{opacity:1}, 
				{duration:400})
			})
	});
	
	
	// rollover function form buttons
	/**/
	$(function(){
		$('form .button, form .sendbutton, .form-submit #submit')
			.css( {opacity:0.5} ) //default
			
			//rollover animation
			.mouseover(function(){
				$(this).stop().animate(
				{opacity:1}, 
				{duration:400})
			})
			
			//rollout animation
			.mouseout(function(){
				$(this).stop().animate(
				{opacity:0.5}, 
				{duration:400})
			})
	});
	
	
	
	// rollover function for main navigation
	/**/
	$(function(){
		//standard rollover
		$('#mainNav ul li a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 -100px"}, 
				{duration:400})
			})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 0"}, 
				{duration:400})
			})
			
		//selected - stops rollout animation	
		$('li.current-page-item a, li.current-menu-item a')
		.css( {backgroundPosition: "0 -100px"} )
		
			.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 -100px"}, 
				{duration:400})
			})
	});
	
	
	// rollover function for sub navigation
	/**/
	$(function(){
		//standard rollover
		$('.subNav li a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 -100px"}, 
				{duration:400})
			})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 0"}, 
				{duration:400})
			})
			
		//selected - stops rollout animation	
		$('.subNav li.current-page-item a, .subNav li.current-menu-item a')
		.css( {backgroundPosition: "0 -100px"} )
		
			.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 -100px"}, 
				{duration:400})
			})
	});
	
	//correcting form styles
		//find checkboxes
		$('form input:checkbox').css('width', 'auto');
		//find radio buttons
		$('form input:radio').css('width', 'auto');
			
});

