// remap jQuery to $
(function($){
$(document).ready(function(){

	// replace the donate button with this one
	//<input type="image" src="/wp-content/themes/dhf/images/button-donate-home.png" name="submit" alt="Donate to the Dallas Hearing Foundation" class="button-donate" />
	$('body.home #sidebar input.button-donate').attr('src','/wp/wp-content/themes/dhf/images/button-donate-home.png');
	
	var $slideshow = $('#slideshow');
    
    if ($('#slideshow').is('#slideshow')) { // only trigger if there is a slideshow present
        
        var show = $slideshow.attr('class').split(' ')[0];
        
        //var show_id = show.split('-')[1];
        //alert(show_id);
        //var count = show.split('-')[2]
        var classes = $slideshow.attr('class').split(' ');
        
        //var img_prefix = classes[1].split('img-prefix-')[1];
            //alert(img_prefix);
        var count = classes[0].split('ss-photo-count-')[1];
        
        // get the directory form the preloaded image
        var src = $('#slideshow img').attr('src').split('/').slice(0,-1).join('/');
        //alert(src);
        
        var h = $('#slideshow img').attr('height');
        var w = $('#slideshow img').attr('width');
        
        // add slides to slideshow (images 2-X) 
        for (var i = 2; i <= count; i++) {
            $slideshow.append('<img src="' + src + '/slide-' + i + '.jpg" width="' + w + '" height="' + h + '" />');
        }
     	
     	
        // start the slideshow 
        $slideshow.cycle({'timeout' : 8000}); 
    }
    
    $('#form-contact').submit(function() {
    	
    	//alert(1);
    	var errors = check_form(this);
    	
    	if (errors == 1) {
    		alert('Please fill out the entire form before submitting.');
    		return false;
    	}
    });
    
    $('#form-financial').submit(function() {
    	
    	//alert(1);
    	var errors = check_form(this);
    	
    	if (errors == 1) {
    		alert('Please fill out the entire form before submitting.');
    		return false;
    	}
    });
    
    check_form = function(form) {
    	
    	var errors = 0;
    	
    	$('.required',form).each(function(i) {
    		var id = $(this).attr('id');
    		if ($(this).val() == '') {
    			//alert('.required[for=' + id + ']');
    			$('label[for=' + id + ']').addClass('error');
    			errors = 1;
    		} else {
    			$('label[for=' + id + ']').removeClass('error');
    		}
    		
    	});
    	
    	return errors;
    }
    
});
})(window.jQuery);


