var drawerClosed = true;
$(function(){
	
	/**
	 * homepage drawer
	 */
	
	
	// animated rollover
	$('#drawer').hover(function() {
		if(drawerClosed){
			$('#drawer').stop().animate({marginTop:-25}, 0);
		}
	}, function() {
		if(drawerClosed){
			$('#drawer').stop().animate({marginTop:-13}, 500);
		}
	});
	
	// click the drawer trigger
	$('#drawer .handle').click(function() {
		if(drawerClosed){
			openDrawer();
		}else{
			closeDrawer();
		}
	});
	
	// click anywhere (except the drawer) to close the drawer
	$(document).click(function(e) {
		if(!$(e.target).is('#drawer') && $(e.target).parents('#drawer').length == 0){
			closeDrawer();
		}
	});
	
	function openDrawer(){
		logTab("Abonamente Disponibile");
		$('#drawer').animate({marginTop:-303}, 100);
		$('#drawer .handle').css('backgroundPosition', '0 0');
		drawerClosed = false;
	}
	
	function closeDrawer(){
		if ($(".my-floating-tab[rel=1]").css("display") == "none" && $(".my-floating-tab[rel=2]").css("display") == "none" && $(".my-floating-tab[rel=3]").css("display") == "none");
		else {
			$(".my-floating-tab").hide();
			$("#drawer").css("position", "absolute");
			$("#drawer .pane-content").css("padding-top", "");
		}
	
		$('#drawer').animate({marginTop:-13}, 100);
		$('#drawer .handle').css('backgroundPosition', '0 -28px');
		drawerClosed = true;		
	}
	
	/*
	// validate the forms
	$('.webform-client-form, #email-mail-page-form').validate({
		messages: {
			'submitted[name]': 'Enter your name',
			'submitted[email]': 'Enter a valid email address',
			'submitted[phone]': 'Enter a phone number',
			'submitted[company]': 'Enter a company',
			'submitted[comment]': 'Enter a comment',
			'submitted[address]': 'Enter an address',
			'submitted[city]': 'Enter a city',
			'submitted[state]': 'Select a state',
			'submitted[zip_code]': 'Enter a zip code',
			'files[upload_resume]': 'Upload a resume',
			'name': 'Enter your name',
			'mail': 'Enter a valid email address',
			'subject': 'Enter a subject'			
		}
	});
	*/
	
	// faqs
	$('.question').click(function() {
		$(this).next().slideToggle(100);
		return false;
	});
		
});

