if(typeof(Inviko) == "undefined" || !Inviko){
	var Inviko = {};
}
var dialog;
function requestInvite(){
	if(!Inviko._requestInvitePanel){
		document.getElementById('requestInvitePanel').style.display = "block";
		Inviko._requestInvitePanel = new YAHOO.widget.Panel("requestInvitePanel", {
			width : "435px",
			visible : false,
			modal: true,
			fixedcenter: true,
			constraintoviewport : true
		});
		Inviko._requestInvitePanel.render();
	}
	Inviko._requestInvitePanel.show();
}

function sendInviteRequest(){
	var name = document.getElementById('inviteeName').value;
	var email = document.getElementById('inviteeEmail').value;
	var interestSource = document.getElementById('interestSource').value;
	var validator = new Inviko.util.StringValidator();
	
	if(!validator.validateEmail(email)){
		alert("The provided email address is not valid");
		return;
	}
	var postData = "name=" + name + "&email=" + email + "&interest_source=" + interestSource;
	var callback = {
		success: function(o){
			if (o !== undefined) {
				var response = YAHOO.lang.JSON.parse(o.responseText);
				alert(response.message);				
			}
		},
		failure: function(o){
			alert("Oops! Something wrong happened. Please try again or please contact the support team at support@inviko.com");
		}
	};
	var conn = YAHOO.util.Connect.asyncRequest("POST", webroot + "users/requestInvite", callback, postData);
	Inviko._requestInvitePanel.hide();
}


function showRecoverPassowrdForm(){
	if(!Inviko._recoverPasswordPanel){
		document.getElementById('recoverPasswordPanel').style.display = "block";
		Inviko._recoverPasswordPanel = new YAHOO.widget.Panel("recoverPasswordPanel", {
			width : "435px",
			visible : false,
			modal: true,
			fixedcenter: true,
			constraintoviewport : true
		});
		Inviko._recoverPasswordPanel.render();
	}
	Inviko._recoverPasswordPanel.show();
}

function sendRecoverPasswordEmail(){
	var email = document.getElementById('recoverPasswordEmail').value;
	var validator = new Inviko.util.StringValidator();
	
	if(!validator.validateEmail(email)){
		alert("The provided email address is not valid");
		return;
	}
	var postData = "data[email]=" + email;
	var callback = {
		success: function(o){
			if (o !== undefined) {
				var response = YAHOO.lang.JSON.parse(o.responseText);
				alert(response.message);				
			}
		},
		failure: function(o){
			alert("Oops! Something wrong happened. Please try again or please contact the support team at support@inviko.com");
		}
	};
	var conn = YAHOO.util.Connect.asyncRequest("POST", webroot + "users/sendResetPasswordEmail", callback, postData);
	Inviko._recoverPasswordPanel.hide();
}

function showLoginForm(){
	if(!Inviko._loginPanel){
		document.getElementById('loginForm').style.display = "block";
		Inviko._loginPanel = new YAHOO.widget.Panel("loginForm", {
			width : "300px",
			visible : false,
			modal: true,
			fixedcenter: true,
			constraintoviewport : true			
		});
		Inviko._loginPanel.render();
	}
	Inviko._loginPanel.show();
}

$(function(){
	dialog = $('a[rel]').overlay({expose: { 
        color: '#333', 
        loadSpeed: 200, 
        opacity: 0.9 
    }, 
    
    onBeforeLoad: function(){
    	$('#videoPlayerHolder').hide();
    },
    
    onBeforeClose: function(){
    	$('#videoPlayerHolder').show();
    },
    
    onLoad: function()
    {   
    	
    	$('.first-field').focus();
    }, api: true});
});

function addReferer(){
	var form = $('#authenticationForm');
	form.append('<input type="hidden" id="referer" name="data[referer]" value="' + encodeURI(document.location.href) + '"></input>');
	
	return true;
}