var showing = true;

jQuery(document).ready(function($) {

			
			// Initialize Slides
			$('#slides').slides({
				play: 6000,
				effect: 'fade',
				generatePagination: false,
				hoverPause: true
			});		
			
			$('a.socImg').animate({
						right: 0
					}, 500);
			
			$('a.open').click(function() {
				if(showing == true) {
					showing = false;
					$('a.socImg').animate({
						right: -50
					}, 500);
					$(this).css('background-position', '0px');
				
				}else {
					showing = true;
					$('a.socImg').animate({
						right: 0
					}, 500);
					$(this).css('background-position', '-24px');
				}
			});
			
			$('a.showBtn').click(function(){
				var that = $(this);
				var toHide = that.parent().parent().find('div.toHide');
				
				if(toHide.is(':hidden')){
					toHide.slideDown();
					that.css('background-position','0 0');
				}else {
					toHide.slideUp();
					that.css('background-position','-17px 0');
				}
				
			});
			
			
			// form watermark functionality
			$('.fields, .textarea, .watermark').focus(function () {
				if(this.value == this.defaultValue) {
					this.value = "";
				}
			});
			
			$('.fields, .textarea, .watermark').blur(function () {
				if(this.value == "") {
					this.value = this.defaultValue;
				}
			}); 
			
			
			// pdf download fly in
			$('div.brochure_pdf_download')
			.hide().delay(1000).slideDown('slow').prepend('<a class="closeBtn"></a>');
			
			$('.closeBtn').click(function() {
				var parent = $(this).parent();
				parent.slideUp();
			});

			// Form Validation
			$('#newsletter').submit(function(){
				var check = 1;
				
				$(this).find(':text').each(function(){
					var val = $(this).val();
					var defval = $(this)[0].defaultValue;
					
					if(val == defval){
						$(this).addClass('error');
						check = 0;
					}
				});
				
				(function(){
					var emailReg = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
					if(!emailReg.test($('#email').val())){
						alert('Please provide a valid email address.');
						$('#email').addClass('error');
						check = 0;
					}
				})();
				
				if(check){
					return true;
				}else {
					return false;
				}
				
			});
				
			
			// dynamic form name insertion
			(function insertFormName() {
				var title = $('h1').html();
				if($('#formName').length > 0) {
					$('#formName').val(title);
				}
			})();
			
			//append author name to span.author
			if($('#author').length > 0){
				var author = $('#author').html().split(' ')[0];
				var authorEmail = $('#author').attr('rel');
				$('span.author').html(author);
				$('#authorField').val(authorEmail);
			}
			
			// popup
			$('a.popUp').click(function(){
				popUp();
			});
			
			function popUp() {
				var the_modal = $('div.modal');
				var the_popup = $('div.popup-form');
				
				the_modal.fadeIn();
				the_popup.show().append('<a class="closeBtn"></a>');
				$('a.closeBtn').click(function(){
					the_modal.hide();
					the_popup.hide();
				});
			}
			
		
		});
		
		

