//Wild Pages Script collection

$(document).ready(function(){
		//Finds non-header images in Index page and hides them from view.
	$('#latestPost').find('img:not(.post-icon)').each(function(){
			$(this).hide();
	});
	
		//Finds images on View page and sets padding based on image alignment.
	$('.entryInfo').find('img[align=left]').each(function(){
		$(this).css('padding-right','15px');
	});
	$('.entryInfo').find('img[align=right]').each(function(){
		$(this).css('padding-left','5px');
	});
	
		//Check to see if online or crsp schools exist, if not, it removes the anchor tag at the top.
		if($('#groundMatches').length<=0){
			$('#ground').hide();
		}					   
		if($('#onlineMatches').length<=0){
			$('#online').hide();
		}
		if($('#crspMatches').length<=0){
			$('#crsp').hide();
		}

		//Customizes select dropdowns into a collection of stylable divs
	$('select').each(function(){
		var title = $(this).prev('label').text();	
		var selVal = $(this).find('option:selected').text();
		if($(this).attr("value")=="" || $(this).attr("value")=="0"){
			$(this).attr('title',title).prev('label').hide().end().SelectCustomizer();
			var name = $(this).attr('id');
			$('#'+name+'_iconselect');
		} else {
			$(this).attr('title','').prev('label').hide().end().SelectCustomizer();
			var name = $(this).attr('id');
			$('#'+name+'_iconselect').append('<span>' + selVal + '</span>');
		}
//		$('.customselect').hide();	
		$('#'+ name + '_options').click(function(){
			v = $(this).find('.selectedclass').attr('title');
			window.location = v;
		});
	});
	
		//Adds class to labels and hides them on keydown in field
	$('div.text > label').addClass('text');
	$('div.input.text > input#LeadZip').each(function(){
		if ($(this).val() == ""){
			$(this).keypress(function(){
				$(this).prev('label').hide();
			}).keyup(function(){
				if($(this).val()==''){
				   $(this).prev('label').show();
				} else{ 
				$(this).prev('label').hide();
				}
			}).blur(function(){
				    if ($(this).val() == ""){
					   $(this).prev('label').show();
					   }
					});
		} else {
			$(this).prev('label').hide();
		}
	});

});
