function initFooterCollaps(){
	var _d = 500;
	$('.expand-box').each(function(){
		var _this = $(this);
		var _opener = $('.expand > a',_this);
		var _close = $('.close > a', _this);
		var _slider = $('.slide-box', _this);
		_opener.click(function(){
			$('#footer .nav li a').each(function(){
				$(this).addClass('no-hover');
			});
			$('#footer .nav').addClass('no-hover');
			_slider.animate({height: _slider.children(':eq(0)').height()}, _d, function(){
				_opener.hide();
				_close.parent().css({visibility: 'visible'});
			});
			return false;
		});
		_close.click(function(){
			_close.parent().css({visibility: 'hidden'});
			_slider.animate({height: 0}, _d, function(){
				_opener.show();
				$('#footer .nav li a').each(function(){
					$(this).removeClass('no-hover');
				});
				$('#footer .nav').removeClass('no-hover');
			});
			return false;
		})
	});
	$('.expasible').each(function(){
		var _d = 500;
		var _this = $(this);
		var _opener = $('.opener',_this);
		var _slider = $('.slider',_this);

		if(!_opener.hasClass('opened')) _slider.slideUp(0);

		_opener.click(function(){
			var _link = $(this);
			if(!$(this).hasClass('opened')){
				_slider.slideDown(_d,function(){
					_link.addClass('opened');
				});
			}else{
				_slider.slideUp(_d,function(){
					_link.removeClass('opened');
				});
			}
			return false;
		})
	})
}
$(function(){
	initFooterCollaps();
});

function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);
	
function isValidEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function validate_email(){
	var email = $('#your-email').val();
	if(!isValidEmail(email)){
		$('.email-form .form-status').text('Please enter a valid email address').css({
			color: '#bf0000',
			paddingTop: '7px'
		});
		return false;
	}else{
		$('.email-form .form-status').text('Thank you!').css({
			color: '#006600',
			paddingTop: '7px'
		});
		
		$.post('/_includes/php/hubspot.php', {
			email: email,
			type: 'Web - Email List'
		}, function(){
			$('#your-email').val('');
		});
	}

	return false;
}


$(function(){
	
	$('.watch_video').bind('click', function(){
		watch_video();
		return false;
	});
	
	if(typeof footer_open != "undefined") { if(footer_open == 1){ $('.expand a').click(); } }
	$('.email-form').append('<div class="form-status"></div>').submit(function(){
		return validate_email();
	});
	
	$(".asset_download").bind('click', function(){
		var link = $(this).attr('href');
		var downloaded = $(this).text();

		if(trim(downloaded) == '') downloaded = link;
		
		$.post('/_includes/php/cookie.php', function(status){
		    if(status != 1){
				$.ajax({
				  url: '/_includes/php/hubspot_form.php?asset=' + link + '&asset_name=' + downloaded,
				  success: function(data) {
				    $.fancybox(
							data,
							{
					        	'autoDimensions'	: true,
								'transitionIn'		: 'none',
								'transitionOut'		: 'none'
							}
						);
				  }
				});
				return false;

			}else{
				/*$.post('/_includes/php/hubspot.php', {
					asset_name: downloaded			
				}, function(){
					window.location = link;
					return false;
				});*/
				
				window.location = link;
				return false;
				
				
			}
		});
		return false;
	});
	
	$(".side-box .eval_form").bind('click', function(){
		$.ajax({
		  url: '/_includes/php/eval_form.php',
		  success: function(data) {
		    $.fancybox(
					data,
					{
			        	'autoDimensions'	: true,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
				);
		  }
		});
		return false;
	});
	
	$(".side-box .demo_form").bind('click', function(){
		$.ajax({
		  url: '/_includes/php/demo_form.php',
		  success: function(data) {
		    $.fancybox(
					data,
					{
			        	'autoDimensions'	: true,
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
				);
		  }
		});
		return false;
	});
	
	
	
	$('a.open-fancy').fancybox();
		
});	

function checkEmail(str) {
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function check_blank(str){
	var str = trim(str);
	if(str.length == 0){
		return false;
	}
	
	return true;

}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function watch_video(){
	$.ajax({
	  url: '/_media/swf/index.html',
	  success: function(data) {
	    $.fancybox(
				data,
				{
					'type': 'iframe',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'url': '/_media/swf/index.html',
					'height' : '590',
					'width' : '915'
				}
			);
	  }
	});
	
	return false;
}
