/* Author: 

*/

//animate-panels

$(document).ready(function () {


/**
* HOW TO ADD NEW SLIDE ELEMENT
*
* Step 1: create a div for your wrapper e.g.
    var $div = $('#news-footer');
    var height = $div.height();
* Step 2: hide the div e.g.
    $div3.hide().css({ height : 0 });
* Step 3:  create a click function for it and ensure that other divs are hidden when you are showing yours
* this means adding another if to the if and else statement that is triggered if your div is not visible.
*
* NOT WORKING!
* usual causes are div names, and the if statement elements not done properly also double check you have the correct height element you created
*/
    // info-wrapper-1
    var $div = $('#news-footer');
    var height = $div.height();
    
    // info-wrapper-2
    //var $div2 = $('#case-footer');
    var height2 = $div2.height();
    
    
    // Hide the divs this way to ensure slide up/down effects happen, don't use hide
    //$div.hide().css({ height : 0 });
    $div2.hide().css({ height : 0 });
    
    $('#latest-news').click(function () {
        if ($div.is(':visible')) {
            $div.animate({ height: 0 }, { duration: 600, complete: function () {
                $div.hide();
            } });
        } else {   
           // If second div or third div are shown hide them first before showing this div
           if ($div2.is(':visible')) {
              $div2.animate({ height: 0 }, { duration: 600, complete: function () {
                    $div2.hide();
                    $div.show().animate({ height : height }, { duration: 600 });
                } });
            }else 
            {
                $div.show().animate({ height : height }, { duration: 600 });
            }

        }
        
        return false;
    });
    
    $('#case-studies').click(function () {
        if ($div2.is(':visible')) {
            $div2.animate({ height: 0 }, { duration: 600, complete: function () {
                $div2.hide();
            } });
        } else {
        
           // If first div or third div are shown hide them first before showing this div
           if ($div.is(':visible')) {
                $div.animate({ height: 0 }, { duration: 600, complete: function () {
                    $div.hide();
                    $div2.show().animate({ height : height2 }, { duration: 600 });
                }});
            }else
            {
                $div2.show().animate({ height : height2 }, { duration: 600 });
            }
        }
        
        return false;
    });
    
    $("label").inFieldLabels();

});

function validateContactForm() 
{
	var errors = '';
	$('.required').each(function(){  
		var value = $(this).val();
		var title = $(this).attr('title');
		if (value == '') {
			errors += '<li>* '+title+'</li>';
		}
	});

	$('.required-email').each(function(){  
		var value = $(this).val();
		var title = $(this).attr('title');
		if (!isValidEmail(value)) {
			errors += '<li>* '+title+'</li>';
		}
	});
		
	// Show errors or submit form
	if (errors.length > 0) {
		$('#form-errors-container').html(errors);
		return false;
	}else {
		return true;
	}
}

function isValidEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   
   return true;
}






















