$(document).ready(function(){
$("#mce-MMERGE1").val("First Name").focus(function(){ if($(this).val() == "First Name"){ $(this).val(''); }}).blur(function(){ if($(this).val() == ''){$(this).val('First Name');}});
$("#mce-LNAME").val("Last Name").focus(function(){ if($(this).val() == "Last Name"){ $(this).val(''); }}).blur(function(){ if($(this).val() == ''){$(this).val('Last Name');}});
$("#mce-EMAIL").val("Email").focus(function(){ if($(this).val() == "Email"){ $(this).val(''); }}).blur(function(){ if($(this).val() == ''){$(this).val('Email');}});
$("#mce-MMERGE5").val("Zip").focus(function(){ if($(this).val() == "Zip"){ $(this).val(''); }}).blur(function(){ if($(this).val() == ''){$(this).val('Zip');}});

$("#mc-embedded-subscribe-form").validationEngine();
$("#donate-form").validationEngine();
	//Hover Buttons
	$(".button-hover").hover(function(){
			var src = $(this).attr("src").match(/[^\.]+/) + "-on.png";
            $(this).attr("src", src);
			
		}, function(){
			var src = $(this).attr("src").replace("-on", "");
            $(this).attr("src", src);
	});  
	$('#rotating-banners').cycle({
			pause: true,
			height: '354px'
		 });
	$("#wrapper-content").equalHeights();
	// Scroll Bar Content Change
	$(".scrollerthumb").click(function(){
	    selectedThumb = $(this).attr('id');
		selectedid = selectedThumb.split("-");
		selectedPost = '#post-' + selectedid[1];
		$("#body-text .active").removeClass('active').fadeOut(function(){
			$(selectedPost).addClass('active').fadeIn(function() {$("#wrapper-content").equalHeights();});});
		});
	
	
	// News Articles Hide/Show

$('.newslinks').each(function() { 
  
  var hiddenElements = $(this).children('li:gt(4)').hide();
  var toggleId = $(this).attr('id') + '-toggle';
   if (hiddenElements.size() > 0) {
      var showCaption = 'View ' + hiddenElements.size() + ' More News Articles';
      $(this).append('<li class="toggler" id="' + toggleId + '">' + showCaption + '</li>');
           $("#" + toggleId)
              .toggle(
                  function() { 
                      hiddenElements.slideDown(function(){$("#wrapper-content").equalHeights();});
                      $(this).text('View Fewer Articles');
                  }, 
                  function() { 
                      hiddenElements.slideUp(function(){$("#wrapper-content").equalHeights();});
                      $(this).text(showCaption);
                  }
             )
      
  } 
});

	
/* var fnames = new Array();var ftypes = new Array();fnames[1]='MMERGE1';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';fnames[0]='EMAIL';ftypes[0]='email';fnames[5]='MMERGE5';ftypes[5]='text';var err_style = '';
try{
    err_style = mc_custom_error_style;
} catch(e){
    err_style = 'margin: 1em 0 0 0; padding: 1em 0.5em 0.5em 0.5em; background: ERROR_BGCOLOR none repeat scroll 0% 0%; font-weight: bold; float: left; z-index: 1; width: 80%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: ERROR_COLOR;';
}

  var options = { errorClass: 'mce_inline_error', errorElement: 'span', errorStyle: err_style, onkeyup: function(){}, onfocusout:function(){}, onblur:function(){}  };
  var mce_validator = $("#mc-embedded-subscribe-form").validationEngine();
  options = { url: 'http://forthegoodofillinois.us1.list-manage.com/subscribe/post-json?u=a68ef2524fe09d37b09403928&id=1dd0cc8095&c=?', type: 'GET', dataType: 'json', contentType: "application/json; charset=utf-8",
                beforeSubmit: function(){
                    $('#mce_tmp_error_msg').remove();
                    $('.datefield','#mc_embed_signup').each(
                        function(){
                            var txt = 'filled';
                            var fields = new Array();
                            var i = 0;
                            $(':text', this).each(
                                function(){
                                    fields[i] = this;
                                    i++;
                                });
                            $(':hidden', this).each(
                                function(){
                                	if ( fields[0].value=='MM' && fields[1].value=='DD' && fields[2].value=='YYYY' ){
                                		this.value = '';
									} else if ( fields[0].value=='' && fields[1].value=='' && fields[2].value=='' ){
                                		this.value = '';
									} else {
	                                    this.value = fields[0].value+'/'+fields[1].value+'/'+fields[2].value;
	                                }
                                });
                        });
                    return mce_validator.form();
                }, 
                success: mce_success_cb
            };
  $('#mc-embedded-subscribe-form').ajaxForm(options);

function mce_success_cb(resp){
    $('#mce-success-response').hide();
    $('#mce-error-response').hide();
    if (resp.result=="success"){
        $('#mce-'+resp.result+'-response').show();
        $('#mce-'+resp.result+'-response').html(resp.msg);
        $('#mc-embedded-subscribe-form').each(function(){
            this.reset();
    	});
    } else {
        var index = -1;
        var msg;
        try {
            var parts = resp.msg.split(' - ',2);
            if (parts[1]==undefined){
                msg = resp.msg;
            } else {
                i = parseInt(parts[0]);
                if (i.toString() == parts[0]){
                    index = parts[0];
                    msg = parts[1];
                } else {
                    index = -1;
                    msg = resp.msg;
                }
            }
        } catch(e){
            index = -1;
            msg = resp.msg;
        }
        try{
            if (index== -1){
                $('#mce-'+resp.result+'-response').show();
                $('#mce-'+resp.result+'-response').html(msg);            
            } else {
                err_id = 'mce_tmp_error_msg';
                html = '<div id="'+err_id+'" style="'+err_style+'"> '+msg+'</div>';
                
                var input_id = '#mc_embed_signup';
                var f = $(input_id);
                if (ftypes[index]=='address'){
                    input_id = '#mce-'+fnames[index]+'-addr1';
                    f = $(input_id).parent().parent().get(0);
                } else if (ftypes[index]=='date'){
                    input_id = '#mce-'+fnames[index]+'-month';
                    f = $(input_id).parent().parent().get(0);
                } else {
                    input_id = '#mce-'+fnames[index];
                    f = $().parent(input_id).get(0);
                }
                if (f){
                    $(f).append(html);
                    $(input_id).focus();
                } else {
                    $('#mce-'+resp.result+'-response').show();
                    $('#mce-'+resp.result+'-response').html(msg);
                }
            }
        } catch(e){
            $('#mce-'+resp.result+'-response').show();
            $('#mce-'+resp.result+'-response').html(msg);
        }
    }
}
*/
});

$(document).ready(function() {
		//scrollpane parts
		var scrollPane = $('div.slider-gallery');
		var scrollContent = $('ul', scrollPane);
		
		//build slider
		var scrollbar = $(".slider-mover").slider({
			
			slide:function(e, ui){
				if( scrollContent.width() > scrollPane.width() ){ scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
				else { scrollContent.css('margin-left', 0); }
			}
		});
		
		//append icon to handle
		var handleHelper = scrollbar.find('.ui-slider-handle')
		.mousedown(function(){
			scrollbar.width( 'handleHelper.width()' );
		})
		.mouseup(function(){
			scrollbar.width( '100%' );
		})
		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
		
		//change overflow to hidden now that slider handles the scrolling
		scrollPane.css('overflow','hidden');
		
		//size scrollbar and handle proportionally to scroll distance
		function sizeScrollbar(){
			var remainder = scrollContent.width() - scrollPane.width();
			var proportion = remainder / scrollContent.width();
			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
			scrollbar.find('.ui-slider-handle').css({
				width: 86,
				'margin-left': 0
			});
			handleHelper.width('').width( scrollbar.width() - handleSize);
		}
		
		//reset slider value based on scroll content position
		function resetValue(){
			var remainder = scrollPane.width() - scrollContent.width();
			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
			var percentage = Math.round(leftVal / remainder * 100);
			scrollbar.slider("value", percentage);
		}
		//if the slider is 100% and window gets larger, reveal content
		function reflowContent(){
				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
				var gap = scrollPane.width() - showing;
				if(gap > 0){
					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
				}
		}
		
		//change handle position on window resize
		$(window)
		.resize(function(){
				resetValue();
				sizeScrollbar();
				reflowContent();
		});
		//init scrollbar size
		setTimeout(sizeScrollbar,10);//safari wants a timeout
});

