﻿$(function() {
	
	//remove every li's last border
	$('ul li:last-child').addClass('last');
	
	//add class hide (.hide) to the widget, who don't have the class
	$('.sidebar-content-block ul:not(.hide)').addClass('hide');
	
	//scroll feature
	$("#top-link").localScroll();
	
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn('slow'); //Fade in the active ID content
		return false;
	});

});

//Toggle
$(function(){		
	$('.tog').addClass('togAdd');
	$('.tog').click().toggle(function(){
			$(this).removeClass('togAdd');
			$(this).addClass('togRemove');
		}, function(){
			$(this).removeClass('togRemove');
			$(this).addClass('togAdd');
	});
	
	$('.tog').click(function(){
		$(this).next().next('.hide').slideToggle("fast");
	});	   
});

//form label slider
$(function(){
	$('form#info .slider label').each(function(){
		var labelColor = '#999';
		var restingPosition = '5px';

		// style the label with JS for progressive enhancement
		$(this).css({
			'color' : labelColor,
				'position' : 'absolute',
				'top' : '6px',
				'left' : restingPosition,
				'display' : 'inline',
			'z-index' : '99'
		});

		// grab the input value
		var inputval = $(this).next('input').val();

		// grab the label width, then add 5 pixels to it
		var labelwidth = $(this).width();
		var labelmove = labelwidth + 5;

		//onload, check if a field is filled out, if so, move the label out of the way
		if(inputval !== ''){
			$(this).stop().animate({ 'left':'-'+labelmove }, 1);
		}    	

		// if the input is empty on focus move the label to the left
		// if it's empty on blur, move it back
		$('input').focus(function(){
			var label = $(this).prev('label');
			var width = $(label).width();
			var adjust = width + 5;
			var value = $(this).val();

			if(value == ''){
				label.stop().animate({ 'left':'-'+adjust }, 'fast');
			} else {
				label.css({ 'left':'-'+adjust });
			}
		}).blur(function(){
			var label = $(this).prev('label');
			var value = $(this).val();

			if(value == ''){
				label.stop().animate({ 'left':restingPosition }, 'fast');
			}	

		});	    	
	});
});