// Fades between images using Jquery. Borrowed from jonraasch.com

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 800, function() {
            $active.removeClass('active last-active');
        });
}


$(function() {
    setInterval( "slideSwitch()", 3000 );
});

  
$.fn.clearForm = function() {
	return this.each(function() {
    	var type = this.type, tag = this.tagName.toLowerCase();
	    if (tag == 'form')
			return $(':input',this).clearForm();
	    if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
	    else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
	    else if (tag == 'select')
			this.selectedIndex = -1;
  });
};

$(document).ready(function(){
	if($('#message').length) {
		$('#bkg_fade').fadeTo(1,0.7);
	}
	$("#close").click(function(){
		$('#message').fadeOut(1000);
		$('#bkg_fade').fadeOut(1000);
		$('form').clearForm();
	});
	
	
	// little box slide show on home page
	var getNum1 = /c_v_/i;
	var getNum2 = /(\.[a-z]+)/i;
	test = 'c_v_1.jpg';
	test = test.replace(getNum1,'');
	test = test.replace(getNum2,'');
	var slide_img = new Array('/img/site/c_v_1.jpg');
	var max_size = 0;
	$('.c_v').each(function (i) {
		slide_img[i+1]= $(this).attr('src');
		++max_size;
	});
	var current = 0;
	
	slideshow = function () {
			++current;
			if (current > max_size) {current = 0;}
			$('#c_v').attr('src',slide_img[current]);
	}
	
	var timeoutID = 0;
	$('#c_v').mouseenter(function () {
		slideshow();
	});
	
	
	$('#c_v').mouseleave(function () {
		slideshow();
	});
});