//*******************************************************************************************
//		GENERAL FUNCTIONS
//*******************************************************************************************

// Dropdown enabler for older browsers not supporting :hover on arbitrary elements
// http://htmldog.com/articles/suckerfish/dropdowns/

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



jQuery(document).ready(function($) {

// Function to swap two classes
$.fn.swapClass = function(c1, c2){
    return this.each(function(){
        var t = $(this);
        (!t.is('.'+c1)) ? 
            t.addClass(c1).removeClass(c2) : t.addClass(c2).removeClass(c1);
    });
}

// Fix IE not responding to change events on radio buttons:
// http://norman.walsh.name/2009/03/24/jQueryIE
$(function() {
    if ($.browser.msie) {
        $('input:radio').click(function () {
            this.blur();
            this.focus();
        });
    }
});
	
// New Windows
$('a.newwindow').bind('click',function(){
    window.open(this.href);
    return false;
});

// Close jQuery object
});
 
//*******************************************************************************************
//		TOGGLES: INDEX ARCHIVES
//*******************************************************************************************

jQuery(document).ready(function($){
	$('#navside .toggle ul').hide();
	$('#navside .toggle h4').toggle(
    	function(){
			$(this).next('ul').slideDown('fast');
			return false;		
    	},
    	function() {
			$(this).next('ul').slideUp('fast');
			return false;		
    	}
    );
});

jQuery(document).ready(function($){
	$('#navside .active ul').show();
	$('#navside .active h4').toggle(
    	function(){
			$(this).next('ul').slideUp('fast');
			return false;		
    	},
    	function() {
			$(this).next('ul').slideDown('fast');
			return false;		
    	}
    );
});

//*******************************************************************************************
//		TOGGLES: MORE NEWS OR ARTICLES
//*******************************************************************************************

/*jQuery(document).ready(function($){
	$('#sidebar .toggle ul').hide();
	$('#sidebar .toggle span').toggle(
    	function(){
			$(this).next('ul').slideDown('fast');
			return false;		
    	},
    	function() {
			$(this).next('ul').slideUp('fast');
			return false;		
    	}
    );
});*/

$(document).ready(function(){
	
	// Hide Toggle
	$(".news-toggle").hide();
	
	
	
	$('.toggle-trigger').click(function() {
    $('.news-toggle').slideToggle(400);
    $(this).text($(this).text() == 'see the latest 3' ? 'see the latest 10' : 'see the latest 3'); // <- HERE
    return false;
	});


});


	
//*******************************************************************************************
//		GALLERY CYCLER AND CAROUSEL
//*******************************************************************************************

jQuery(document).ready(function($){
   
	// Slideshow panel -- images swapped when clicked in the thumbs carousel
   $('#logos').cycle({
		fx:			'scrollLeft',
		speed:		300,
		timeout:	0,
		next:		'#next',
		prev:		'#prev',
		pause:		0,
		autostop:	0
   });
});

//*******************************************************************************************
//		BASKET PAGE FUNCTIONS
//*******************************************************************************************

$(document).ready(function(){

	//Hide (Collapse) the delegates on load
	$(".delegates").hide();
	
	$('.delegate-toggle').click(function() {
		
		$(this).next(".delegates").slideToggle("fast");
		
		//$(this).html("Hide Delegates");

		
	});
	
	$('.delegate-toggle').toggle(function (){
    
		$(this).html("hide delegates");

		}, function(){
    	$(this).text("view delegates")
		
	});


});

//*******************************************************************************************
//		Form Validation
//*******************************************************************************************

$(document).ready(function(){

	$("#contact-form").validate();
	$("#advanced_Search").validate();
	$("#commentform").validate();
	$("#calculator").validate();
	$("#billing_details_form").validate();

});

//*******************************************************************************************
//		Fancy Box Settings
//*******************************************************************************************
$(document).ready(function() {
	$(".fancybox").fancybox({
			/*'padding'			: 0,*/
			'autoScale'			: false,
			'width'				: '800',
			'height'			: '800',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
	});					   
});


//*******************************************************************************************
//		Clear Inputs on focus
//*******************************************************************************************

$(document).ready(function(){

	var clearMePrevious = '';
	
	// clear input on focus
	$('.clearMeFocus').focus(function(){
if($(this).val()==this.defaultValue){
$(this).val('');
}
});

// if field is empty afterward, add text again
$('.clearMeFocus').blur(function(){
if($(this).val()==''){
$(this).val(this.defaultValue);
}
});
});

//*******************************************************************************************
//		Accordian setting
//*******************************************************************************************

$(document).ready(function(){

	jQuery('#learning_and_development').accordion({
		autoheight: false,
		/*active: '.selected',
		selectedClass: 'active',*/
		animated: 'easeslide',
		header: "h2"
	});

});

//*******************************************************************************************
//		Homepage Carousel
//*******************************************************************************************

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#carousel').jcarousel({
        auto: 2,
        wrap: 'last',
		visible: 4,
        initCallback: mycarousel_initCallback
    });
});

