$(document).ready(document_Ready);
var initCredits = 0;
var creditTimer = {};

function document_Ready(){
	assignBHEventListeners();
	
	var showCredits = $('#showCredits');
	var FooterRight_Links = $('#FooterRight_Links');
	var CreditLinkDiv = $('#CreditLinkDiv');
	
	showCredits.bind("mouseover", function(){
		FooterRight_Links.fadeOut(500, function(){
			CreditLinkDiv.animate( { right:"0" }, 500, "linear", function(){
				FooterRight_Links.delay(5000,function(){
					CreditLinkDiv.animate( {right: -330}, 500, "linear", function(){
						FooterRight_Links.fadeIn(500);
					});
				});
			});;
		});	
	});
	$('#logout').bind('click', closeSession);;	
}


function assignBHEventListeners(){
	$("*[SideBarSearch='true']").click(SideBarSearch_Click);
	$(":text[HasInputMask]").bind("focus", HasInputMask_Focus);
}



function SideBarSearch_Click(){
	var sKeywords = $("#SideBar_Keywords");
	var mask = "keywords";
	if(sKeywords.attr("HasInputMask") != null){
		mask = sKeywords.attr("HasInputMask");
	}
	if(sKeywords.val() == mask){
		sKeywords.val("");
	}
}


function HasInputMask_Focus(){
	var sender = $(this);
	if(sender.val() == sender.attr("HasInputMask")){
		sender.val("");
	}
}



function serveNewCaptcha(popUpID, ImgContainer){
	$.ajax({
		type: "POST",
		url: "/_commongoal/Ajax/Resources.cfc",
		dataType: "text",
		data: {
		   method: 'getNewCaptcha', 
		   popUpID: popUpID
		   , ImgContainer: ImgContainer
		},
		success: newCaptcha_Success
		, error: newCaptcha_Error
	})
}

function closeSession(){
	$.ajax({
		url: "/plugins/Profile/signIn_form/cfc/bhSession.cfc"
		,data: {
			method: "endBHSession"
		}
		, error: function(){
				return false;
			}
	});
}


var newCaptcha_Success = function(result){
	var obj = jQuery.parseJSON(result);
	var popUpCaptchaContainer = $('#' + obj.IMGCONTAINER);
	popUpCaptchaContainer.html(obj.IMAGE);
}
var newCaptcha_Error = function(results){
	//alert("served new capthca !!!ERROR!!!");
	alert("Sorry, this feature is momentarity disabled. Please check again later.");
}
















