// build the home menu
voxox.buildhome = function() {

    if (!$("#page0").length) {
		var addItem = function (i, item) {
			var pageNumber = Math.floor(i/menuPageSize);
			var column     = i % menuColumns;
			if ( !$("#page"+pageNumber).length ) // check to see if we need to add a new page
				$("<div>").attr("id","page"+pageNumber).appendTo("#pages");
			var div = $("<div>").text(item.name).addClass("item").addClass("col"+column).appendTo("#page"+pageNumber);
			$("<a>").addClass("icon").addClass(item.id).prependTo(div).text(" ");
			div.wrap('<a href="'+item.url+'"></a>');
		}
		$.each(menuItems,function(i,item) {addItem(i,item)});

		var pageWidth = $("#pages:first-child").width();
		$("#pages").width($("#pages > div").length * pageWidth);
		$("a.enabled, a.disabled").hide();
		if( $("#pages > div").length > 1 ) {
			$("a.disabled:not(.right)").show();
			$("a.enabled:not(.left)").show();
            $('#home').serialScroll({
				target:'#menu', items:'#pages > div',
				prev:'a.left:first', next:'a.right:first',
				axis:'x', duration: 600,
				force:true, lock: false, cycle: false,
				onBefore:function( e, elem, $pane, $items, pos ){
					$("a.enabled").show(); $("a.disabled").hide();
					if( pos == 0 ) {
						$("a.disabled:not(.right)").show();
						$("a.enabled:not(.right)").hide();  
					}
					else if( pos == $items.length-1 ){
						$("a.disabled:not(.left)").show();
						$("a.enabled:not(.left)").hide();    
					} 
                      
				}
			}); 
            
		}		
	}
	voxox.home = function(){};
	voxox.home.show = function () {
		$("#home").fadeIn("slow"); $("#loading").fadeOut("fast");
	    if (voxox.userid && (voxox.userdata.hasValidated != 'Y') && !$.cookie("smsCancelled")) {
			voxox.myaccount.buildsmsverify();
		} else if(voxox.version != "") {
			var version = voxox.version.match(/\d/g).join(''); 
			if (version < "205") {
				voxox.alertOnce("newversion205", "New Version Available","A new version of VoxOx is available to download.<br/><a href='openLink$http://download.voxox.com'><u>Click here</u></a> to visit our download page.");
			}
		}
	}
    
    $("#home_sedInvite_button").click(function() {
        voxox.home.sendInvite();
    });
    
    voxox.home.sendInvite = function () {
	    var params = [voxox.userid, $("#inviteFriendsBannerText").val(),voxox.username,voxox.userdata.voxox_id];
	    voxox.callGateway("invites","newInvite",params,function(data) {
	        if (!data.success){
	            voxox.alert("invitefriends_error","Error",data.result);   
            } else { saveSmssaveSms
	            voxox.alert("invitefriends_alert","Invite Friends","Invitation Sent",{"align":"center"});  }
	    }); 

        voxox.alert("invitefriends_alert","Invite Friends","Invitation Sent",{"align":"center"});  
    };
    
    $('#home input[type="text"]').example(function() { return $(this).attr("title"); });
};
